Lines Matching defs:hash

7 to compute a needle hash and zip through the haystack when compared to
45 /// a pre-computed needle hash.
55 let mut hash = Hash::from_bytes_fwd(&haystack[..needle.len()]);
59 if nhash.eq(hash) && is_prefix(haystack, needle) {
65 hash.roll(&nhash, haystack[0], haystack[needle.len()]);
76 /// a pre-computed needle hash.
85 let mut hash =
88 if nhash.eq(hash) && is_suffix(haystack, needle) {
94 hash.roll(
103 /// A hash derived from a needle.
106 /// The actual hash.
107 hash: Hash,
109 /// the hash. It is defined to be 2^(n-1) (using wrapping exponentiation),
111 /// from the hash once the hash window rolls past it.
116 /// Create a new Rabin-Karp hash for the given needle for use in forward
119 let mut nh = NeedleHash { hash: Hash::new(), hash_2pow: 1 };
123 nh.hash.add(needle[0]);
125 nh.hash.add(b);
131 /// Create a new Rabin-Karp hash for the given needle for use in reverse
134 let mut nh = NeedleHash { hash: Hash::new(), hash_2pow: 1 };
138 nh.hash.add(needle[needle.len() - 1]);
140 nh.hash.add(b);
147 fn eq(&self, hash: Hash) -> bool {
148 self.hash == hash
152 /// A Rabin-Karp hash. This might represent the hash of a needle, or the hash
158 /// Create a new hash that represents the empty string.
163 /// Create a new hash from the bytes given for use in forward searches.
165 let mut hash = Hash::new();
167 hash.add(b);
169 hash
172 /// Create a new hash from the bytes given for use in reverse searches.
174 let mut hash = Hash::new();
176 hash.add(b);
178 hash
181 /// Add 'new' and remove 'old' from this hash. The given needle hash should
182 /// correspond to the hash computed for the needle being searched for.
191 /// Add a byte to this hash.
196 /// Remove a byte from this hash. The given needle hash should correspond
197 /// to the hash computed for the needle being searched for.