Skip to content

Commit 465c48a

Browse files
committed
[WIP] [NOT-WORKING] Add basic cache
1 parent 6d3d229 commit 465c48a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Diff for: storage-proofs/src/zigzag_graph.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::marker::PhantomData;
2+
use std::collections::HashMap;
3+
use std::sync::RwLock;
24

35
use crate::crypto::feistel::{self, FeistelPrecomputed};
46
use crate::drgraph::{BucketGraph, Graph};
@@ -18,6 +20,7 @@ where
1820
base_graph: G,
1921
pub reversed: bool,
2022
feistel_precomputed: FeistelPrecomputed,
23+
parents_cache: RwLock<HashMap<usize, Vec<usize>>>,
2124
_h: PhantomData<H>,
2225
}
2326

@@ -50,6 +53,7 @@ where
5053
expansion_degree,
5154
reversed: false,
5255
feistel_precomputed: feistel::precompute((expansion_degree * nodes) as u32),
56+
parents_cache: RwLock::new(HashMap::new()),
5357
_h: PhantomData,
5458
}
5559
}
@@ -83,6 +87,7 @@ pub trait ZigZag: ::std::fmt::Debug + Clone + PartialEq + Eq {
8387
fn reversed(&self) -> bool;
8488
fn expanded_parents(&self, node: usize) -> Vec<usize>;
8589
fn real_index(&self, i: usize) -> usize;
90+
fn parents_cache(&self) -> RwLock<HashMap<usize, Vec<usize>>>;
8691
fn new_zigzag(
8792
nodes: usize,
8893
base_degree: usize,
@@ -205,6 +210,7 @@ where
205210
expansion_degree: self.expansion_degree,
206211
reversed: !self.reversed,
207212
feistel_precomputed: feistel::precompute((self.expansion_degree * self.size()) as u32),
213+
parents_cache: RwLock::new(HashMap::new()),
208214
_h: PhantomData,
209215
}
210216
}
@@ -223,7 +229,13 @@ where
223229

224230
#[inline]
225231
fn expanded_parents(&self, node: usize) -> Vec<usize> {
226-
(0..self.expansion_degree)
232+
233+
// let parents_cache = self.parents_cache().read().unwrap();
234+
// if (*parents_cache).contains_key(&node) {
235+
// return (*parents_cache)[&node].clone();
236+
// }
237+
238+
let parents: Vec<usize> = (0..self.expansion_degree)
227239
.filter_map(|i| {
228240
let other = self.correspondent(node, i);
229241
if self.reversed {
@@ -238,7 +250,12 @@ where
238250
None
239251
}
240252
})
241-
.collect()
253+
.collect();
254+
255+
// let mut parents_cache = self.parents_cache().write().unwrap();
256+
// (*parents_cache).insert(node, parents.clone());
257+
258+
parents
242259
}
243260

244261
#[inline]
@@ -249,6 +266,10 @@ where
249266
i
250267
}
251268
}
269+
270+
fn parents_cache(&self) -> RwLock<HashMap<usize, Vec<usize>>> {
271+
self.parents_cache
272+
}
252273
}
253274

254275
#[cfg(test)]

0 commit comments

Comments
 (0)