Skip to content

Commit a9c2307

Browse files
committed
replace all uses of HashMap and HashSet with BTreeMap and BTreeSet to avoid wasm32-wasip1 binaries depending on random_get import
1 parent 26fee08 commit a9c2307

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

core/src/name_registry.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
cmp::Ordering,
3-
collections::{BTreeMap, HashMap, HashSet},
3+
collections::{BTreeMap, BTreeSet},
44
fmt::Debug,
55
};
66

@@ -25,7 +25,7 @@ impl<FA, FO> NamePreference<FA, FO> {
2525

2626
#[derive(Debug)]
2727
pub struct NameRegistry<'type_graph> {
28-
assigned_names: HashMap<TypeId, &'type_graph str>,
28+
assigned_names: BTreeMap<TypeId, &'type_graph str>,
2929
}
3030

3131
impl<'type_graph> NameRegistry<'type_graph> {
@@ -50,12 +50,12 @@ impl<'type_graph> NameRegistry<'type_graph> {
5050
/// Maximum Bipartite Matching.
5151
struct BipartiteMatcher<'type_graph> {
5252
graph: BTreeMap<TypeId, Vec<&'type_graph str>>,
53-
matched: HashMap<&'type_graph str, TypeId>,
54-
visited: HashSet<TypeId>,
53+
matched: BTreeMap<&'type_graph str, TypeId>,
54+
visited: BTreeSet<TypeId>,
5555
}
5656

5757
impl<'a> BipartiteMatcher<'a> {
58-
fn solve(graph: BTreeMap<TypeId, Vec<&'a str>>) -> HashMap<TypeId, &'a str> {
58+
fn solve(graph: BTreeMap<TypeId, Vec<&'a str>>) -> BTreeMap<TypeId, &'a str> {
5959
let mut matcher = Self {
6060
graph,
6161
matched: Default::default(),
@@ -71,7 +71,7 @@ impl<'a> BipartiteMatcher<'a> {
7171
matcher.try_match(type_id);
7272
}
7373

74-
let mut result = HashMap::new();
74+
let mut result = BTreeMap::new();
7575
for (name, type_id) in &matcher.matched {
7676
result.insert(*type_id, *name);
7777
}
@@ -115,7 +115,7 @@ impl<'a> BipartiteMatcher<'a> {
115115
struct NameCollector<'type_graph> {
116116
type_graph: &'type_graph TypeGraph,
117117
names: BTreeMap<TypeId, Vec<&'type_graph str>>,
118-
visited: HashSet<TypeId>,
118+
visited: BTreeSet<TypeId>,
119119
}
120120

121121
impl<'type_graph> NameCollector<'type_graph> {

core/src/type_graph.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
//! - Compact representation of potentially infinite linked list structure
159159
//! ```
160160
use std::{
161-
collections::{BTreeMap, HashMap, HashSet},
161+
collections::{BTreeMap, BTreeSet},
162162
fmt::Display,
163163
};
164164

@@ -185,7 +185,7 @@ pub struct TypeGraph {
185185
/// Type definition node. Mirrors FieldType but uses [`TypeId`] references.
186186
///
187187
/// Implements Ord for BTreeMap caching (interning).
188-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
188+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
189189
pub enum TypeDef {
190190
Unknown,
191191
Null,
@@ -200,7 +200,7 @@ pub enum TypeDef {
200200
}
201201

202202
/// Named field in object type.
203-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
203+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
204204
pub struct ObjectField {
205205
pub name: String,
206206
pub type_id: TypeId,
@@ -254,7 +254,7 @@ fn canonicalize(type_def: &mut TypeDef, nodes: &BTreeMap<TypeId, TypeDef>) {
254254
#[derive(Default)]
255255
struct GraphBuilder {
256256
nodes: BTreeMap<TypeId, TypeDef>,
257-
cache: HashMap<TypeDef, TypeId>,
257+
cache: BTreeMap<TypeDef, TypeId>,
258258
iota: Iota,
259259
}
260260

@@ -345,7 +345,7 @@ impl GraphBuilder {
345345
#[derive(Default)]
346346
struct TypeReducer {
347347
reduced_nodes: BTreeMap<TypeId, TypeDef>,
348-
cache: HashMap<TypeDef, TypeId>,
348+
cache: BTreeMap<TypeDef, TypeId>,
349349
remaps: Vec<(TypeId, TypeId)>, // original TypeGraph to reduced TypeGraph
350350
iota: Iota,
351351
}
@@ -576,7 +576,7 @@ impl<'type_graph> CanonicalView<'type_graph> {
576576
&self,
577577
f: &mut std::fmt::Formatter<'_>,
578578
type_id: TypeId,
579-
visited: &mut HashSet<TypeId>,
579+
visited: &mut BTreeSet<TypeId>,
580580
) -> std::fmt::Result {
581581
if visited.contains(&type_id) {
582582
return match self.name_registry.assigned_name(type_id) {
@@ -642,7 +642,7 @@ impl Display for CanonicalView<'_> {
642642
}?;
643643

644644
// Then print the body of the root type
645-
let mut visited = HashSet::new();
645+
let mut visited = BTreeSet::new();
646646
self.fmt_type(f, self.type_graph.root, &mut visited)
647647
}
648648
}

0 commit comments

Comments
 (0)