Master the fundamental concepts of memory optimization through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksCompilers, JVMs, and Python intern identifiers and literal strings so equality checks become pointer compares. Parsing millions of JSON keys benefits when the same field name like status appears on every row.
Hash table maps string content to canonical storage. On insert, return existing pointer if hash and bytes match.
cLoading…
strcmp on collisionKeep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will implement a string intern table and show reduced memory on repetitive input. This exercise asks you to verify that equal strings share one address.
Compilers, interpreters and parsers see the same identifiers thousands of times. String interning stores each distinct string once and hands out a small integer id. Equal strings then compare as equal ids, and duplicates cost nothing. Build an interning table on an open-addressing hash table with FNV-1a hashing and linear probing, which grows to keep the load factor at or below 3/4.
cLoading…
h = 2166136261; for each byte: h ^= byte; h *= 16777619 (mod 2^32).h & (capacity − 1). Probe the following slots with wrap-around until you find an equal string (existing) or an empty slot (new). The probe count is the number of slots examined, including the last one.(count + 1) * 4 > capacity * 3, double the capacity and reinsert every string in id order, then find the new string's slot. Ids are assigned 0, 1, 2… in order of first appearance.capacity: table already in use, capacity: power of two, 1..4096, and WORD -> table full (1024 strings at most).cLoading…
Input:
cLoading…
Output:
cLoading…
Hidden tests cover repeated resizes starting from a capacity of 1, repeated words, lookups of missing words, and invalid capacity commands.