Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
optimize account hash merkle tree index from vec to 2-element array
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Oct 24, 2023
1 parent 6470544 commit 73910a7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions accounts-db/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ const _: () = assert!(

#[derive(Default, Debug, PartialEq, Eq)]
pub struct CumulativeOffset {
pub index: Vec<usize>,
/// Since the source data in at most 2D, two indexes are enough.
pub index: [usize; 2],
pub start_offset: usize,
}

Expand Down Expand Up @@ -416,7 +417,7 @@ impl CumulativeOffsets {
.filter_map(|(i, len)| {
if len > 0 {
let result = CumulativeOffset {
index: vec![i],
index: [i, i],
start_offset: total_count,
};
total_count += len;
Expand Down Expand Up @@ -1373,7 +1374,7 @@ mod tests {
cumulative_offsets = Vec::with_capacity(raw.len() * v_outer.len());
}
cumulative_offsets.push(CumulativeOffset {
index: vec![i, j],
index: [i, j],
start_offset: total_count,
});
total_count += len;
Expand Down Expand Up @@ -2126,7 +2127,7 @@ mod tests {
fn test_accountsdb_cumulative_find() {
let input = CumulativeOffsets {
cumulative_offsets: vec![CumulativeOffset {
index: vec![0],
index: [0; 2],
start_offset: 0,
}],
total_count: 0,
Expand All @@ -2136,11 +2137,11 @@ mod tests {
let input = CumulativeOffsets {
cumulative_offsets: vec![
CumulativeOffset {
index: vec![0],
index: [0; 2],
start_offset: 0,
},
CumulativeOffset {
index: vec![1],
index: [1; 2],
start_offset: 2,
},
],
Expand Down

0 comments on commit 73910a7

Please sign in to comment.