https://github.com/boxdot/chm-hash-rs
CHM algorithm for generating perfect hash functions
https://github.com/boxdot/chm-hash-rs
Last synced: about 1 year ago
JSON representation
CHM algorithm for generating perfect hash functions
- Host: GitHub
- URL: https://github.com/boxdot/chm-hash-rs
- Owner: boxdot
- License: apache-2.0
- Created: 2019-01-11T18:39:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-11T18:40:22.000Z (over 7 years ago)
- Last Synced: 2025-02-04T15:48:40.862Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# chm-hash
Perfect hash function generator based on the CHM algorithm by Z. J. Czech, G. Havas and B.S. Majewski "_An optimal algorithm for generating minimal perfect hash functions_" in Information Processing Letters, 43(5):257-264, 1992.
## Usage
```rust
let animals = ["Elephant", "Horse", "Camel", "Python", "Dog", "Cat"];
let h = generate_hash(
animals
.iter()
.enumerate()
.map(|(idx, animal)| (animal, idx)), // idx is desired hash value
);
assert!(animals
.iter()
.enumerate()
.all(|(idx, animal)| h.hash(animal) == idx));
```
## WIP
In the above example, you don't want to use the generated version of the hash function dynamically,
but implement it as a static function (cf. [benches/state_lookup.rs](benches/state_lookup.rs)) due
to performance reasons. Just run the benchmarks, you will see why.
* [ ] Provide code generation e.g. by derive macro.
* [ ] Allow to specify seed when generating the hash function, for making tests and benchmarks
deterministic.
## Acknowledgments
Most of the code is ported from http://ilan.schnell-web.net/prog/perfect-hash/.
## License
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT License ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this document by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.