Sort weighted bucket iter() by weight

This commit is contained in:
folex
2020-03-26 19:06:44 +03:00
parent f60d004675
commit 3d52a6b021
3 changed files with 13 additions and 11 deletions

View File

@ -74,7 +74,7 @@ fn build_nodes_with_config(num: usize, cfg: KademliaConfig) -> (u64, Vec<(ed2551
let local_id = local_public_key.clone().into_peer_id(); let local_id = local_public_key.clone().into_peer_id();
let store = MemoryStore::new(local_id.clone()); let store = MemoryStore::new(local_id.clone());
let trust = TrustGraph::new(HashMap::new()); let trust = TrustGraph::new(Vec::new());
let behaviour = Kademlia::with_config(ed25519_key.clone(), local_id.clone(), store, cfg.clone(), trust); let behaviour = Kademlia::with_config(ed25519_key.clone(), local_id.clone(), store, cfg.clone(), trust);
result.push((ed25519_key, Swarm::new(transport, behaviour, local_id))); result.push((ed25519_key, Swarm::new(transport, behaviour, local_id)));
} }

View File

@ -178,12 +178,6 @@ where
/// the node that was replaced. `None` indicates that the nodes in the /// the node that was replaced. `None` indicates that the nodes in the
/// bucket remained unchanged. /// bucket remained unchanged.
pub fn apply_pending(&mut self) -> Vec<AppliedPending<TKey, TVal>> { pub fn apply_pending(&mut self) -> Vec<AppliedPending<TKey, TVal>> {
// self.weighted
// .apply_pending()
// .iter()
// .chain(self.swamp.apply_pending().iter())
// .collect()
Iterator::chain( Iterator::chain(
self.weighted.apply_pending().into_iter(), self.weighted.apply_pending().into_iter(),
self.swamp.apply_pending().into_iter(), self.swamp.apply_pending().into_iter(),

View File

@ -311,10 +311,18 @@ where
} }
} }
pub fn iter(&self) -> impl Iterator<Item = (&Node<TKey, TVal>, NodeStatus)> { pub fn iter(&self) -> impl Iterator<Item = (&Node<TKey, TVal>, NodeStatus)> + '_ {
self.map let mut keys = self.map.keys().collect::<Vec<_>>();
.values() keys.sort();
.map(|bucket| bucket.iter().map(|(n, s)| (&n.inner, s))) let map: &HashMap<u32, _> = &self.map;
keys.into_iter()
.map(move |w| {
map.get(&w)
.into_iter()
.map(|bucket| bucket.iter().map(|(n, s)| (&n.inner, s)))
.flatten()
})
.flatten() .flatten()
} }