perfect-hash 0.0.2
A minimal D application.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Perfect-hash
Generates perfect hash function for a set of keys.
Can be used to quickly determine if a key belongs in a set.
Examples
Either supply a list of strings:
import std.random;
import perfecthash.generator;
auto keys = ["asdf", "fdsa", "car", "garage", "elephant", "kangeroo"];
auto rnd = Random(9123);
auto ph = createPerfectHashFunction(keys, rnd);
foreach(idx, key; keys)
assert(ph(key) == idx);
Or a list of KeyValue where you yourself determine to which value each string gets hashed too. Usefull if a set of strings consists of subsets, and you quickly want to determine which subset it belongs to.
Here is a set of strings which contain either animals '0' or things '1'
import std.random;
import perfecthash.generator;
enum Class {
Animal = 0,
Thing = 1
}
auto keys = [KeyValue("gorilla",Class.Animal), KeyValue("car",Class.Thing), KeyValue("house",Class.Thing), KeyValue("kangeroo",Class.Animal), KeyValue("elephant",Class.Animal), KeyValue("door",Class.Thing)];
auto rnd = Random(9812);
auto ph = createPerfectHashFunction(keys, rnd);
assert(ph("car") == Class.Thing);
assert(ph("elephant") == Class.Animal);
To quickly determine whether a string belongs in a set:
import std.random;
import perfecthash.generator;
auto keys = ["asdf", "fdsa", "car", "garage", "elephant", "kangeroo"];
auto rnd = Random(9123);
auto ph = createPerfectHashFunction(keys, rnd);
assert(keys[ph("garage")] == "garage");
assert(keys[ph("notfound")] != "notfound");
- Registered by Koppe
- 0.0.2 released 4 years ago
- skoppe/perfect-hash
- proprietary
- Copyright © 2020, Sebastiaan Koppe
- Authors:
- Dependencies:
- none
- Versions:
-
1.0.2 2020-Jul-30 1.0.1 2020-Jul-30 1.0.0 2020-Jul-29 0.7.0 2020-Jan-20 0.6.0 2020-Jan-20 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
36 downloads total
-
- Score:
- 0.8
- Short URL:
- perfect-hash.dub.pm