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

Function hash_trigrams

src/simhash/minhash.c:221–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221static int hash_trigrams(const char **tokens, int token_count, cbm_minhash_t *out) {
222 for (int k = 0; k < CBM_MINHASH_K; k++) {
223 out->values[k] = UINT32_MAX;
224 }
225
226 uniq_trig_set_t uniq;
227 uniq_trig_init(&uniq);
228 char trigram_buf[TRIGRAM_BUF_LEN];
229
230 for (int i = 0; i + TRIGRAM_WINDOW < token_count; i++) {
231 int w =
232 trigram_structural_weight(tokens[i], tokens[i + SKIP_ONE], tokens[i + TRIGRAM_WINDOW]);
233 if (w == 0) {
234 continue;
235 }
236
237 int len = snprintf(trigram_buf, sizeof(trigram_buf), "%s|%s|%s", tokens[i],
238 tokens[i + SKIP_ONE], tokens[i + TRIGRAM_WINDOW]);
239 if (len <= 0 || (size_t)len >= sizeof(trigram_buf)) {
240 continue;
241 }
242
243 uniq_trig_insert(&uniq, XXH3_64bits(trigram_buf, (size_t)len));
244 weighted_minhash_update(out, trigram_buf, len, w);
245 }
246 return uniq.count;
247}
248
249bool cbm_minhash_compute(TSNode func_body, const char *source, int language, cbm_minhash_t *out) {
250 (void)source;

Callers 1

cbm_minhash_computeFunction · 0.85

Calls 4

uniq_trig_initFunction · 0.85
uniq_trig_insertFunction · 0.85
weighted_minhash_updateFunction · 0.85

Tested by

no test coverage detected