uint64_t ent_key = ent->key;
if (ent_key == DOES_NOT_EXIST) {
TRACE("h1", "hti_lookup: entry %p for key %p is empty", ent,
uint64_t ent_key = ent->key;
if (ent_key == DOES_NOT_EXIST) {
TRACE("h1", "hti_lookup: entry %p for key %p is empty", ent,
*is_empty = 1; // indicate an empty so the caller avoids an expensive key compare
return ent;
}
// Compare <key> with the key in the entry.
*is_empty = 1; // indicate an empty so the caller avoids an expensive key compare
return ent;
}
// Compare <key> with the key in the entry.
// fast path for integer keys
if (ent_key == (uint64_t)key) {
TRACE("h1", "hti_lookup: found entry %p with key %p", ent, ent_key);
// fast path for integer keys
if (ent_key == (uint64_t)key) {
TRACE("h1", "hti_lookup: found entry %p with key %p", ent, ent_key);
// The key in <ent> is made up of two parts. The 48 low-order bits are a pointer. The
// high-order 16 bits are taken from the hash. The bits from the hash are used as a
// quick check to rule out non-equal keys without doing a complete compare.
// The key in <ent> is made up of two parts. The 48 low-order bits are a pointer. The
// high-order 16 bits are taken from the hash. The bits from the hash are used as a
// quick check to rule out non-equal keys without doing a complete compare.
TRACE("h1", "hti_lookup: found entry %p with key %p", ent, GET_PTR(ent_key));
return ent;
}
TRACE("h1", "hti_lookup: found entry %p with key %p", ent, GET_PTR(ent_key));
return ent;
}
// The old table's dead entries don't need to be copied to the new table, but their keys need to be freed.
assert(COPIED_VALUE == TAG_VALUE(TOMBSTONE));
if (ht1_ent_val == TOMBSTONE) {
TRACE("h1", "hti_copy_entry: entry %p old value was deleted, now freeing key %p", ht1_ent, key);
// The old table's dead entries don't need to be copied to the new table, but their keys need to be freed.
assert(COPIED_VALUE == TAG_VALUE(TOMBSTONE));
if (ht1_ent_val == TOMBSTONE) {
TRACE("h1", "hti_copy_entry: entry %p old value was deleted, now freeing key %p", ht1_ent, key);
// We use 0 to indicate that <key_hash> is uninitiallized. Occasionally the key's hash will really be 0 and we
// waste time recomputing it every time. It is rare enough (1 in 65k) that it won't hurt performance.
if (key_hash == 0) {
// We use 0 to indicate that <key_hash> is uninitiallized. Occasionally the key's hash will really be 0 and we
// waste time recomputing it every time. It is rare enough (1 in 65k) that it won't hurt performance.
if (key_hash == 0) {
- uint64_t new_key = (uint64_t)((hti->ht->clone_fun == NULL) ? key : hti->ht->clone_fun(key));
- if (EXPECT_FALSE(hti->ht->hash_fun != NULL)) {
+ uint64_t new_key = (uint64_t)((hti->ht->key_type == NULL) ? key : hti->ht->key_type->clone(key));
+ if (EXPECT_FALSE(hti->ht->key_type != NULL)) {
// Combine <new_key> pointer with bits from its hash
new_key = ((uint64_t)(key_hash >> 16) << 48) | new_key;
}
// Combine <new_key> pointer with bits from its hash
new_key = ((uint64_t)(key_hash >> 16) << 48) | new_key;
}
if (old_ent_key != DOES_NOT_EXIST) {
TRACE("h0", "hti_cas: lost race to install key %p in entry %p", new_key, ent);
TRACE("h0", "hti_cas: found %p instead of NULL",
if (old_ent_key != DOES_NOT_EXIST) {
TRACE("h0", "hti_cas: lost race to install key %p in entry %p", new_key, ent);
TRACE("h0", "hti_cas: found %p instead of NULL",
- (hti->ht->clone_fun != NULL) ? (void *)old_ent_key : GET_PTR(old_ent_key), 0);
- if (hti->ht->clone_fun != NULL) {
+ (hti->ht->key_type == NULL) ? (void *)old_ent_key : GET_PTR(old_ent_key), 0);
+ if (hti->ht->key_type != NULL) {
nbd_free(GET_PTR(new_key));
}
return hti_cas(hti, key, key_hash, expected, new); // tail-call
nbd_free(GET_PTR(new_key));
}
return hti_cas(hti, key, key_hash, expected, new); // tail-call
// If the entry is in the middle of a copy, the copy must be completed first.
uint64_t ent_val = ent->val;
// If the entry is in the middle of a copy, the copy must be completed first.
uint64_t ent_val = ent->val;
while ((old_val = hti_cas(hti, key, key_hash, expected_val, new_val)) == COPIED_VALUE) {
assert(hti->next);
hti = hti->next;
while ((old_val = hti_cas(hti, key, key_hash, expected_val, new_val)) == COPIED_VALUE) {
assert(hti->next);
hti = hti->next;
do {
val = hti_cas(hti, key, key_hash, CAS_EXPECT_WHATEVER, TOMBSTONE);
if (val != COPIED_VALUE)
do {
val = hti_cas(hti, key, key_hash, CAS_EXPECT_WHATEVER, TOMBSTONE);
if (val != COPIED_VALUE)
do {
for (uint32_t i = 0; i < (1 << hti->scale); ++i) {
assert(hti->table[i].val == COPIED_VALUE || !IS_TAGGED(hti->table[i].val));
do {
for (uint32_t i = 0; i < (1 << hti->scale); ++i) {
assert(hti->table[i].val == COPIED_VALUE || !IS_TAGGED(hti->table[i].val));