"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/utils/hash.c" between
nanomsg-1.1.4.tar.gz and nanomsg-1.1.5.tar.gz

About: nanomsg is a socket library that provides several common communication patterns. It aims to make the networking layer fast, scalable, and easy to use.

hash.c  (nanomsg-1.1.4):hash.c  (nanomsg-1.1.5)
skipping to change at line 55 skipping to change at line 55
void nn_hash_term (struct nn_hash *self) void nn_hash_term (struct nn_hash *self)
{ {
uint32_t i; uint32_t i;
for (i = 0; i != self->slots; ++i) for (i = 0; i != self->slots; ++i)
nn_list_term (&self->array [i]); nn_list_term (&self->array [i]);
nn_free (self->array); nn_free (self->array);
} }
static void nn_hash_rehash (struct nn_hash *self) { static void nn_hash_rehash (struct nn_hash *self)
{
uint32_t i; uint32_t i;
uint32_t oldslots; uint32_t oldslots;
struct nn_list *oldarray; struct nn_list *oldarray;
struct nn_hash_item *hitm; struct nn_hash_item *hitm;
uint32_t newslot; uint32_t newslot;
/* Allocate new double-sized array of slots. */ /* Allocate new double-sized array of slots. */
oldslots = self->slots; oldslots = self->slots;
oldarray = self->array; oldarray = self->array;
self->slots *= 2; self->slots *= 2;
self->array = nn_alloc (sizeof (struct nn_list) * self->slots, "hash map"); self->array = nn_alloc (sizeof (struct nn_list) * self->slots, "hash map");
alloc_assert (self->array); alloc_assert (self->array);
for (i = 0; i != self->slots; ++i) for (i = 0; i != self->slots; ++i)
nn_list_init (&self->array [i]); nn_list_init (&self->array [i]);
/* Move the items from old slot array to new slot array. */ /* Move the items from old slot array to new slot array. */
for (i = 0; i != oldslots; ++i) { for (i = 0; i != oldslots; ++i) {
while (!nn_list_empty (&oldarray [i])) { while (!nn_list_empty (&oldarray [i])) {
hitm = nn_cont (nn_list_begin (&oldarray [i]), hitm = nn_cont (nn_list_begin (&oldarray [i]),
struct nn_hash_item, list); struct nn_hash_item, list);
nn_list_erase (&oldarray [i], &hitm->list); nn_list_erase (&oldarray [i], &hitm->list);
newslot = nn_hash_key (hitm->key) % self->slots; newslot = nn_hash_key (hitm->key) % self->slots;
nn_list_insert (&self->array [newslot], &hitm->list, nn_list_insert (&self->array [newslot], &hitm->list,
nn_list_end (&self->array [newslot])); nn_list_end (&self->array [newslot]));
} }
nn_list_term (&oldarray [i]); nn_list_term (&oldarray [i]);
} }
/* Deallocate the old array of slots. */ /* Deallocate the old array of slots. */
nn_free (oldarray); nn_free (oldarray);
} }
void nn_hash_insert (struct nn_hash *self, uint32_t key, void nn_hash_insert (struct nn_hash *self, uint32_t key,
struct nn_hash_item *item) struct nn_hash_item *item)
{ {
struct nn_list_item *it; struct nn_list_item *it;
skipping to change at line 110 skipping to change at line 111
nn_assert (nn_cont (it, struct nn_hash_item, list)->key != key); nn_assert (nn_cont (it, struct nn_hash_item, list)->key != key);
item->key = key; item->key = key;
nn_list_insert (&self->array [i], &item->list, nn_list_insert (&self->array [i], &item->list,
nn_list_end (&self->array [i])); nn_list_end (&self->array [i]));
++self->items; ++self->items;
/* If the hash is getting full, double the amount of slots and /* If the hash is getting full, double the amount of slots and
re-hash all the items. */ re-hash all the items. */
if (nn_slow (self->items * 2 > self->slots && self->slots < 0x80000000)) if (nn_slow (self->items * 2 > self->slots && self->slots < 0x80000000))
nn_hash_rehash(self); nn_hash_rehash(self);
} }
void nn_hash_erase (struct nn_hash *self, struct nn_hash_item *item) void nn_hash_erase (struct nn_hash *self, struct nn_hash_item *item)
{ {
uint32_t slot; uint32_t slot;
slot = nn_hash_key (item->key) % self->slots; slot = nn_hash_key (item->key) % self->slots;
nn_list_erase (&self->array [slot], &item->list); nn_list_erase (&self->array [slot], &item->list);
--self->items; --self->items;
} }
 End of changes. 5 change blocks. 
12 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)