Skip to content

Commit e5023b7

Browse files
committed
Remove hashbrown dependency
Replace the usage of `HashMap` and `HashSet` with `BTreeMap` and `BTreeSet` and remove the `hashbrown` dependency This is an API breaking change because the `KeyMap` type is public.
1 parent a07a17a commit e5023b7

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2018"
1313
[features]
1414
default = ["std"]
1515
std = ["bitcoin/std", "bitcoin/secp-recovery"]
16-
no-std = ["hashbrown", "bitcoin/no-std"]
16+
no-std = ["bitcoin/no-std"]
1717
compiler = []
1818
trace = []
1919

@@ -23,7 +23,6 @@ base64 = ["bitcoin/base64"]
2323

2424
[dependencies]
2525
bitcoin = { version = "0.30.0", default-features = false }
26-
hashbrown = { version = "0.11", optional = true }
2726
internals = { package = "bitcoin-private", version = "0.1.0", default_features = false }
2827

2928
# Do NOT use this as a feature! Use the `serde` feature instead.

src/descriptor/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub use self::key::{
5757
/// [`Descriptor::parse_descriptor`], since the descriptor will always only contain
5858
/// public keys. This map allows looking up the corresponding secret key given a
5959
/// public key from the descriptor.
60-
pub type KeyMap = HashMap<DescriptorPublicKey, DescriptorSecretKey>;
60+
pub type KeyMap = BTreeMap<DescriptorPublicKey, DescriptorSecretKey>;
6161

6262
/// Script descriptor
6363
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -656,7 +656,7 @@ impl Descriptor<DescriptorPublicKey> {
656656
Ok(public_key)
657657
}
658658

659-
let mut keymap_pk = KeyMapWrapper(HashMap::new(), secp);
659+
let mut keymap_pk = KeyMapWrapper(BTreeMap::new(), secp);
660660

661661
struct KeyMapWrapper<'a, C: secp256k1::Signing>(KeyMap, &'a secp256k1::Secp256k1<C>);
662662

@@ -1501,7 +1501,7 @@ mod tests {
15011501
witness: Witness::default(),
15021502
};
15031503
let satisfier = {
1504-
let mut satisfier = HashMap::with_capacity(2);
1504+
let mut satisfier = BTreeMap::new();
15051505

15061506
satisfier.insert(
15071507
a,

src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ pub use bitcoin;
100100
#[macro_use]
101101
extern crate alloc;
102102

103-
#[cfg(not(feature = "std"))]
104-
extern crate hashbrown;
105-
106103
#[cfg(any(feature = "std", test))]
107104
extern crate core;
108105

@@ -961,9 +958,6 @@ mod prelude {
961958
vec::Vec,
962959
};
963960

964-
#[cfg(all(not(feature = "std"), not(test)))]
965-
pub use hashbrown::{HashMap, HashSet};
966-
967961
#[cfg(all(not(feature = "std"), not(test)))]
968962
pub use self::mutex::Mutex;
969963
}

src/miniscript/analyzable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
213213
// to have an iterator
214214
let all_pkhs_len = self.iter_pk().count();
215215

216-
let unique_pkhs_len = self.iter_pk().collect::<HashSet<_>>().len();
216+
let unique_pkhs_len = self.iter_pk().collect::<BTreeSet<_>>().len();
217217

218218
unique_pkhs_len != all_pkhs_len
219219
}

src/policy/concrete.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
327327
let mut prob = 0.;
328328
let semantic_policy = self.lift()?;
329329
let concrete_keys = self.keys();
330-
let key_prob_map: HashMap<_, _> = self
330+
let key_prob_map: BTreeMap<_, _> = self
331331
.to_tapleaf_prob_vec(1.0)
332332
.into_iter()
333333
.filter(|(_, ref pol)| matches!(*pol, Concrete::Key(..)))
@@ -563,7 +563,7 @@ impl<Pk: MiniscriptKey> PolicyArc<Pk> {
563563
// owing to the current [policy element enumeration algorithm][`Policy::enumerate_pol`],
564564
// two passes of the algorithm might result in same sub-policy showing up. Currently, we
565565
// merge the nodes by adding up the corresponding probabilities for the same policy.
566-
let mut pol_prob_map = HashMap::<Arc<Self>, OrdF64>::new();
566+
let mut pol_prob_map = BTreeMap::<Arc<Self>, OrdF64>::new();
567567

568568
let arc_self = Arc::new(self);
569569
tapleaf_prob_vec.insert((Reverse(OrdF64(prob)), Arc::clone(&arc_self)));
@@ -791,7 +791,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
791791
pub fn check_duplicate_keys(&self) -> Result<(), PolicyError> {
792792
let pks = self.keys();
793793
let pks_len = pks.len();
794-
let unique_pks_len = pks.into_iter().collect::<HashSet<_>>().len();
794+
let unique_pks_len = pks.into_iter().collect::<BTreeSet<_>>().len();
795795

796796
if pks_len > unique_pks_len {
797797
Err(PolicyError::DuplicatePubKeys)

0 commit comments

Comments
 (0)