Skip to content

Commit

Permalink
Fixup hashtable: Delete unsed function hashtableReplace
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Söderqvist <[email protected]>
  • Loading branch information
zuiderkwast committed Dec 2, 2024
1 parent 9a2e4e1 commit c957864
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
27 changes: 5 additions & 22 deletions src/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,23 +1301,6 @@ void hashtableInsertAtPosition(hashtable *ht, void *entry, hashtablePosition *po
/* Hash bits are already set by hashtableFindPositionForInsert. */
}

/* Add or overwrite. Returns 1 if an new entry was inserted, 0 if an existing
* entry was overwritten. */
int hashtableReplace(hashtable *ht, void *entry) {
const void *key = entryGetKey(ht, entry);
int pos_in_bucket = 0;
uint64_t hash = hashKey(ht, key);
bucket *b = findBucket(ht, hash, key, &pos_in_bucket, NULL);
if (b != NULL) {
freeEntry(ht, b->entries[pos_in_bucket]);
b->entries[pos_in_bucket] = entry;
return 0;
} else {
insert(ht, hash, entry);
return 1;
}
}

/* Removes the entry with the matching key and returns it. The entry
* destructor is not called. Returns 1 and points 'popped' to the entry if a
* matching entry was found. Returns 0 if no matching entry was found. */
Expand Down Expand Up @@ -1776,18 +1759,18 @@ void hashtableInitIterator(hashtableIterator *iterator, hashtable *ht) {
*
* It's allowed to insert and replace entries. Deleting entries is only allowed
* for the entry that was just returned by hashtableNext. Deleting other entries
* are not supported. (It can cause internal fragmentation.)
* is possible, but doing so can cause internal fragmentation, so don't.
*
* Guarantees:
*
* - Entries that are in the hash table for the entire iteration are returned
* exactly once.
*
* - Entries that are deleted or replaced using hashtableReplace after they
* have been returned are not returned again.
* - Entries that are deleted or replaced after they have been returned are not
* returned again.
*
* - Entries that are replaced using hashtableReplace before they've been
* returned by the iterator will be returned.
* - Entries that are replaced before they've been returned by the iterator will
* be returned.
*
* - Entries that are inserted during the iteration may or may not be returned
* by the iterator.
Expand Down
1 change: 0 additions & 1 deletion src/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ int hashtableAdd(hashtable *ht, void *entry);
int hashtableAddOrFind(hashtable *ht, void *entry, void **existing);
int hashtableFindPositionForInsert(hashtable *ht, void *key, hashtablePosition *position, void **existing);
void hashtableInsertAtPosition(hashtable *ht, void *entry, hashtablePosition *position);
int hashtableReplace(hashtable *ht, void *entry);
int hashtablePop(hashtable *ht, const void *key, void **popped);
int hashtableDelete(hashtable *ht, const void *key);
void **hashtableTwoPhasePopFindRef(hashtable *ht, const void *key, hashtablePosition *position);
Expand Down

0 comments on commit c957864

Please sign in to comment.