MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_ht_set

Function cbm_ht_set

src/foundation/hash_table.c:126–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126void *cbm_ht_set(CBMHashTable *ht, const char *key, void *value) {
127 if (!ht || !key)
128 return NULL;
129 /* ONE probe: get_or_insert either inserts (key, value) or hands back the
130 * existing entry, whose previous value is returned and whose key AND value
131 * are replaced -- exactly what _insert did. The old get-then-insert hashed
132 * every key twice: 83 M repeated strlen calls inside vt_hash_string on the
133 * Go corpus (waste sanitizer, 2026-09-17). Verstable reports an insertion
134 * as a size change. */
135 void *prev = NULL;
136 HT_WROTE(ht);
137#if defined(CBM_MEMWASTE) && CBM_MEMWASTE
138 size_t buckets_before = cbm_vt_bucket_count(&ht->vt);
139#endif
140 size_t size_before = cbm_vt_size(&ht->vt);
141 cbm_vt_itr itr = cbm_vt_get_or_insert(&ht->vt, key, value);
142 if (!cbm_vt_is_end(itr) && cbm_vt_size(&ht->vt) == size_before) {
143 prev = itr.data->val;
144 itr.data->key = key;
145 itr.data->val = value;
146 }
147#if defined(CBM_MEMWASTE) && CBM_MEMWASTE
148 bool grew = cbm_vt_bucket_count(&ht->vt) != buckets_before;
149 if (grew) {
150 ht->waste_growths++;
151 }
152 if (cbm_memev_enabled()) {
153 cbm_work_note(CBM_WORK_HT_SET, ht->waste_site, 0, grew ? 1 : 0, 0);
154 }
155#endif
156 return prev;
157}
158
159void *cbm_ht_get(const CBMHashTable *ht, const char *key) {
160 if (!ht || !key)

Callers 15

dg_elementFunction · 0.85
dg_excalidrawFunction · 0.85
php_count_nameFunction · 0.85
cbm_quarantine_loadFunction · 0.85
c_static_namesFunction · 0.85
cbm_doclink_c_scan_scopeFunction · 0.85
cbm_run_kotlin_lsp_crossFunction · 0.85
ensure_pretrained_mapFunction · 0.85

Calls 2

cbm_memev_enabledFunction · 0.85
cbm_work_noteFunction · 0.85

Tested by 12

te_cov_pushFunction · 0.68
ti_add_suffixesFunction · 0.68
cbm_ti_source_finishFunction · 0.68
ti_note_occurrenceFunction · 0.68
ts_load_fileFunction · 0.68
cbm_ti_graph_has_nameFunction · 0.68
ts_add_nodeFunction · 0.68
ts_add_wholeFunction · 0.68
ts_add_deletedFunction · 0.68
ts_names_addFunction · 0.68
ts_index_modelFunction · 0.68
te_reached_namesFunction · 0.68