Skip to content

Commit

Permalink
Use BTreeSet/BTreeMap instead of HashSet/HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
danielabrozzoni committed Aug 18, 2023
1 parent f3a8566 commit 4400f85
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl Plan {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
/// Signatures which a key can produce
///
/// Defaults to `ecdsa=true` and `taproot=TaprootCanSign::default()`
Expand All @@ -480,7 +480,7 @@ impl Default for CanSign {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
/// Signatures which a taproot key can produce
///
/// Defaults to `key_spend=true`, `script_spend=Any` and `sighash_default=true`
Expand Down Expand Up @@ -512,7 +512,7 @@ impl Default for TaprootCanSign {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
/// Which taproot leaves the key can sign for
pub enum TaprootAvailableLeaves {
/// Cannot sign for any leaf
Expand Down Expand Up @@ -546,15 +546,15 @@ pub struct Assets {
/// derived with either `derivation_path` or a derivation path that extends `derivation_path`
/// by exactly one child number. For example, if the derivation path `m/0/1` is provided, the
/// user can sign with either `m/0/1` or `m/0/1/*`.
pub keys: HashSet<(bip32::KeySource, CanSign)>,
pub keys: BTreeSet<(bip32::KeySource, CanSign)>,
/// Set of available sha256 preimages
pub sha256_preimages: HashSet<sha256::Hash>,
pub sha256_preimages: BTreeSet<sha256::Hash>,
/// Set of available hash256 preimages
pub hash256_preimages: HashSet<hash256::Hash>,
pub hash256_preimages: BTreeSet<hash256::Hash>,
/// Set of available ripemd160 preimages
pub ripemd160_preimages: HashSet<ripemd160::Hash>,
pub ripemd160_preimages: BTreeSet<ripemd160::Hash>,
/// Set of available hash160 preimages
pub hash160_preimages: HashSet<hash160::Hash>,
pub hash160_preimages: BTreeSet<hash160::Hash>,
/// Maximum absolute timelock allowed
pub absolute_timelock: Option<LockTime>,
/// Maximum relative timelock allowed
Expand Down Expand Up @@ -679,7 +679,7 @@ impl AssetProvider<DefiniteDescriptorKey> for Assets {

impl FromIterator<DescriptorPublicKey> for Assets {
fn from_iter<I: IntoIterator<Item = DescriptorPublicKey>>(iter: I) -> Self {
let mut keys = HashSet::new();
let mut keys = BTreeSet::new();
for pk in iter {
for deriv_path in pk.full_derivation_paths() {
keys.insert(((pk.master_fingerprint(), deriv_path), CanSign::default()));
Expand All @@ -699,8 +699,8 @@ pub trait IntoAssets {
}

impl IntoAssets for KeyMap {
fn into_assets(mut self) -> Assets {
Assets::from_iter(self.drain().map(|(k, _)| k))
fn into_assets(self) -> Assets {
Assets::from_iter(self.into_iter().map(|(k, _)| k))
}
}

Expand Down

0 comments on commit 4400f85

Please sign in to comment.