diff --git a/README.md b/README.md index ff45216cef233604d7a437462402e3618e3a9fcd..725b3742f0042e0e7527cdcbbbe8f727571c57c7 100644 --- a/README.md +++ b/README.md @@ -37,18 +37,18 @@ LevelDB for rust 1. 1.0.0 版本, 完成 util 相关的内容 -| 功能模块 | 完成人 | -|-------------------------------|--------------| -| Arena (Memory Management) | wangboo | -| Slice | wangboo | -| BloomFilter | colagy | -| Cache | colagy | -| Coding (Primitive Type SerDe) | colagy | -| Comparator | fengyang | -| Status | fengyang | -| Random | fengyang | -| CRC | lxd5866 | -| Env | lxd5866 | -| Hash | lxd5866 | -| MutexLock | kazeseiriou | -| Histgram | kazeseiriou | \ No newline at end of file +| 功能模块 | 完成人 | +|-------------------------------|-------------| +| Arena (Memory Management) | wangboo | +| Slice | wangboo | +| Random | colagy | +| Cache | colagy | +| Coding (Primitive Type SerDe) | colagy | +| Comparator | fengyang | +| Status | fengyang | +| BloomFilter | fengyang | +| CRC | lxd5866 | +| Env | lxd5866 | +| Hash | lxd5866 | +| MutexLock | kazeseiriou | +| Histgram | kazeseiriou | \ No newline at end of file diff --git a/src/traits/iterator.rs b/src/traits/iterator.rs index 319650a7a237f22507e4ef62f6347fac70f37f12..a985e81ad68b49c971c249bca5fefd5ae1908854 100644 --- a/src/traits/iterator.rs +++ b/src/traits/iterator.rs @@ -1,7 +1,6 @@ -use crate::util::Slice; +use crate::util::slice::Slice; pub trait Iterator { - fn valid(&self) -> bool; fn seek_to_first(&mut self); @@ -19,6 +18,4 @@ pub trait Iterator { fn value(&self) -> &Slice; } -trait AAA { - -} +trait AAA {} diff --git a/src/traits/mod.rs b/src/traits/mod.rs index fb4a7b14ad387496c2539be1c2670821968f4824..74f6e800347c1bb0251c7f5bbabbba7ddd13c936 100644 --- a/src/traits/mod.rs +++ b/src/traits/mod.rs @@ -1,4 +1,4 @@ -use crate::util::Slice; +use crate::util::slice::Slice; mod iterator; mod comparator; diff --git a/src/util/coding.rs b/src/util/coding.rs new file mode 100644 index 0000000000000000000000000000000000000000..74f2492e3cef4de6067d84fabb54e2da55413728 --- /dev/null +++ b/src/util/coding.rs @@ -0,0 +1,47 @@ +const B: u8 = 128; + +/// +/// +/// +pub trait Coding { + fn varint32(self, buf: &mut [u8]); +} + +impl Coding for u32 +{ + fn varint32(self, buf: &mut [u8]) { + // if self < 1 << 7 { + // buf[0] = self as u8; + // } else if self < 1 << 14 { + // buf[0] = self | B; + // println!("{:b}", buf[0]); + // buf[1] = buf[0] >> 7; + // println!("{:b}", buf[1]); + // } else if self < 1 << 21 { + // buf[0] = (self | B as u8) as u8; + // println!("{:b}", buf[0]); + // buf[1] = (buf[0] >> 7) | B; + // println!("{:b}", buf[1]); + // buf[2] = buf[1] >> 14; + // println!("{:b}", buf[2]); + // } else if self < 1 << 28 { + // buf[0] = (self | B as u8) as u8; + // println!("{:b}", buf[0]); + // buf[1] = (buf[0] >> 7) | B; + // println!("{:b}", buf[1]); + // buf[2] = (buf[1] >> 14) | B; + // println!("{:b}", buf[2]); + // buf[3] = buf[2] >> 21; + // } else { + // buf[0] = (self | B as u8) as u8; + // println!("{:b}", buf[0]); + // buf[1] = (buf[0] >> 7) | B; + // println!("{:b}", buf[1]); + // buf[2] = (buf[1] >> 14) | B; + // println!("{:b}", buf[2]); + // buf[3] = (buf[2] >> 21) | B; + // println!("{:b}", buf[3]); + // buf[4] = buf[3] >> 28; + // } + } +} \ No newline at end of file diff --git a/src/util/coding_test.rs b/src/util/coding_test.rs new file mode 100644 index 0000000000000000000000000000000000000000..3c4184f62558e28f92d57534635ed78c81c3fc5c --- /dev/null +++ b/src/util/coding_test.rs @@ -0,0 +1,20 @@ +mod test { + use crate::util::coding::Coding; + + #[test] + fn test_i32() { + let mut buf: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + let x = 127.varint32(&mut buf); + println!("{:?}", buf); + println!("{:?}", x); + println!("{:b}", buf[0]); + } + + #[test] + fn test_offset() { + let buf: [u8; 3] = [0, 1, 2]; + let mut offset: usize = 0; + offset += 1; + println!("{:?}", buf[offset]) + } +} diff --git a/src/util/mod.rs b/src/util/mod.rs index 3f159e66e099d362139eb5513fe2506f8eab5d8b..fe7c884251c3c2b51d0c269ad6bcae918f4b8908 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,3 +1,5 @@ -mod slice; -mod status; -mod slice_test; \ No newline at end of file +pub mod slice; +pub mod status; +mod slice_test; +pub mod coding; +mod coding_test; \ No newline at end of file