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

Function gb_intern

src/graph_buffer/graph_buffer.c:134–145  ·  view source on GitHub ↗

Intern a repetitive string into the buffer's pool: identical content collapses * to a single heap copy owned by the pool. NULL maps to "{}" (matches * heap_strdup). The returned pointer is stable for the buffer's lifetime and * must never be freed or mutated by callers. Returns NULL only on OOM. */

Source from the content-addressed store, hash-verified

132 * heap_strdup). The returned pointer is stable for the buffer's lifetime and
133 * must never be freed or mutated by callers. Returns NULL only on OOM. */
134static const char *gb_intern(cbm_gbuf_t *gb, const char *s) {
135 const char *key = s ? s : "{}";
136 const char *found = cbm_ht_get(gb->intern_pool, key);
137 if (found) {
138 return found;
139 }
140 char *copy = strdup(key);
141 if (copy) {
142 cbm_ht_set(gb->intern_pool, copy, copy); /* key == value == owned copy */
143 }
144 return copy;
145}
146
147static void make_id_key(char *buf, size_t bufsz, int64_t id) {
148 snprintf(buf, bufsz, "%lld", (long long)id);

Callers 4

cbm_gbuf_upsert_nodeFunction · 0.85
cbm_gbuf_insert_edgeFunction · 0.85
merge_update_existingFunction · 0.85
merge_copy_new_nodeFunction · 0.85

Calls 2

cbm_ht_getFunction · 0.85
cbm_ht_setFunction · 0.85

Tested by

no test coverage detected