1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::vvc::Vvc;
use std::collections::BTreeMap;
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Btmvc { pub attr: BTreeMap<usize, Vec<char>>}
impl Btmvc {
pub fn new<'a>(attr: &'a str, sep: char) -> Self {
let vvchar = Vvc::new(attr, sep);
let mut btm = BTreeMap::new();
for (k, v) in vvchar.attr.iter().enumerate() {
btm.insert(k, v.to_vec());
}
Btmvc { attr: btm }
}
pub fn search_all<'a>(self, word: &'a str) -> Option<Vec<usize>> {
let word_vc: Vec<char> = word.chars().collect();
let mut stack: Vec<usize> = vec![];
for k in self.attr.keys() {
if self.attr.get(&k).unwrap() == &word_vc {
stack.push(*k);
} else {
continue;
}
}
match stack.len() {
0 => None,
_ => Some(stack),
}
}
}