Skip to content

Commit 78051ea

Browse files
committed
bt
1 parent 6ba638f commit 78051ea

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["algorithm-macro"]
33

44
[package]
55
name = "algorithm"
6-
version = "0.1.13"
6+
version = "0.1.14"
77
edition = "2021"
88
authors = ["tickbh <[email protected]>"]
99
description = "about algorithm data structure, now has ttl with lru/lru-k/lfu/arc and slab/rbtree/roaring_bitmap/timer_wheelss, 关于算法常用的数据结构"
@@ -15,7 +15,7 @@ keywords = ["arc", "lru", "lfu", "timerwheel", "slab"]
1515

1616
[dependencies]
1717
lazy_static="1.5.0"
18-
hashbrown="0.14"
18+
hashbrown="0.15.1"
1919
log="0.4.22"
2020

2121
[dependencies.algorithm-macro]
@@ -24,7 +24,7 @@ version = "0.1"
2424

2525
[dev-dependencies]
2626
rand="0.8.5"
27-
libc="0.2.158"
27+
libc="0.2.162"
2828
slab = "0.4.9"
2929

3030
[profile.release]

src/buf/binary_mut.rs

+14
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ unsafe impl BtMut for BinaryMut {
396396
}
397397
}
398398

399+
400+
399401
impl AsRef<[u8]> for BinaryMut {
400402
#[inline]
401403
fn as_ref(&self) -> &[u8] {
@@ -554,6 +556,18 @@ impl Write for BinaryMut {
554556
}
555557
}
556558

559+
// impl Write for &mut BinaryMut {
560+
// #[inline(always)]
561+
// fn write(&mut self, buf: &[u8]) -> Result<usize> {
562+
// self.put_slice(buf);
563+
// Ok(buf.len())
564+
// }
565+
566+
// fn flush(&mut self) -> Result<()> {
567+
// Ok(())
568+
// }
569+
// }
570+
557571
impl Debug for BinaryMut {
558572
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
559573
f.debug_struct("BinaryMut")

src/buf/bt.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1364,3 +1364,26 @@ impl<T: AsRef<[u8]>> Bt for std::io::Cursor<T> {
13641364
Binary::from(self.get_ref().as_ref()[(self.position() as usize)..].to_vec())
13651365
}
13661366
}
1367+
1368+
1369+
impl<T: Bt> Bt for &mut T {
1370+
fn remaining(&self) -> usize {
1371+
T::remaining(self)
1372+
}
1373+
1374+
fn chunk(&self) -> &[u8] {
1375+
T::chunk(self)
1376+
}
1377+
1378+
fn advance(&mut self, n: usize) {
1379+
T::advance(self, n)
1380+
}
1381+
1382+
fn advance_chunk(&mut self, n: usize) -> &[u8] {
1383+
T::advance_chunk(self, n)
1384+
}
1385+
1386+
fn into_binary(self) -> Binary {
1387+
panic!("mut ref must not into")
1388+
}
1389+
}

src/buf/bt_mut.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1035,4 +1035,18 @@ unsafe impl BtMut for Vec<u8> {
10351035
}
10361036
}
10371037

1038+
}
1039+
1040+
unsafe impl<T: BtMut> BtMut for &mut T {
1041+
fn remaining_mut(&self) -> usize {
1042+
T::remaining_mut(self)
1043+
}
1044+
1045+
unsafe fn advance_mut(&mut self, cnt: usize) {
1046+
T::advance_mut(self, cnt)
1047+
}
1048+
1049+
fn chunk_mut(&mut self) -> &mut [MaybeUninit<u8>] {
1050+
T::chunk_mut(self)
1051+
}
10381052
}

0 commit comments

Comments
 (0)