} gmx_hash_e_t;
typedef struct gmx_hash {
- int mod;
- int mask;
- int nalloc;
+ int mod;
+ int mask;
+ int nalloc;
int *direct;
gmx_hash_e_t *hash;
- int nkey;
- int start_space_search;
+ int nkey;
+ int start_space_search;
} t_gmx_hash;
/* Clear all the entries in the hash table */
{
int i;
- for(i=0; i<hash->nalloc; i++)
+ for (i = 0; i < hash->nalloc; i++)
{
hash->hash[i].key = -1;
hash->hash[i].next = -1;
hash->nkey = 0;
}
-static void gmx_hash_realloc(gmx_hash_t hash,int nkey_used_estimate)
+static void gmx_hash_realloc(gmx_hash_t hash, int nkey_used_estimate)
{
/* Memory requirements:
* nkey_used_est*(2+1-2(1-e^-1/2))*3 ints
{
hash->mod *= 2;
}
- hash->mask = hash->mod - 1;
+ hash->mask = hash->mod - 1;
hash->nalloc = over_alloc_dd(hash->mod);
- srenew(hash->hash,hash->nalloc);
+ srenew(hash->hash, hash->nalloc);
if (debug != NULL)
{
- fprintf(debug,"Hash table mod %d nalloc %d\n",hash->mod,hash->nalloc);
+ fprintf(debug, "Hash table mod %d nalloc %d\n", hash->mod, hash->nalloc);
}
}
{
if (debug != NULL)
{
- fprintf(debug,"Hash table size %d #key %d: resizing\n",
- hash->mod,hash->nkey);
+ fprintf(debug, "Hash table size %d #key %d: resizing\n",
+ hash->mod, hash->nkey);
}
- gmx_hash_realloc(hash,hash->nkey);
+ gmx_hash_realloc(hash, hash->nkey);
}
gmx_hash_clear(hash);
{
gmx_hash_t hash;
- snew(hash,1);
+ snew(hash, 1);
hash->hash = NULL;
- gmx_hash_realloc(hash,nkey_used_estimate);
+ gmx_hash_realloc(hash, nkey_used_estimate);
gmx_hash_clear(hash);
}
/* Set the hash entry for global atom a_gl to local atom a_loc and cell. */
-static void gmx_hash_set(gmx_hash_t hash,int key,int value)
+static void gmx_hash_set(gmx_hash_t hash, int key, int value)
{
- int ind,ind_prev,i;
+ int ind, ind_prev, i;
ind = key & hash->mask;
-
+
if (hash->hash[ind].key >= 0)
{
/* Search the last entry in the linked list for this index */
ind_prev = ind;
- while(hash->hash[ind_prev].next >= 0)
+ while (hash->hash[ind_prev].next >= 0)
{
ind_prev = hash->hash[ind_prev].next;
}
if (ind == hash->nalloc)
{
hash->nalloc = over_alloc_dd(ind+1);
- srenew(hash->hash,hash->nalloc);
- for(i=ind; i<hash->nalloc; i++)
+ srenew(hash->hash, hash->nalloc);
+ for (i = ind; i < hash->nalloc; i++)
{
hash->hash[i].key = -1;
hash->hash[i].next = -1;
}
}
hash->hash[ind_prev].next = ind;
-
+
hash->start_space_search = ind + 1;
}
hash->hash[ind].key = key;
}
/* Delete the hash entry for key */
-static void gmx_hash_del(gmx_hash_t hash,int key)
+static void gmx_hash_del(gmx_hash_t hash, int key)
{
- int ind,ind_prev;
+ int ind, ind_prev;
ind_prev = -1;
- ind = key & hash->mask;
+ ind = key & hash->mask;
do
{
if (hash->hash[ind].key == key)
return;
}
ind_prev = ind;
- ind = hash->hash[ind].next;
+ ind = hash->hash[ind].next;
}
while (ind >= 0);
}
/* Change the value for present hash entry for key */
-static void gmx_hash_change_value(gmx_hash_t hash,int key,int value)
+static void gmx_hash_change_value(gmx_hash_t hash, int key, int value)
{
int ind;
ind = key & hash->mask;
do
- {
+ {
if (hash->hash[ind].key == key)
{
hash->hash[ind].val = value;
-
+
return;
}
ind = hash->hash[ind].next;
}
/* Change the hash value if already set, otherwise set the hash value */
-static void gmx_hash_change_or_set(gmx_hash_t hash,int key,int value)
+static void gmx_hash_change_or_set(gmx_hash_t hash, int key, int value)
{
int ind;
ind = key & hash->mask;
do
- {
+ {
if (hash->hash[ind].key == key)
{
hash->hash[ind].val = value;
}
while (ind >= 0);
- gmx_hash_set(hash,key,value);
+ gmx_hash_set(hash, key, value);
return;
}
/* Returns if the key is present, if the key is present *value is set */
-static gmx_bool gmx_hash_get(const gmx_hash_t hash,int key,int *value)
+static gmx_bool gmx_hash_get(const gmx_hash_t hash, int key, int *value)
{
int ind;
}
/* Returns the value or -1 if the key is not present */
-static int gmx_hash_get_minone(const gmx_hash_t hash,int key)
+static int gmx_hash_get_minone(const gmx_hash_t hash, int key)
{
int ind;