3 ms·
"Static Search Structure" seems relevant [1]: A static search structure is an Abstract Data Type with certain fundamental operations, e.g., initialize, insert,
by ripe 4y ago
"Static Search Structure" seems relevant [1]:
A static search structure is an Abstract Data Type with certain fundamental operations, e.g., initialize, insert, and retrieve. Conceptually, all insertions occur before any retrievals. It is a useful data structure for representing static search sets. Static search sets occur frequently in software system applications. Typical static search sets include compiler reserved words, assembler instruction opcodes, and built-in shell interpreter commands. Search set members, called keywords, are inserted into the structure only once, usually during program initialization, and are not generally modified at run-time.
Numerous static search structure implementations exist, e.g., arrays, linked lists, binary search trees, digital search tries, and hash tables. Different approaches offer trade-offs between space utilization and search time efficiency. For example, an n element sorted array is space efficient, though the average-case time complexity for retrieval operations using binary search is proportional to log n. Conversely, hash table implementations often locate a table entry in constant time, but typically impose additional memory overhead and exhibit poor worst case performance.
Minimal perfect hash functions provide an optimal solution for a particular class of static search sets. A minimal perfect hash function is defined by two properties:
* It allows keyword recognition in a static search set using at most one probe into the hash table. This represents the “perfect” property.
* The actual memory allocated to store the keywords is precisely large enough for the keyword set, and no larger. This is the “minimal” property.
For most applications it is far easier to generate perfect hash functions than minimal perfect hash functions. Moreover, non-minimal perfect hash functions frequently execute faster than minimal ones in practice. This phenomena occurs since searching a sparse keyword table increases the probability of locating a “null” entry, thereby reducing string comparisons.
User @rwmj earlier posted a link to GNU gperf. That's an implementation.
gperf's default behavior generates near-minimal perfect hash functions for keyword sets. However, gperf provides many options that permit user control over the degree of minimality and perfection.
[1] https://www.gnu.org/software/gperf/manual/gperf.html https://www.gnu.org/software/gperf/manual/gperf.html
- DenisM 4y agoVery well written, thank you. Long enough to cover the subject, short enough to retain interest. If you have more of these on various subjects I would pay to read them. Perhaps make a book “Byte-size introductions to various CS topics” or some such.
- ripe 4y agoThank you for the kind words! That was extracted from the link I provided, with minor rewording. Since the pandemic, I have been writing short articles aimed at lay people (not readers like you on HN), called Robots In Plain English. Link in my profile. A different thing from what you were asking, but might be interesting to you.