1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use crate::index::config::{check_over_size_limit, IndexType, IndexTypeId, IndexTypeInternal};
use std::fmt::Display;
use std::ops::Deref;
use std::sync::Arc;
#[derive(Debug, Clone, Eq)]
pub struct ByteVec {
value: Arc<Vec<u8>>,
start: usize,
size: usize,
}
impl ByteVec {
pub fn new(value: Vec<u8>) -> Self {
let size = value.len();
Self {
value: Arc::new(value),
start: 0,
size,
}
}
pub fn new_slice(value: Arc<Vec<u8>>, start: usize, size: usize) -> Self {
Self { value, start, size }
}
fn slice(&self) -> &[u8] {
&self.value[self.start..self.start + self.size]
}
}
impl PartialOrd for ByteVec {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.slice().partial_cmp(other.slice())
}
}
impl PartialEq for ByteVec {
fn eq(&self, other: &Self) -> bool {
self.slice().eq(other.slice())
}
}
impl Ord for ByteVec {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.slice().cmp(other.slice())
}
}
impl Deref for ByteVec {
type Target = [u8];
fn deref(&self) -> &Self::Target {
self.slice()
}
}
impl From<&[u8]> for ByteVec {
fn from(f: &[u8]) -> ByteVec {
ByteVec::new(f.to_vec())
}
}
impl From<Vec<u8>> for ByteVec {
fn from(f: Vec<u8>) -> ByteVec {
ByteVec::new(f)
}
}
impl From<ByteVec> for Vec<u8> {
fn from(f: ByteVec) -> Vec<u8> {
f.slice().to_vec()
}
}
impl Display for ByteVec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.slice())
}
}
impl IndexTypeInternal for ByteVec {
fn get_id() -> u8 {
16
}
fn get_type_id() -> IndexTypeId {
IndexTypeId::ByteVec
}
fn over_size_limit(&self) -> bool {
check_over_size_limit(self.size)
}
}
impl IndexType for ByteVec {}