refactor path fn to be cleaner and more readable (#1195)
This commit is contained in:
@@ -838,14 +838,11 @@ pub fn is_left_sibling(pos: u64) -> bool {
|
||||
/// The size (and therefore the set of peaks) of the MMR
|
||||
/// is defined by last_pos.
|
||||
pub fn path(pos: u64, last_pos: u64) -> Vec<u64> {
|
||||
let mut path = vec![pos];
|
||||
let mut path = vec![];
|
||||
let mut current = pos;
|
||||
while current + 1 <= last_pos {
|
||||
while current <= last_pos {
|
||||
path.push(current);
|
||||
let (parent, _) = family(current);
|
||||
if parent > last_pos {
|
||||
break;
|
||||
}
|
||||
path.push(parent);
|
||||
current = parent;
|
||||
}
|
||||
path
|
||||
|
||||
+13
-5
@@ -93,18 +93,18 @@ where
|
||||
|
||||
fn rewind(
|
||||
&mut self,
|
||||
position: u64,
|
||||
rewind_add_pos: &Bitmap,
|
||||
rewind_rm_pos: &Bitmap,
|
||||
_position: u64,
|
||||
_rewind_add_pos: &Bitmap,
|
||||
_rewind_rm_pos: &Bitmap,
|
||||
) -> Result<(), String> {
|
||||
panic!("not yet implemented for vec backend...");
|
||||
panic!("not implemented for vec backend...");
|
||||
}
|
||||
|
||||
fn get_data_file_path(&self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn snapshot(&self, header: &BlockHeader) -> Result<(), String> {
|
||||
fn snapshot(&self, _header: &BlockHeader) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -208,6 +208,14 @@ fn various_families() {
|
||||
assert_eq!(pmmr::family(1_000), (1_001, 997));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_paths() {
|
||||
assert_eq!(pmmr::path(1, 1), [1]);
|
||||
assert_eq!(pmmr::path(1, 3), [1, 3]);
|
||||
assert_eq!(pmmr::path(2, 3), [2, 3]);
|
||||
assert_eq!(pmmr::path(4, 16), [4, 6, 7, 15]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_left_sibling() {
|
||||
assert_eq!(pmmr::is_left_sibling(1), true);
|
||||
|
||||
Reference in New Issue
Block a user