hashTable_t * makeHashTable() { hashTable_t * ht = (hashTable_t *)malloc(sizeof(hashTable_t)); if (ht == NULL) fatalError("samblaster: unable to allocate hash table.\n"); hashTableInit(ht, hashTableSizes[0]); return ht; }
size_t mx_create_hashtable(unsigned int hashtable_size) { HASH_TABLE *hash; hash = (HASH_TABLE*)malloc(sizeof(HASH_TABLE)); hashTableInit(hash); return (size_t)hash; }
void mx_ht_clear(size_t ht) { HASH_TABLE *hash; hash = (HASH_TABLE*)ht; hashTableDestroy(hash); hashTableInit(hash); }
Fsm::Fsm() { hashTableInit(&mStates, 32); mInit = false; mCurrent = 0; mOld = 0; mCallback = 0; mInitCallback = 0; }
void lruCacheInit(int capacity) { mCacheSize = 0; mCapacity = capacity; mCacheList = malloc(sizeof(struct LRUItem) * capacity); mCacheListLast = mCacheList; mHeadItem = NULL; mTailItem = NULL; hashTableInit(capacity); }
void resizeHashTable(hashTable_t * ht) { // Find out what size table is next. int newsize = 0; for (int i=0; i<numOfSizes; i++) { if (hashTableSizes[i] == ht->size) { newsize = hashTableSizes[i+1]; break; } } // Remember the current values array. UINT64 * oldtable = ht->table; int size = ht->size; // Now reinit the hash table with a new table, etc. hashTableInit(ht, newsize); // Now iterate over all values and rehash them into the new table. for (int i=0; i<size; i++) { UINT64 value = oldtable[i]; if (isEmpty(value)) continue; if (isValue(value)) { hashTableInsert(ht, unmakeValue(value)); continue; } // We need to iterate through the nodes. hashNode_t * node = makePtr(value); while (true) { for (int j=0; j<HASHNODE_PAYLOAD_SIZE; j++) { value = node->values[j]; if (isEmpty(value)) break; hashTableInsert(ht, unmakeValue(value)); } if (node->next == NULL) break; node = node->next; } // We need to free up the nodes. // TODO move out of line. node->next = hashNodeFreeList; hashNodeFreeList = makePtr(oldtable[i]); } // Free up the oldtable. if (oldtable != NULL) free(oldtable); }
static void* searchEntryFromTable(const char *key) { ENTRY e,*ep; if (key == NULL) { return NULL; } hashTableInit(); e.key = (char*)key; LOCK_HASH_TABLE(); ep = hsearch(e, FIND); UNLOCK_HASH_TABLE(); if (ep != NULL) { return ep->data; } return NULL; }
static int insertEntryIntoTable(const char *key, void *data) { ENTRY e, *ep; if (key == NULL || data == NULL) { return 0; } if (! hashTableInit()) { return -1; } e.data = data; e.key = (char*)key; LOCK_HASH_TABLE(); ep = hsearch(e, ENTER); UNLOCK_HASH_TABLE(); if (ep == NULL) { fprintf(stderr, "warn adding key (%s) to hash table, <%d>: %s\n", key, errno, strerror(errno)); } return 0; }
void GlobalFactory::init() { hashTableInit(&idPool, 10); hashTableInit(&typePool, 10); }