Make a true v0.2.0 release

This commit is contained in:
Alex 2021-10-18 11:51:37 +02:00
parent 040231d554
commit 448709c1db
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1
4 changed files with 16 additions and 15 deletions

3
Cargo.lock generated
View file

@ -311,7 +311,8 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "kuska-handshake" name = "kuska-handshake"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/Alexis211/handshake?branch=tokio1.0#a99e5a9c8591c41c99ce0bdfe18d596e3933bc4e" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e33da4b69f23c2ece0b3e729d079cebdc2c0206e493e42f510f500ad81c631d5"
dependencies = [ dependencies = [
"futures", "futures",
"hex", "hex",

View file

@ -39,7 +39,7 @@ bytes = "0.6.0"
lru = { version = "0.6", optional = true } lru = { version = "0.6", optional = true }
sodiumoxide = { version = "0.2.5-0", package = "kuska-sodiumoxide" } sodiumoxide = { version = "0.2.5-0", package = "kuska-sodiumoxide" }
kuska-handshake = { version = "0.2.0", git = "https://github.com/Alexis211/handshake", branch = "tokio1.0", features = ["default", "async_std"] } kuska-handshake = { version = "0.2.0", features = ["default", "async_std"] }
[dev-dependencies] [dev-dependencies]
structopt = { version = "0.3", default-features = false } structopt = { version = "0.3", default-features = false }

View file

@ -13,8 +13,6 @@
//! about message priorization. //! about message priorization.
//! Also check out the examples to learn how to use this crate. //! Also check out the examples to learn how to use this crate.
#![feature(map_first_last)]
pub mod error; pub mod error;
pub mod util; pub mod util;

View file

@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap, VecDeque}; use std::collections::{HashMap, VecDeque};
use std::sync::Arc; use std::sync::Arc;
use log::trace; use log::trace;
@ -50,31 +50,33 @@ struct SendQueueItem {
} }
struct SendQueue { struct SendQueue {
items: BTreeMap<u8, VecDeque<SendQueueItem>>, items: VecDeque<(u8, VecDeque<SendQueueItem>)>,
} }
impl SendQueue { impl SendQueue {
fn new() -> Self { fn new() -> Self {
Self { Self {
items: BTreeMap::new(), items: VecDeque::with_capacity(64),
} }
} }
fn push(&mut self, item: SendQueueItem) { fn push(&mut self, item: SendQueueItem) {
let prio = item.prio; let prio = item.prio;
let mut items_at_prio = self let pos_prio = match self.items.binary_search_by(|(p, _)| p.cmp(&prio)) {
.items Ok(i) => i,
.remove(&prio) Err(i) => {
.unwrap_or_else(|| VecDeque::with_capacity(4)); self.items.insert(i, (prio, VecDeque::new()));
items_at_prio.push_back(item); i
self.items.insert(prio, items_at_prio); }
};
self.items[pos_prio].1.push_back(item);
} }
fn pop(&mut self) -> Option<SendQueueItem> { fn pop(&mut self) -> Option<SendQueueItem> {
match self.items.pop_first() { match self.items.pop_front() {
None => None, None => None,
Some((prio, mut items_at_prio)) => { Some((prio, mut items_at_prio)) => {
let ret = items_at_prio.pop_front(); let ret = items_at_prio.pop_front();
if !items_at_prio.is_empty() { if !items_at_prio.is_empty() {
self.items.insert(prio, items_at_prio); self.items.push_front((prio, items_at_prio));
} }
ret.or_else(|| self.pop()) ret.or_else(|| self.pop())
} }