feat: change Message.cancel from Vec to a HashSet

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-07-08 10:33:12 +02:00
parent e670faf1b4
commit 91d97b2586

View File

@ -6,7 +6,7 @@ use cid::Cid;
use core::convert::TryFrom;
use prost::Message as ProstMessage;
use std::{
collections::HashMap,
collections::{HashMap, HashSet},
mem,
sync::{
atomic::{AtomicU64, Ordering},
@ -127,7 +127,7 @@ pub struct Message {
/// List of wanted blocks.
want: HashMap<Cid, Priority>,
/// List of blocks to cancel.
cancel: Vec<Cid>,
cancel: HashSet<Cid>,
/// Wheather it is the full list of wanted blocks.
full: bool,
/// List of blocks to send.
@ -151,7 +151,7 @@ impl Message {
}
/// Returns the list of cancelled blocks.
pub fn cancel(&self) -> &[Cid] {
pub fn cancel(&self) -> &HashSet<Cid> {
&self.cancel
}
@ -172,7 +172,7 @@ impl Message {
/// Adds a block to the cancel list.
pub fn cancel_block(&mut self, cid: &Cid) {
self.cancel.push(cid.to_owned());
self.cancel.insert(cid.to_owned());
}
/// Removes the block from the want list.