/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* Glenn Fowler24* AT&T Research25*26* hash table library27*/2829#include "hashlib.h"3031/*32* change table size and rehash33* size must be a power of 234*/3536void37hashsize(register Hash_table_t* tab, int size)38{39register Hash_bucket_t** old_s;40register Hash_bucket_t** new_s;41register Hash_bucket_t* old_b;42register Hash_bucket_t* new_b;43Hash_bucket_t** old_sx;44unsigned int index;45Hash_region_f region;46void* handle;4748if (size > 0 && size != tab->size && !(size & (size - 1)))49{50if (region = tab->root->local->region)51{52handle = tab->root->local->handle;53new_s = (Hash_bucket_t**)(*region)(handle, NiL, sizeof(Hash_bucket_t*) * size, 0);54}55else new_s = newof(0, Hash_bucket_t*, size, 0);56if (!new_s) tab->flags |= HASH_FIXED;57else58{59old_sx = (old_s = tab->table) + tab->size;60tab->size = size;61while (old_s < old_sx)62{63old_b = *old_s++;64while (old_b)65{66new_b = old_b;67old_b = old_b->next;68index = new_b->hash;69HASHMOD(tab, index);70new_b->next = new_s[index];71new_s[index] = new_b;72}73}74if ((tab->flags & (HASH_RESIZE|HASH_STATIC)) != HASH_STATIC)75{76if (region) (*region)(handle, tab->table, 0, 0);77else free(tab->table);78}79tab->table = new_s;80tab->flags |= HASH_RESIZE;81}82}83}848586