Skip to content

Commit

Permalink
chore: Use HashMap instead of BTreeMap for storing fields by id in St…
Browse files Browse the repository at this point in the history
…uctType (#14)
  • Loading branch information
amogh-jahagirdar authored Jul 30, 2023
1 parent 3604a8f commit 831e93c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/spec/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/*!
* Data Types
*/
use std::{collections::BTreeMap, fmt, ops::Index};
use std::{collections::HashMap, fmt, ops::Index};

use serde::{
de::{self, Error, IntoDeserializer, MapAccess, Visitor},
Expand Down Expand Up @@ -197,7 +197,7 @@ pub struct StructType {
fields: Vec<StructField>,
/// Lookup for index by field id
#[serde(skip_serializing)]
id_lookup: BTreeMap<i32, usize>,
id_lookup: HashMap<i32, usize>,
}

impl<'de> Deserialize<'de> for StructType {
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<'de> Deserialize<'de> for StructType {
impl StructType {
/// Creates a struct type with the given fields.
pub fn new(fields: Vec<StructField>) -> Self {
let id_lookup = BTreeMap::from_iter(fields.iter().enumerate().map(|(i, x)| (x.id, i)));
let id_lookup = HashMap::from_iter(fields.iter().enumerate().map(|(i, x)| (x.id, i)));
Self { fields, id_lookup }
}
/// Get structfield with certain id
Expand Down Expand Up @@ -402,7 +402,7 @@ mod tests {
initial_default: None,
write_default: None,
}],
id_lookup: BTreeMap::from([(1, 0)]),
id_lookup: HashMap::from([(1, 0)]),
}),
)
}
Expand Down Expand Up @@ -435,7 +435,7 @@ mod tests {
initial_default: None,
write_default: None,
}],
id_lookup: BTreeMap::from([(1, 0)]),
id_lookup: HashMap::from([(1, 0)]),
}),
)
}
Expand Down Expand Up @@ -486,7 +486,7 @@ mod tests {
write_default: None,
},
],
id_lookup: BTreeMap::from([(1, 0), (2, 1)]),
id_lookup: HashMap::from([(1, 0), (2, 1)]),
}),
)
}
Expand Down

0 comments on commit 831e93c

Please sign in to comment.