diff options
Diffstat (limited to 'libcnary')
| -rw-r--r-- | libcnary/node.c | 20 | ||||
| -rw-r--r-- | libcnary/node_list.c | 14 |
2 files changed, 17 insertions, 17 deletions
diff --git a/libcnary/node.c b/libcnary/node.c index 46532aa..fadc9de 100644 --- a/libcnary/node.c +++ b/libcnary/node.c | |||
| @@ -96,14 +96,14 @@ int node_attach(node_t* parent, node_t* child) { | |||
| 96 | 96 | ||
| 97 | int node_detach(node_t* parent, node_t* child) { | 97 | int node_detach(node_t* parent, node_t* child) { |
| 98 | if (!parent || !child) return -1; | 98 | if (!parent || !child) return -1; |
| 99 | int index = node_list_remove(parent->children, child); | 99 | int node_index = node_list_remove(parent->children, child); |
| 100 | if (index >= 0) { | 100 | if (node_index >= 0) { |
| 101 | parent->count--; | 101 | parent->count--; |
| 102 | } | 102 | } |
| 103 | return index; | 103 | return node_index; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | int node_insert(node_t* parent, unsigned int index, node_t* child) | 106 | int node_insert(node_t* parent, unsigned int node_index, node_t* child) |
| 107 | { | 107 | { |
| 108 | if (!parent || !child) return -1; | 108 | if (!parent || !child) return -1; |
| 109 | child->isLeaf = TRUE; | 109 | child->isLeaf = TRUE; |
| @@ -113,7 +113,7 @@ int node_insert(node_t* parent, unsigned int index, node_t* child) | |||
| 113 | if(parent->isLeaf == TRUE) { | 113 | if(parent->isLeaf == TRUE) { |
| 114 | parent->isLeaf = FALSE; | 114 | parent->isLeaf = FALSE; |
| 115 | } | 115 | } |
| 116 | int res = node_list_insert(parent->children, index, child); | 116 | int res = node_list_insert(parent->children, node_index, child); |
| 117 | if (res == 0) { | 117 | if (res == 0) { |
| 118 | parent->count++; | 118 | parent->count++; |
| 119 | } | 119 | } |
| @@ -155,11 +155,11 @@ unsigned int node_n_children(struct node_t* node) | |||
| 155 | node_t* node_nth_child(struct node_t* node, unsigned int n) | 155 | node_t* node_nth_child(struct node_t* node, unsigned int n) |
| 156 | { | 156 | { |
| 157 | if (!node || !node->children || !node->children->begin) return NULL; | 157 | if (!node || !node->children || !node->children->begin) return NULL; |
| 158 | unsigned int index = 0; | 158 | unsigned int node_index = 0; |
| 159 | int found = 0; | 159 | int found = 0; |
| 160 | node_t *ch; | 160 | node_t *ch; |
| 161 | for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { | 161 | for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { |
| 162 | if (index++ == n) { | 162 | if (node_index++ == n) { |
| 163 | found = 1; | 163 | found = 1; |
| 164 | break; | 164 | break; |
| 165 | } | 165 | } |
| @@ -191,7 +191,7 @@ node_t* node_next_sibling(struct node_t* node) | |||
| 191 | int node_child_position(struct node_t* parent, node_t* child) | 191 | int node_child_position(struct node_t* parent, node_t* child) |
| 192 | { | 192 | { |
| 193 | if (!parent || !parent->children || !parent->children->begin || !child) return -1; | 193 | if (!parent || !parent->children || !parent->children->begin || !child) return -1; |
| 194 | int index = 0; | 194 | int node_index = 0; |
| 195 | int found = 0; | 195 | int found = 0; |
| 196 | node_t *ch; | 196 | node_t *ch; |
| 197 | for (ch = node_first_child(parent); ch; ch = node_next_sibling(ch)) { | 197 | for (ch = node_first_child(parent); ch; ch = node_next_sibling(ch)) { |
| @@ -199,12 +199,12 @@ int node_child_position(struct node_t* parent, node_t* child) | |||
| 199 | found = 1; | 199 | found = 1; |
| 200 | break; | 200 | break; |
| 201 | } | 201 | } |
| 202 | index++; | 202 | node_index++; |
| 203 | } | 203 | } |
| 204 | if (!found) { | 204 | if (!found) { |
| 205 | return -1; | 205 | return -1; |
| 206 | } | 206 | } |
| 207 | return index; | 207 | return node_index; |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | node_t* node_copy_deep(node_t* node, copy_func_t copy_func) | 210 | node_t* node_copy_deep(node_t* node, copy_func_t copy_func) |
diff --git a/libcnary/node_list.c b/libcnary/node_list.c index 5b291e7..4b268e0 100644 --- a/libcnary/node_list.c +++ b/libcnary/node_list.c | |||
| @@ -72,9 +72,9 @@ int node_list_add(node_list_t* list, node_t* node) { | |||
| 72 | return 0; | 72 | return 0; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | int node_list_insert(node_list_t* list, unsigned int index, node_t* node) { | 75 | int node_list_insert(node_list_t* list, unsigned int node_index, node_t* node) { |
| 76 | if (!list || !node) return -1; | 76 | if (!list || !node) return -1; |
| 77 | if (index >= list->count) { | 77 | if (node_index >= list->count) { |
| 78 | return node_list_add(list, node); | 78 | return node_list_add(list, node); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| @@ -84,8 +84,8 @@ int node_list_insert(node_list_t* list, unsigned int index, node_t* node) { | |||
| 84 | unsigned int pos = 0; | 84 | unsigned int pos = 0; |
| 85 | node_t* prev = NULL; | 85 | node_t* prev = NULL; |
| 86 | 86 | ||
| 87 | if (index > 0) { | 87 | if (node_index > 0) { |
| 88 | while (pos < index) { | 88 | while (pos < node_index) { |
| 89 | prev = cur; | 89 | prev = cur; |
| 90 | cur = cur->next; | 90 | cur = cur->next; |
| 91 | pos++; | 91 | pos++; |
| @@ -124,7 +124,7 @@ int node_list_remove(node_list_t* list, node_t* node) { | |||
| 124 | if (!list || !node) return -1; | 124 | if (!list || !node) return -1; |
| 125 | if (list->count == 0) return -1; | 125 | if (list->count == 0) return -1; |
| 126 | 126 | ||
| 127 | int index = 0; | 127 | int node_index = 0; |
| 128 | node_t* n; | 128 | node_t* n; |
| 129 | for (n = list->begin; n; n = n->next) { | 129 | for (n = list->begin; n; n = n->next) { |
| 130 | if (node == n) { | 130 | if (node == n) { |
| @@ -145,9 +145,9 @@ int node_list_remove(node_list_t* list, node_t* node) { | |||
| 145 | list->begin = newnode; | 145 | list->begin = newnode; |
| 146 | } | 146 | } |
| 147 | list->count--; | 147 | list->count--; |
| 148 | return index; | 148 | return node_index; |
| 149 | } | 149 | } |
| 150 | index++; | 150 | node_index++; |
| 151 | } | 151 | } |
| 152 | return -1; | 152 | return -1; |
| 153 | } | 153 | } |
