Add traversal history for index search

This commit is contained in:
femsci 2023-02-06 10:02:13 +01:00
parent 179b220c2e
commit 5e8a2d6c25
Signed by: femsci
GPG key ID: 08F7911F0E650C67

View file

@ -508,11 +508,11 @@ impl LocalRecord {
impl Store for LocalStore {
fn get_creds(&self, specifier: &String, key: &String) -> Option<StoreRecord> {
match self.btree_find_key(&key) {
Some(x) => {
(Some(x), _) => {
println!("Found: {}", x);
todo!()
}
None => return None,
(None, _) => return None,
}
}
@ -620,7 +620,7 @@ impl LocalStore {
node
}
fn btree_find_key(&self, key: &String) -> Option<u64> {
fn btree_find_key(&self, key: &String) -> (Option<u64>, Vec<u64>) {
let mut file: BufReader<File> =
BufReader::new(File::open(&self.path).expect("Cannot open file"));
@ -630,6 +630,8 @@ impl LocalStore {
hasher.finish()
};
let mut traversal_history = Vec::new();
let pos = file.seek(SeekFrom::Start(0x90)).unwrap();
let mut block = self
.enc_ctx
@ -637,6 +639,7 @@ impl LocalStore {
.unwrap();
loop {
traversal_history.push(block.stream_position().unwrap());
let node = self.read_node(&mut block);
if node.node_type == IndexNodeType::Invalid {
@ -649,10 +652,10 @@ impl LocalStore {
if node.node_type == IndexNodeType::Leaf {
for child in node.children() {
if child.key == hash {
return Some(child.pointer);
return (Some(child.pointer), traversal_history);
}
}
return None;
return (None, traversal_history);
}
for child in node.children {