/* looks up key in hashtable and returns blind data */ void* XRayHashTableLookup(struct XRayHashTable *table, uint32_t key) { uint32_t h = XRayHashTableHashKey(key); uint32_t m = table->size - 1; uint32_t j = h & m; uint32_t i; int z = 1; for (i = 0; i < m; ++i) { /* an empty entry means the {key, data} isn't in the table */ if (NULL == table->array[j].data) { ++g_hash_histo[0]; return NULL; } /* search for address */ if (table->array[j].key == key) { if (z >= HASH_HISTO) z = HASH_HISTO - 1; ++g_hash_histo[z]; return table->array[j].data; } j = (j + 1) & m; ++z; } /* table was full, and there wasn't a match */ return NULL; }
void* XRayHashTableInsert(struct XRayHashTable* table, void* data, uint32_t key) { uint32_t h = XRayHashTableHashKey(key); uint32_t m = table->capacity - 1; uint32_t j = h & m; uint32_t i; for (i = 0; i < m; ++i) { if (NULL == table->array[j].data) { void* ret; float ratio; table->array[j].data = data; table->array[j].key = key; ++table->count; ret = data; ratio = (float)table->count / (float)table->capacity; if (ratio > XRAY_SYMBOL_TABLE_MAX_RATIO) XRayHashTableGrow(table); return ret; } if (table->array[j].key == key) { return table->array[j].data; } j = (j + 1) & m; } return NULL; }
/* inserts key & data into hash table. No duplicates. */ void* XRayHashTableInsert(struct XRayHashTable *table, void *data, uint32_t key) { uint32_t h = XRayHashTableHashKey(key); uint32_t m = table->size - 1; uint32_t j = h & m; uint32_t i; for (i = 0; i < m; ++i) { /* take the first empty entry */ /* (the key,data isn't already in the table) */ if (NULL == table->array[j].data) { void *ret; float ratio; table->array[j].data = data; table->array[j].key = key; ++table->count; ret = data; ratio = (float)table->count / (float)table->size; /* double the size of the symtable if we've hit the ratio */ if (ratio > XRAY_SYMBOL_TABLE_MAX_RATIO) XRayHashTableGrow(table); return ret; } /* if the key is already present, return the data in the table */ if (table->array[j].key == key) { return table->array[j].data; } j = (j + 1) & m; } /* table was full */ return NULL; }
void* XRayHashTableLookup(struct XRayHashTable* table, uint32_t key) { uint32_t h = XRayHashTableHashKey(key); uint32_t m = table->capacity - 1; uint32_t j = h & m; uint32_t i; int z = 1; for (i = 0; i < m; ++i) { if (NULL == table->array[j].data) { ++g_hash_histo[0]; return NULL; } if (table->array[j].key == key) { if (z >= HASH_HISTO) z = HASH_HISTO - 1; ++g_hash_histo[z]; return table->array[j].data; } j = (j + 1) & m; ++z; } return NULL; }