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
use idx_binary::IdxBinary;
use versatile_data::IdxSized;
use crate::collection::CollectionRow;
pub struct RelationIndexes{
key_names:IdxBinary
,key:IdxSized<u32>
,parent:IdxSized<CollectionRow>
,child:IdxSized<CollectionRow>
}
impl RelationIndexes{
pub fn new(
key_names:IdxBinary
,key:IdxSized<u32>
,parent:IdxSized<CollectionRow>
,child:IdxSized<CollectionRow>
)->RelationIndexes{
RelationIndexes{
key_names
,key
,parent
,child
}
}
pub fn insert(&mut self,relation_key:&str,parent:CollectionRow,child:CollectionRow){
if let Some(key_id)=self.key_names.entry(relation_key.as_bytes()){
self.key.insert(key_id);
self.parent.insert(parent);
self.child.insert(child);
}
}
pub fn childs(&self,key:&str,parent:&CollectionRow)->Vec<CollectionRow>{
let mut ret:Vec<CollectionRow>=Vec::new();
if let Some(key)=self.key_names.row(key.as_bytes()){
let c=self.parent.select_by_value(parent);
for i in c{
if let (
Some(key_row)
,Some(child)
)=(
self.key.value(i)
,self.child.value(i)
){
if key_row==key{
ret.push(child);
}
}
}
}
ret
}
}