MCPcopy Create free account
hub / github.com/NetHack/NetHack / add_glyph_to_cache

Function add_glyph_to_cache

src/glyphs.c:371–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369}
370
371staticfn void
372add_glyph_to_cache(int glyphnum, const char *id)
373{
374 uint32 hash = glyph_hash(id);
375 size_t hash1 = (size_t) (hash & (glyphid_cache_size - 1));
376 size_t hash2 = (size_t)
377 (((hash >> glyphid_cache_lsize) & (glyphid_cache_size - 1)) | 1);
378 size_t i = hash1;
379
380 do {
381 if (glyphid_cache[i].id == NULL) {
382 /* Empty bucket found */
383 glyphid_cache[i].id = dupstr(id);
384 glyphid_cache[i].glyphnum = glyphnum;
385 return;
386 }
387 /* For speed, assume that no ID occurs twice */
388 i = (i + hash2) & (glyphid_cache_size - 1);
389 } while (i != hash1);
390 /* This should never happen */
391 panic("glyphid_cache full");
392}
393
394staticfn int
395find_glyph_in_cache(const char *id)

Callers 1

parse_idFunction · 0.85

Calls 3

glyph_hashFunction · 0.85
dupstrFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected