Add FNV-1a string hash and string intern table #3
Loading…
Reference in a new issue
No description provided.
Delete branch "fputs/intern"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds FNV-1a 64
lfstr_hash,lfstr_hash_cb, andlfstr_match, plus anLfInterntable.The hash is xor-then-multiply with the standard offset basis and prime, narrowed to
size_t. There is no seed. An empty view returns the offset basis and does not readp.lfstr_matchfollows the hash-map convention:0means equal.LfInternis a complete struct so the caller can own the handle.mapandslabsare private. Each distinct string is its own block (the bytes, a trailing NUL that is not counted inn, and the storedLfStr). A later intern does not move earlier pointers. Duplicates, including the empty string, return the same pointer and do not allocate again.destroyfrees the blocks. The caller does not free an internedp.flint_alloc_faildoes not link libflint, so that test also buildsstring.candmemory.c(the string object referencesarena_malloc). The armed failure is the second distinct string'smalloc. The first string stays readable and the output sentinel is unchanged.Tested with
-DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF.ctest --label-exclude slow: 26/26 passed.cde39a5633e4f268108ce4f268108caf62840717