MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ckh_try_bucket_insert

Function ckh_try_bucket_insert

deps/jemalloc/src/ckh.c:101–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101static bool
102ckh_try_bucket_insert(ckh_t *ckh, size_t bucket, const void *key,
103 const void *data) {
104 ckhc_t *cell;
105 unsigned offset, i;
106
107 /*
108 * Cycle through the cells in the bucket, starting at a random position.
109 * The randomness avoids worst-case search overhead as buckets fill up.
110 */
111 offset = (unsigned)prng_lg_range_u64(&ckh->prng_state,
112 LG_CKH_BUCKET_CELLS);
113 for (i = 0; i < (ZU(1) << LG_CKH_BUCKET_CELLS); i++) {
114 cell = &ckh->tab[(bucket << LG_CKH_BUCKET_CELLS) +
115 ((i + offset) & ((ZU(1) << LG_CKH_BUCKET_CELLS) - 1))];
116 if (cell->key == NULL) {
117 cell->key = key;
118 cell->data = data;
119 ckh->count++;
120 return false;
121 }
122 }
123
124 return true;
125}
126
127/*
128 * No space is available in bucket. Randomly evict an item, then try to find an

Callers 2

ckh_evict_reloc_insertFunction · 0.70
ckh_try_insertFunction · 0.70

Calls 1

prng_lg_range_u64Function · 0.50

Tested by

no test coverage detected