Skip to content

Commit 60e6f24

Browse files
authored
use btreemap instead of hashmap for deterministic iteration order. (#2023)
1 parent 75752a4 commit 60e6f24

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Cairo-VM Changelog
22

33
#### Upcoming Changes
4+
* Refactor: Replaced HashMap with BTreeMap to guarantee deterministic ordering of the data [#2023] (https://github.com/lambdaclass/cairo-vm/pull/2023)
5+
46
* fix: Updated the logic for collecting builtin segment data for prover input info, removing dependency on the existence of stop pointers. [#2022](https://github.com/lambdaclass/cairo-vm/pull/2022)
57

68
* fix: Keep None values in memory segments for the prover input info [#2021](https://github.com/lambdaclass/cairo-vm/pull/2021)

Diff for: vm/src/vm/runners/cairo_runner.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
math_utils::safe_div_usize,
55
stdlib::{
66
any::Any,
7-
collections::{HashMap, HashSet},
7+
collections::{BTreeMap, HashMap, HashSet},
88
ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign},
99
prelude::*,
1010
},
@@ -1516,7 +1516,7 @@ impl CairoRunner {
15161516
})
15171517
.collect();
15181518

1519-
let builtins_segments: HashMap<usize, BuiltinName> = self
1519+
let builtins_segments: BTreeMap<usize, BuiltinName> = self
15201520
.vm
15211521
.builtin_runners
15221522
.iter()
@@ -1554,9 +1554,9 @@ pub struct ProverInputInfo {
15541554
/// A vector of segments, where each segment is a vector of maybe relocatable values or holes (`None`).
15551555
pub relocatable_memory: Vec<Vec<Option<MaybeRelocatable>>>,
15561556
/// A map from segment index to a vector of offsets within the segment, representing the public memory addresses.
1557-
pub public_memory_offsets: HashMap<usize, Vec<usize>>,
1557+
pub public_memory_offsets: BTreeMap<usize, Vec<usize>>,
15581558
/// A map from the builtin segment index into its name.
1559-
pub builtins_segments: HashMap<usize, BuiltinName>,
1559+
pub builtins_segments: BTreeMap<usize, BuiltinName>,
15601560
}
15611561

15621562
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -5603,7 +5603,7 @@ mod tests {
56035603
assert!(prover_info.public_memory_offsets.is_empty());
56045604
assert_eq!(
56055605
prover_info.builtins_segments,
5606-
HashMap::from([(2, BuiltinName::ecdsa)])
5606+
BTreeMap::from([(2, BuiltinName::ecdsa)])
56075607
);
56085608
}
56095609

0 commit comments

Comments
 (0)