diff --git a/Cargo.lock b/Cargo.lock index f453d16..40d2fe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ dependencies = [ [[package]] name = "algorithm" -version = "0.1.10" +version = "0.1.11" dependencies = [ "algorithm-macro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown", diff --git a/Cargo.toml b/Cargo.toml index 98d4c6c..bb7f022 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["algorithm-macro"] [package] name = "algorithm" -version = "0.1.10" +version = "0.1.11" edition = "2021" authors = ["tickbh "] description = "about algorithm data structure, now has ttl with lru/lru-k/lfu/arc and slab/rbtree/roaring_bitmap/timer_wheelss, 关于算法常用的数据结构" diff --git a/src/buf/binary_mut.rs b/src/buf/binary_mut.rs index 464005f..3091095 100644 --- a/src/buf/binary_mut.rs +++ b/src/buf/binary_mut.rs @@ -289,9 +289,20 @@ impl BinaryMut { } } + /// 获取可读且已初始化的数据 + /// + /// # Examples + /// + /// ``` + /// use algorithm::buf::{BinaryMut, Bt, BtMut}; + /// + /// let mut buf = BinaryMut::with_capacity(0); + /// assert!(buf.data_mut().len() != 0); + /// + /// ``` pub fn data_mut(&mut self) -> &mut [u8] { - if self.wpos + 128 < self.vec.capacity() { - self.reserve(128); + if self.wpos + 128 > self.vec.len() { + self.vec.resize(self.wpos + 128, 0); } &mut self.vec[self.wpos..] }