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

Function gb_intern

src/graph_buffer/graph_buffer.c:130–141  ·  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

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