Lines Matching full: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()]); in find_with() localVariable
59 if nhash.eq(hash) && is_prefix(haystack, needle) { in find_with()
65 hash.roll(&nhash, haystack[0], haystack[needle.len()]); in find_with()
76 /// a pre-computed needle hash.
85 let mut hash = in rfind_with() localVariable
86 Hash::from_bytes_rev(&haystack[haystack.len() - needle.len()..]); in rfind_with()
88 if nhash.eq(hash) && is_suffix(haystack, needle) { in rfind_with()
94 hash.roll( in rfind_with()
103 /// A hash derived from a needle.
106 /// The actual hash.
107 hash: Hash, field
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 }; in forward()
123 nh.hash.add(needle[0]); in forward()
125 nh.hash.add(b); in forward()
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 }; in reverse()
138 nh.hash.add(needle[needle.len() - 1]); in reverse()
140 nh.hash.add(b); in reverse()
147 fn eq(&self, hash: Hash) -> bool { in eq()
148 self.hash == hash in eq()
152 /// A Rabin-Karp hash. This might represent the hash of a needle, or the hash
155 pub(crate) struct Hash(u32); struct
157 impl Hash { impl
158 /// Create a new hash that represents the empty string.
159 pub(crate) fn new() -> Hash { in new()
160 Hash(0) in new()
163 /// Create a new hash from the bytes given for use in forward searches.
164 pub(crate) fn from_bytes_fwd(bytes: &[u8]) -> Hash { in from_bytes_fwd() argument
165 let mut hash = Hash::new(); in from_bytes_fwd() localVariable
167 hash.add(b); in from_bytes_fwd()
169 hash in from_bytes_fwd()
172 /// Create a new hash from the bytes given for use in reverse searches.
173 fn from_bytes_rev(bytes: &[u8]) -> Hash { in from_bytes_rev() argument
174 let mut hash = Hash::new(); in from_bytes_rev() localVariable
176 hash.add(b); in from_bytes_rev()
178 hash in from_bytes_rev()
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.