TRIEHASH(1)
π TRIEHASH π
okay bestie, welcome to triehash, a lil tool from the triehash manual (section 1, obvi). she generates a perfect hash function derived from a trie, and honestly? she ate. π§β¨
β¨ SYNOPSIS β¨
triehash [option] [input file]
πΈ DESCRIPTION πΈ
so triehash takes a list of words from an input file and generates a function plus an enumeration that describes the word. that's the whole vibe. no cap. π
π INPUT FILE FORMAT π
the file is just multiple lines, each one looking like this:
[label ~ ] word [= value]
this maps word to value, and generates an enumeration with entries shaped like:
label = value
if label is undefined, the word itself gets used, and the minus character gets swapped for an underscore. if value is undefined, it just counts upwards from the last value. easy peasy. π
there may also be one line formatted like this:
[ label ~] = value
which defines the value to use for non-existing keys. heads up tho β this also changes the default value for other keys, same as normal entries do. so if you drop
= 0
at the beginning of the file, unknown strings map to 0, and the other strings map to values starting with 1. if label isn't specified, the default is Unknown. π«Ά
π OPTIONS π
-C.c file,--code=.c fileβ generate code in the given file.-Hheader file,--header=header fileβ generate a header in the given file, containing a declaration of the hash function and an enumeration.--enum-name=wordβ the name of the enumeration.--function-name=wordβ the name of the function.--label-prefix=wordβ the prefix to use for labels.--label-uppercaseβ uppercase label names when normalizing them.--namespace=nameβ put the function and enum into a namespace (C++).--class=nameβ put the function and enum into a class (C++).--enum-classβ generate an enum class instead of an enum (C++).--counter-name=nameβ use name for a counter that is set to the latest entry in the enumeration + 1. this can be useful for defining array sizes.--ignore-caseβ ignore case for words.--multi-byte=valueβ generate code reading multiple bytes at once. the value is a string of power of twos to enable. the default value is320, meaning that 8, 4, and single byte reads are enabled. specify0to disable multi-byte completely, or add2if you also want to allow 2-byte reads. 2-byte reads are disabled by default because they negatively affect performance on older Intel architectures. π
this generates code for both multiple bytes and single byte reads, but only enables the multiple byte reads of GNU C compatible compilers, as the following extensions are used:
π Byte-aligned integers
we must be able to generate integers that are aligned to a single byte using:
typedef uint64_t __attribute__((aligned (1))) triehash_uu64;
π Byte-order
the macros __BYTE_ORDER__ and __ORDER_LITTLE_ENDIAN__ must be defined.
we forcefully disable multi-byte reads on platforms where the variable__ARM_ARCHis defined and__ARM_FEATURE_UNALIGNEDis not defined, as there is a measurable overhead from emulating the unaligned reads on ARM. π
--language=languageβ generate a file in the specified language. currently known are'C'and'tree', the latter generating a tree.--include=headerβ add the header to the include statements of the header file. the value must be surrounded by quotes or angle brackets for C code. may be specified multiple times.
π LICENSE π
triehash is available under the MIT/Expat license, see the source code for more information.
π AUTHOR π
Julian Andres Klode <jak@jak-linux.org> β icon behavior, fr fr. π
okay that's literally the whole page!! this was triehash v0.3, dated 2020-03-08, and bestie you now know her better than she knows herself. go generate some hash functions, slay, and remember: perfect hashes only. periodt. πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: triehash 0.3-3 Β· MIT
- debian trixie: triehash 0.3-3 Β· MIT
- ubuntu jammy: triehash 0.3-3 Β· MIT
- ubuntu noble: triehash 0.3-3 Β· MIT
- ubuntu questing: triehash 0.3-3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms