Import 'twox-hash' crate

Request Document: go/android-rust-importing-crates
For CL Reviewers: go/android3p#cl-review
For Build Team: go/ab-third-party-imports

Bug: 319233932
Test: n/a
Change-Id: Ib1680ecd9731b50bc0bf05c2fbeac49636c2243d
21 files changed
tree: c3681f7f61501f4634856bbff5ef145b3c5ba522
  1. .github/
  2. src/
  3. .cargo_vcs_info.json
  4. .gitignore
  5. Cargo.toml
  6. Cargo.toml.orig
  7. LICENSE.txt
  8. METADATA
  9. MODULE_LICENSE_MIT
  10. OWNERS
  11. README.md
README.md

TwoX-Hash

A Rust implementation of the XXHash algorithm.

Build Status Current Version

Documentation

Examples

With a fixed seed

use std::hash::BuildHasherDefault;
use std::collections::HashMap;
use twox_hash::XxHash64;

let mut hash: HashMap<_, _, BuildHasherDefault<XxHash64>> = Default::default();
hash.insert(42, "the answer");
assert_eq!(hash.get(&42), Some(&"the answer"));

With a random seed

use std::collections::HashMap;
use twox_hash::RandomXxHashBuilder64;

let mut hash: HashMap<_, _, RandomXxHashBuilder64> = Default::default();
hash.insert(42, "the answer");
assert_eq!(hash.get(&42), Some(&"the answer"));

Benchmarks

64-bit

BytesSipHasher (MB/s)XXHash (MB/s)Ratio
1523873%
421014870%
16615615100%
329141391152%
12813473657271%
25614145019355%
51215466168399%
102415656206397%
104857615927564475%
BytesFnvHasher (MB/s)XXHash (MB/s)Ratio
11000384%
480014819%
1676161581%
327611391183%
1287273657503%
2567595019661%
5127456168828%
10247416206838%
104857674575641015%

32-bit

BytesSipHasher (MB/s)XXHash32 (MB/s)Ratio
15255106%
4210210100%
166151230200%
329141882206%
12813473282244%
25614143459245%
51215463792245%
102415653938252%
104857615924127259%
BytesFnvHasher (MB/s)XXHash32 (MB/s)Ratio
11000556%
480021026%
167611230162%
327611882247%
1287273282451%
2567593459456%
5127453792509%
10247413938531%
10485767454127554%

Contributing

  1. Fork it ( https://github.com/shepmaster/twox-hash/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Add a failing test.
  4. Add code to pass the test.
  5. Commit your changes (git commit -am 'Add some feature')
  6. Ensure tests pass.
  7. Push to the branch (git push origin my-new-feature)
  8. Create a new Pull Request