equal
deleted
inserted
replaced
206 } else { |
206 } else { |
207 self.buf.len() * 2 |
207 self.buf.len() * 2 |
208 } |
208 } |
209 } |
209 } |
210 |
210 |
|
211 pub fn is_empty(&self) -> bool { |
|
212 self.len() == 0 |
|
213 } |
|
214 |
211 pub fn is_prefix_of(&self, node: &Node) -> bool { |
215 pub fn is_prefix_of(&self, node: &Node) -> bool { |
212 if self.is_odd { |
216 if self.is_odd { |
213 let buf = self.buf; |
217 let buf = self.buf; |
214 let last_pos = buf.len() - 1; |
218 let last_pos = buf.len() - 1; |
215 node.data.starts_with(buf.split_at(last_pos).0) |
219 node.data.starts_with(buf.split_at(last_pos).0) |
240 let until = if self.is_odd { |
244 let until = if self.is_odd { |
241 buf.len() - 1 |
245 buf.len() - 1 |
242 } else { |
246 } else { |
243 buf.len() |
247 buf.len() |
244 }; |
248 }; |
245 for i in 0..until { |
249 for (i, item) in buf.iter().enumerate().take(until) { |
246 if buf[i] != node.data[i] { |
250 if *item != node.data[i] { |
247 if buf[i] & 0xf0 == node.data[i] & 0xf0 { |
251 return if *item & 0xf0 == node.data[i] & 0xf0 { |
248 return Some(2 * i + 1); |
252 Some(2 * i + 1) |
249 } else { |
253 } else { |
250 return Some(2 * i); |
254 Some(2 * i) |
251 } |
255 }; |
252 } |
256 } |
253 } |
257 } |
254 if self.is_odd && buf[until] & 0xf0 != node.data[until] & 0xf0 { |
258 if self.is_odd && buf[until] & 0xf0 != node.data[until] & 0xf0 { |
255 Some(until * 2) |
259 Some(until * 2) |
256 } else { |
260 } else { |