diff options
Diffstat (limited to 'cint_array.c')
-rw-r--r-- | cint_array.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/cint_array.c b/cint_array.c index 136f9ad4..9bf4987b 100644 --- a/cint_array.c +++ b/cint_array.c @@ -59,6 +59,7 @@ static void cint_print(NODE *symbol); afunc_t cint_array_func[] = { cint_array_init, is_uinteger, + null_length, cint_lookup, cint_exists, cint_clear, @@ -66,6 +67,7 @@ afunc_t cint_array_func[] = { cint_list, cint_copy, cint_dump, + (afunc_t) 0, }; static inline int cint_hash(long k); @@ -78,7 +80,7 @@ static NODE **tree_exists(NODE *tree, long k); static void tree_clear(NODE *tree); static int tree_remove(NODE *symbol, NODE *tree, long k); static void tree_copy(NODE *newsymb, NODE *tree, NODE *newtree); -static long tree_list(NODE *tree, NODE **list, unsigned int flags); +static long tree_list(NODE *tree, NODE **list, assoc_kind_t assoc_kind); static inline NODE **tree_find(NODE *tree, long k, int i); static void tree_info(NODE *tree, NODE *ndump, const char *aname); static size_t tree_kilobytes(NODE *tree); @@ -91,7 +93,7 @@ static inline NODE **leaf_exists(NODE *array, long k); static void leaf_clear(NODE *array); static int leaf_remove(NODE *symbol, NODE *array, long k); static void leaf_copy(NODE *newsymb, NODE *array, NODE *newarray); -static long leaf_list(NODE *array, NODE **list, unsigned int flags); +static long leaf_list(NODE *array, NODE **list, assoc_kind_t assoc_kind); static void leaf_info(NODE *array, NODE *ndump, const char *aname); #ifdef ARRAYDEBUG static void leaf_print(NODE *array, size_t bi, int indent_level); @@ -418,15 +420,16 @@ cint_list(NODE *symbol, NODE *t) unsigned long k = 0, num_elems, list_size; size_t j, ja, jd; int elem_size = 1; + assoc_kind_t assoc_kind; num_elems = symbol->table_size; if (num_elems == 0) return NULL; - - if ((t->flags & (AINDEX|AVALUE|ADELETE)) == (AINDEX|ADELETE)) + assoc_kind = (assoc_kind_t) t->flags; + if ((assoc_kind & (AINDEX|AVALUE|ADELETE)) == (AINDEX|ADELETE)) num_elems = 1; - if ((t->flags & (AINDEX|AVALUE)) == (AINDEX|AVALUE)) + if ((assoc_kind & (AINDEX|AVALUE)) == (AINDEX|AVALUE)) elem_size = 2; list_size = num_elems * elem_size; @@ -434,7 +437,8 @@ cint_list(NODE *symbol, NODE *t) xn = symbol->xarray; list = xn->alist(xn, t); assert(list != NULL); - t->flags &= ~(AASC|ADESC); + assoc_kind &= ~(AASC|ADESC); + t->flags = (unsigned int) assoc_kind; if (num_elems == 1 || num_elems == xn->table_size) return list; erealloc(list, NODE **, list_size * sizeof(NODE *), "cint_list"); @@ -442,18 +446,20 @@ cint_list(NODE *symbol, NODE *t) } else emalloc(list, NODE **, list_size * sizeof(NODE *), "cint_list"); - - if ((t->flags & AINUM) == 0) /* not sorting by "index num" */ - t->flags &= ~(AASC|ADESC); + if ((assoc_kind & AINUM) == 0) { + /* not sorting by "index num" */ + assoc_kind &= ~(AASC|ADESC); + t->flags = (unsigned int) assoc_kind; + } /* populate it with index in ascending or descending order */ for (ja = NHAT, jd = INT32_BIT - 1; ja < INT32_BIT && jd >= NHAT; ) { - j = (t->flags & ADESC) ? jd-- : ja++; + j = (assoc_kind & ADESC) ? jd-- : ja++; tn = symbol->nodes[j]; if (tn == NULL) continue; - k += tree_list(tn, list + k, t->flags); + k += tree_list(tn, list + k, assoc_kind); if (k >= list_size) return list; } @@ -875,7 +881,7 @@ tree_find(NODE *tree, long k, int i) /* tree_list --- return a list of items in the HAT */ static long -tree_list(NODE *tree, NODE **list, unsigned int flags) +tree_list(NODE *tree, NODE **list, assoc_kind_t assoc_kind) { NODE *tn; size_t j, cj, hsize; @@ -888,15 +894,15 @@ tree_list(NODE *tree, NODE **list, unsigned int flags) hsize /= 2; for (j = 0; j < hsize; j++) { - cj = (flags & ADESC) ? (hsize - 1 - j) : j; + cj = (assoc_kind & ADESC) ? (hsize - 1 - j) : j; tn = tree->nodes[cj]; if (tn == NULL) continue; if (tn->type == Node_array_tree) - k += tree_list(tn, list + k, flags); + k += tree_list(tn, list + k, assoc_kind); else - k += leaf_list(tn, list + k, flags); - if ((flags & ADELETE) != 0 && k >= 1) + k += leaf_list(tn, list + k, assoc_kind); + if ((assoc_kind & ADELETE) != 0 && k >= 1) return k; } return k; @@ -1141,7 +1147,7 @@ leaf_copy(NODE *newsymb, NODE *array, NODE *newarray) /* leaf_list --- return a list of items */ static long -leaf_list(NODE *array, NODE **list, unsigned int flags) +leaf_list(NODE *array, NODE **list, assoc_kind_t assoc_kind) { NODE *r, *subs; long num, i, ci, k = 0; @@ -1149,14 +1155,14 @@ leaf_list(NODE *array, NODE **list, unsigned int flags) static char buf[100]; for (i = 0; i < size; i++) { - ci = (flags & ADESC) ? (size - 1 - i) : i; + ci = (assoc_kind & ADESC) ? (size - 1 - i) : i; r = array->nodes[ci]; if (r == NULL) continue; /* index */ num = array->array_base + ci; - if (flags & AISTR) { + if (assoc_kind & AISTR) { sprintf(buf, "%ld", num); subs = make_string(buf, strlen(buf)); subs->numbr = num; @@ -1168,16 +1174,16 @@ leaf_list(NODE *array, NODE **list, unsigned int flags) list[k++] = subs; /* value */ - if (flags & AVALUE) { + if (assoc_kind & AVALUE) { if (r->type == Node_val) { - if ((flags & AVNUM) != 0) + if ((assoc_kind & AVNUM) != 0) (void) force_number(r); - else if ((flags & AVSTR) != 0) + else if ((assoc_kind & AVSTR) != 0) r = force_string(r); } list[k++] = r; } - if ((flags & ADELETE) != 0 && k >= 1) + if ((assoc_kind & ADELETE) != 0 && k >= 1) return k; } |