### Build and Query PtrHash Index Source: https://github.com/ragnargrootkoerkamp/ptrhash/blob/master/readme.md Demonstrates how to create a PtrHash index from a large set of keys and then query for the minimal index of a specific key. It also shows how to get a non-minimal index and iterate over all indices. ```rust use ptr_hash::{PtrHash, PtrHashParams}; // Generate some random keys. let n = 1_000_000_000; let keys = ptr_hash::util::generate_keys(n); // Build the datastructure. let mphf = ::new(&keys, PtrHashParams::default()); // Get the minimal index of a key. let key = 0; let idx = mphf.index(&key); assert!(idx < n); // Get the non-minimal index of a key. Slightly faster, but can be >=n. let _idx = mphf.index_no_remap(&key); // An iterator over the indices of the keys. // 32: number of iterations ahead to prefetch. // true: remap to a minimal key in [0, n). let indices = mphf.index_stream::<32, true, _>(&keys); assert_eq!(indices.sum::(), (n * (n - 1)) / 2); // Test that all items map to different indices let mut taken = vec![false; n]; for key in keys { let idx = mphf.index(&key); assert!(!taken[idx]); taken[idx] = true; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.