TRIEHASH(1)

πŸ“¦
version 0.3 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu questing

πŸ’– 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 is 320, meaning that 8, 4, and single byte reads are enabled. specify 0 to disable multi-byte completely, or add 2 if 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_ARCH is defined and __ARM_FEATURE_UNALIGNED is 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