X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgl_anytreehash_list1.h;h=0ef6d566ac5fd3a3ef9a1edd9830ed2c4d0af9a2;hb=cb07569c0de7172006a6dcf94adc5658fdaa523c;hp=7f38180c9ce1e65263fd331c95dcac8e526de11d;hpb=0a51cf1590113188ff1dc78dc79d2924c262a865;p=gnulib.git diff --git a/lib/gl_anytreehash_list1.h b/lib/gl_anytreehash_list1.h index 7f38180c9..0ef6d566a 100644 --- a/lib/gl_anytreehash_list1.h +++ b/lib/gl_anytreehash_list1.h @@ -78,6 +78,15 @@ compare_by_position (const void *x1, const void *x2) position1 < position2 ? -1 : 0); } +/* Compares a node's position in the tree with a given threshold. */ +static bool +compare_position_threshold (const void *x, const void *threshold) +{ + gl_list_node_t node = (gl_list_node_t) x; + size_t position = node_position (node); + return (position >= (uintptr_t)threshold); +} + /* Return the first element of a non-empty ordered set of nodes. */ static inline gl_list_node_t gl_oset_first (gl_oset_t set) @@ -100,7 +109,7 @@ gl_oset_first (gl_oset_t set) static void add_to_bucket (gl_list_t list, gl_list_node_t new_node) { - size_t index = new_node->h.hashcode % list->table_size; + size_t bucket = new_node->h.hashcode % list->table_size; /* If no duplicates are allowed, multiple nodes are not needed. */ if (list->base.allow_duplicates) @@ -110,7 +119,7 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node) gl_listelement_equals_fn equals = list->base.equals_fn; gl_hash_entry_t *entryp; - for (entryp = &list->table[index]; *entryp != NULL; entryp = &(*entryp)->hash_next) + for (entryp = &list->table[bucket]; *entryp != NULL; entryp = &(*entryp)->hash_next) { gl_hash_entry_t entry = *entryp; @@ -148,8 +157,7 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node) gl_oset_add (nodes, node); gl_oset_add (nodes, new_node); - multi_entry = - (struct gl_multiple_nodes *) xmalloc (sizeof (struct gl_multiple_nodes)); + multi_entry = XMALLOC (struct gl_multiple_nodes); multi_entry->h.hash_next = entry->hash_next; multi_entry->h.hashcode = entry->hashcode; multi_entry->magic = MULTIPLE_NODES_MAGIC; @@ -162,8 +170,8 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node) } } /* If no duplicates are allowed, multiple nodes are not needed. */ - new_node->h.hash_next = list->table[index]; - list->table[index] = &new_node->h; + new_node->h.hash_next = list->table[bucket]; + list->table[bucket] = &new_node->h; } /* Remove a node from the hash table structure. @@ -175,7 +183,7 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node) static void remove_from_bucket (gl_list_t list, gl_list_node_t old_node) { - size_t index = old_node->h.hashcode % list->table_size; + size_t bucket = old_node->h.hashcode % list->table_size; if (list->base.allow_duplicates) { @@ -184,7 +192,7 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node) gl_listelement_equals_fn equals = list->base.equals_fn; gl_hash_entry_t *entryp; - for (entryp = &list->table[index]; ; entryp = &(*entryp)->hash_next) + for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next) { gl_hash_entry_t entry = *entryp; @@ -230,7 +238,7 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node) /* If no duplicates are allowed, multiple nodes are not needed. */ gl_hash_entry_t *entryp; - for (entryp = &list->table[index]; ; entryp = &(*entryp)->hash_next) + for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next) { if (*entryp == &old_node->h) {