Use regular (ahash) IndexMap for PeerMaps

This commit is contained in:
Joakim Frostegård 2022-08-06 16:50:56 +02:00
parent 5f0971e952
commit c76d7442e2
7 changed files with 16 additions and 8 deletions

1
Cargo.lock generated
View file

@ -68,6 +68,7 @@ dependencies = [
"hashbrown 0.12.3",
"hex",
"hwloc",
"indexmap",
"indexmap-amortized",
"libc",
"log",

View file

@ -24,6 +24,7 @@ duplicate = "0.4"
git-testament = "0.2"
hashbrown = "0.12"
hex = "0.4"
indexmap = "1"
indexmap-amortized = "1"
libc = "0.2"
log = "0.4"

View file

@ -13,6 +13,9 @@ pub mod privileges;
#[cfg(feature = "rustls")]
pub mod rustls_config;
/// IndexMap using AHash hasher
pub type IndexMap<K, V> = indexmap::IndexMap<K, V, RandomState>;
/// Amortized IndexMap using AHash hasher
pub type AmortizedIndexMap<K, V> = indexmap_amortized::IndexMap<K, V, RandomState>;
@ -104,7 +107,7 @@ impl Drop for PanicSentinel {
#[inline]
pub fn extract_response_peers<K, V, R, F>(
rng: &mut impl Rng,
peer_map: &AmortizedIndexMap<K, V>,
peer_map: &IndexMap<K, V>,
max_num_peers_to_take: usize,
sender_peer_map_key: K,
peer_conversion_function: F,

View file

@ -16,7 +16,7 @@ use rand::SeedableRng;
use smartstring::{LazyCompact, SmartString};
use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache};
use aquatic_common::{extract_response_peers, PanicSentinel};
use aquatic_common::{extract_response_peers, IndexMap, PanicSentinel};
use aquatic_common::{AmortizedIndexMap, CanonicalSocketAddr};
use aquatic_common::{SecondsSinceServerStart, ServerStartInstant, ValidUntil};
use aquatic_http_protocol::common::*;
@ -78,7 +78,7 @@ pub struct PeerMapKey<I: Ip> {
pub ip_or_key: Either<I, SmartString<LazyCompact>>,
}
pub type PeerMap<I> = AmortizedIndexMap<PeerMapKey<I>, Peer<I>>;
pub type PeerMap<I> = IndexMap<PeerMapKey<I>, Peer<I>>;
pub struct TorrentData<I: Ip> {
pub peers: PeerMap<I>,

View file

@ -1,6 +1,8 @@
use std::net::{Ipv4Addr, Ipv6Addr};
use aquatic_common::{AmortizedIndexMap, SecondsSinceServerStart, ServerStartInstant, ValidUntil};
use aquatic_common::{
AmortizedIndexMap, IndexMap, SecondsSinceServerStart, ServerStartInstant, ValidUntil,
};
use aquatic_http_protocol::common::{AnnounceEvent, InfoHash, PeerId};
use aquatic_http_protocol::response::ResponsePeer;
@ -55,7 +57,7 @@ pub struct PeerMapKey<I: Ip> {
pub ip_address: I,
}
pub type PeerMap<I> = AmortizedIndexMap<PeerMapKey<I>, Peer<I>>;
pub type PeerMap<I> = IndexMap<PeerMapKey<I>, Peer<I>>;
pub struct TorrentData<I: Ip> {
pub peers: PeerMap<I>,

View file

@ -2,6 +2,7 @@ use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
use std::sync::Arc;
use aquatic_common::IndexMap;
use aquatic_common::SecondsSinceServerStart;
use aquatic_common::ServerStartInstant;
use aquatic_common::{
@ -35,7 +36,7 @@ impl<I: Ip> Peer<I> {
}
}
pub type PeerMap<I> = AmortizedIndexMap<PeerId, Peer<I>>;
pub type PeerMap<I> = IndexMap<PeerId, Peer<I>>;
pub struct TorrentData<I: Ip> {
peers: PeerMap<I>,

View file

@ -13,7 +13,7 @@ use hashbrown::HashMap;
use rand::{rngs::SmallRng, SeedableRng};
use aquatic_common::{
extract_response_peers, AmortizedIndexMap, PanicSentinel, SecondsSinceServerStart,
extract_response_peers, AmortizedIndexMap, IndexMap, PanicSentinel, SecondsSinceServerStart,
ServerStartInstant,
};
use aquatic_ws_protocol::*;
@ -53,7 +53,7 @@ struct Peer {
pub valid_until: ValidUntil,
}
type PeerMap = AmortizedIndexMap<PeerId, Peer>;
type PeerMap = IndexMap<PeerId, Peer>;
struct TorrentData {
pub peers: PeerMap,