Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn bloomfilter() {
- let mut bloom_filter = BloomFilter::<&str, 1024>::new(5);
- //they really are that terrible
- let test_sentence = "AJR are a god awful fucking band";
- for word in test_sentence.split_whitespace() {
- bloom_filter.insert(&word);
- }
- for word in test_sentence.split_whitespace() {
- assert!(bloom_filter.must_contain(&word));
- }
- let mut more_hashes = BloomFilter::<&str, 1024>::new(50);
- let mut less_hashes = BloomFilter::<&str, 1024>::new(5);
- let test_sentence = "I'm listening to \"Terminal Z\" by Skee Mask and it's
- honestly stunning. It's a very futuristic spacey sounding atmospheric ambient,
- with lush synths and detuned wacky sounding effects. Touching music truly is
- one of the most precious things in life.";
- for word in test_sentence.split_whitespace() {
- more_hashes.insert(&word);
- less_hashes.insert(&word);
- }
- let mut false_positives = (0, 0);
- for _ in 0..10000 {
- let word = &rand_string()[..];
- if less_hashes.must_contain(&word) {
- false_positives.0 = false_positives.0 + 1
- }
- if more_hashes.must_contain(&word) {
- false_positives.1 = false_positives.1 + 1
- }
- }
- println!("5 hash bloom filter false positives: {}", false_positives.0);
- println!("50 hash false positives: {}", false_positives.1);
- assert!(false_positives.0 >= false_positives.1);
- }
Add Comment
Please, Sign In to add comment