Download

intern

A string/data interning library for C

Docs 447 wordsText 309Markdown 138
NameModifiedLinesSize
.gitignore 1 line<1% of this folder's lines 5 B<1% of this folder's bytes
.gitmodules 3 lines<1% of this folder's lines 78 B<1% of this folder's bytes
LICENSE 40 lines11% of this folder's lines 1.9 KiB17% of this folder's bytes
Makefile 32 lines9% of this folder's lines 740 B6% of this folder's bytes
README.md 36 lines10% of this folder's lines 1 KiB9% of this folder's bytes
SipHash @ 7ce54fc 0 lines0% of this folder's lines 0 B0% of this folder's bytes
intern.c 225 lines63% of this folder's lines 6.8 KiB59% of this folder's bytes
intern.h 23 lines6% of this folder's lines 1001 B8% of this folder's bytes

README.md

Intern

A minimalist string (or arbitrary data) interning library meant to work with the Boehm garbage collector. The interning uses SipHash for fast and secure hashing.

API

// Intern a chunk of bytes which may or may not contain references to GC objects
const void *intern_bytes(const char *bytes, size_t len);
// Intern a NUL-terminated string
const char *intern_str(const char *str);
// Intern a length-delimited string (automatically appending a terminating NUL byte)
// (Useful for interning a slice of a string)
const char *intern_strn(const char *str, size_t len);
// Randomize the hash function used for interning
void randomize_hash(void);

Usage

Here's a simple example usage:

const char *str1 = intern_str("hello");
const char *str2 = intern_str("hello");
assert(str1 == str2);
const char *str3 = intern_strn("hello world", 5);
assert(str3 == str1);

License

This library is released under the MIT license with the commons clause. See the LICENSE file for full details.