aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-29 01:01:27 -0500
committerJesse Luehrs <doy@tozt.net>2013-03-29 01:01:27 -0500
commit4cd87702004fca9e05e7c5bb899f366caf632842 (patch)
treeed3061a8b6c8e786326214a57501cda2f2f943b4
parent809ac25b4fda72630704158afe9c88ba38cc412f (diff)
downloadrust-term-4cd87702004fca9e05e7c5bb899f366caf632842.tar.gz
rust-term-4cd87702004fca9e05e7c5bb899f366caf632842.zip
this should be a strict prefix
-rw-r--r--src/util.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/util.rs b/src/util.rs
index b69578d..dc1728d 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -99,8 +99,13 @@ impl<T> Trie<T> {
pub fn has_prefix (&self, s: &str) -> bool {
let bytes = str::as_bytes_slice(s);
- let (prefix_length, _) = self.root.find_prefix_trie(bytes);
- prefix_length == vec::len(bytes)
+ let (prefix_length, node) = self.root.find_prefix_trie(bytes);
+ if prefix_length == vec::len(bytes) {
+ vec::any(node.children, |child| { child.is_some() })
+ }
+ else {
+ false
+ }
}
}
@@ -182,9 +187,9 @@ fn test_trie1 () {
check_not_has_prefix(&trie, "bo");
check_not_has_prefix(&trie, "qu");
- check_has_prefix(&trie, "foo");
- check_has_prefix(&trie, "bar");
- check_has_prefix(&trie, "baz");
+ check_not_has_prefix(&trie, "foo");
+ check_not_has_prefix(&trie, "bar");
+ check_not_has_prefix(&trie, "baz");
check_not_has_prefix(&trie, "for");
check_not_has_prefix(&trie, "bao");
check_not_has_prefix(&trie, "quu");