diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-29 01:01:27 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-29 01:01:27 -0500 |
commit | 4cd87702004fca9e05e7c5bb899f366caf632842 (patch) | |
tree | ed3061a8b6c8e786326214a57501cda2f2f943b4 | |
parent | 809ac25b4fda72630704158afe9c88ba38cc412f (diff) | |
download | rust-term-4cd87702004fca9e05e7c5bb899f366caf632842.tar.gz rust-term-4cd87702004fca9e05e7c5bb899f366caf632842.zip |
this should be a strict prefix
-rw-r--r-- | src/util.rs | 15 |
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"); |