mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
Replace HashMap and IndexMap with indexmap_amortized
This will hopefully get down latency.
This commit is contained in:
parent
362ee7274f
commit
b8073e4bd1
12 changed files with 55 additions and 41 deletions
|
|
@ -199,7 +199,6 @@ mod tests {
|
|||
use std::collections::HashSet;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use quickcheck::{quickcheck, TestResult};
|
||||
use rand::thread_rng;
|
||||
|
||||
|
|
@ -229,7 +228,7 @@ mod tests {
|
|||
let gen_num_peers = data.0 as u32;
|
||||
let req_num_peers = data.1 as usize;
|
||||
|
||||
let mut peer_map: PeerMap<Ipv4Addr> = IndexMap::with_capacity(gen_num_peers as usize);
|
||||
let mut peer_map: PeerMap<Ipv4Addr> = Default::default();
|
||||
|
||||
let mut opt_sender_key = None;
|
||||
let mut opt_sender_peer = None;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ use std::sync::Arc;
|
|||
use std::time::Instant;
|
||||
|
||||
use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap};
|
||||
use hashbrown::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use aquatic_common::AHashIndexMap;
|
||||
|
||||
pub use aquatic_common::{access_list::AccessList, ValidUntil};
|
||||
pub use aquatic_udp_protocol::*;
|
||||
|
|
@ -80,7 +79,7 @@ pub struct PeerMapKey<I: Ip> {
|
|||
pub peer_id: PeerId,
|
||||
}
|
||||
|
||||
pub type PeerMap<I> = IndexMap<PeerMapKey<I>, Peer<I>>;
|
||||
pub type PeerMap<I> = AHashIndexMap<PeerMapKey<I>, Peer<I>>;
|
||||
|
||||
pub struct TorrentData<I: Ip> {
|
||||
pub peers: PeerMap<I>,
|
||||
|
|
@ -91,14 +90,14 @@ pub struct TorrentData<I: Ip> {
|
|||
impl<I: Ip> Default for TorrentData<I> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
peers: IndexMap::new(),
|
||||
peers: Default::default(),
|
||||
num_seeders: 0,
|
||||
num_leechers: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type TorrentMap<I> = HashMap<InfoHash, TorrentData<I>>;
|
||||
pub type TorrentMap<I> = AHashIndexMap<InfoHash, TorrentData<I>>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TorrentMaps {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::{net::SocketAddr, time::Instant};
|
||||
|
||||
use aquatic_common::AHashIndexMap;
|
||||
pub use aquatic_common::{access_list::AccessList, ValidUntil};
|
||||
pub use aquatic_udp_protocol::*;
|
||||
use hashbrown::HashMap;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ConnectionMap(HashMap<(ConnectionId, SocketAddr), ValidUntil>);
|
||||
pub struct ConnectionMap(AHashIndexMap<(ConnectionId, SocketAddr), ValidUntil>);
|
||||
|
||||
impl ConnectionMap {
|
||||
pub fn insert(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue