Lines Matching defs:table
40 PHashTable *table;
76 PHashTable **table)
81 if (table == NULL ||
125 *table = tmp;
129 ESR_ReturnCode PHashTableDestroy(PHashTable *table)
133 if (table == NULL)
136 block = table->entryBlock;
144 FREE(table->entries);
145 FREE(table);
149 ESR_ReturnCode PHashTableGetSize(PHashTable *table,
152 if (table == NULL || size == NULL)
155 *size = table->size;
159 static PHashTableEntry *getEntry(PHashTable *table,
164 PHashTableEntry *entry = table->entries[idx];
180 if (entry->hashCode == hashCode && table->args.compFunction(key, entry->key) == 0)
193 entry->table->entries[entry->idx] = entry->next;
200 entry->table->size--;
202 entry->next = entry->table->freeList;
203 entry->table->freeList = entry;
208 ESR_ReturnCode PHashTableGetValue(PHashTable *table, const void *key, void **value)
214 if (table == NULL || value == NULL)
217 hashCode = table->args.hashFunction(key);
218 idx = hashCode % table->args.capacity;
219 if ((entry = getEntry(table, key, hashCode, idx)) != NULL)
231 ESR_ReturnCode PHashTableContainsKey(PHashTable *table, const void *key, ESR_BOOL* exists)
236 if (table == NULL || exists == NULL)
242 rc = PHashTableGetEntry(table, key, &entry);
255 ESR_ReturnCode PHashTableGetEntry(PHashTable *table, const void *key, PHashTableEntry **entry)
261 if (table == NULL || entry == NULL)
264 hashCode = table->args.hashFunction(key);
265 idx = hashCode % table->args.capacity;
267 result = getEntry(table, key, hashCode, idx);
274 static ESR_ReturnCode PHashTableRehash(PHashTable *table)
277 unsigned int oldCapacity = table->args.capacity;
283 REALLOC(table->entries,
289 table->entries = newEntries;
290 table->args.capacity = newCapacity;
291 table->threshold = (unsigned int)(newCapacity * table->args.maxLoadFactor);
295 table->entries[i] = NULL;
300 for (entry = table->entries[i]; entry != NULL;)
313 table->entries[i] = next;
318 tmp = table->entries[idx];
323 table->entries[idx] = entry;
338 ESR_ReturnCode PHashTablePutValue(PHashTable *table,
347 if (table == NULL) return ESR_INVALID_ARGUMENT;
348 hashCode = table->args.hashFunction(key);
349 idx = hashCode % table->args.capacity;
351 entry = getEntry(table, key, hashCode, idx);
361 if (table->size >= table->threshold)
363 if ((rc = PHashTableRehash(table)) != ESR_SUCCESS)
365 idx = hashCode % table->args.capacity;
368 if (table->freeList == NULL)
374 block = NEW(PHashTableEntryBlock, table->memoryTag);
378 block->next = table->entryBlock;
379 table->entryBlock = block;
394 entry->next = table->freeList;
397 table->freeList = block->entries;
401 entry = table->freeList;
402 table->freeList = entry->next;
405 entry->table = table;
410 entry->next = table->entries[idx];
414 table->entries[idx] = entry;
415 table->size++;
422 ESR_ReturnCode PHashTableRemoveValue(PHashTable *table,
430 if (table == NULL)
437 hashCode = table->args.hashFunction(key);
438 idx = hashCode % table->args.capacity;
440 entry = getEntry(table, key, hashCode, idx);
488 * Removes the entry from its hash table.
502 static PHashTableEntry* iteratorAdvance(PHashTable *table, PHashTableEntry *entry)
512 while (++idx < table->args.capacity)
514 if (table->entries[idx] != NULL)
516 entry = table->entries[idx];
524 for (idx = 0; idx < table->args.capacity; ++idx)
526 if (table->entries[idx] != NULL)
528 entry = table->entries[idx];
537 ESR_ReturnCode PHashTableEntryGetFirst(PHashTable *table, PHashTableEntry **entry)
539 if (table == NULL || entry == NULL)
542 *entry = iteratorAdvance(table, NULL);
547 * Iterates on the next key and value. Returns a NULL key when at the end of the hash table.
558 *entry = iteratorAdvance((*entry)->table, *entry);