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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/leveldb/include/leveldb/slice.h]
/**
| Slice is a simple structure containing
| a pointer into some external storage and
| a size. The user of a Slice must ensure that
| the slice is not used after the corresponding
| external storage has been deallocated.
|
| Multiple threads can invoke const methods on
| a Slice without external synchronization, but
| if any of the threads may call a non-const
| method, all threads accessing the same Slice
| must use external synchronization.
*/
pub struct Slice {
data: *const u8,
size: usize,
}
impl Default for Slice {
/**
| Create an empty slice.
|
*/
fn default() -> Self {
todo!();
/*
: data(""),
: size(0),
*/
}
}
impl Index<usize> for Slice {
type Output = u8;
/**
| Return the ith byte in the referenced data.
|
| REQUIRES: n < size()
*/
#[inline] fn index(&self, n: usize) -> &Self::Output {
todo!();
/*
assert(n < size());
return data_[n];
*/
}
}
impl PartialEq<Slice> for Slice {
fn eq(&self, other: &Slice) -> bool {
todo!();
/*
return ((x.size() == y.size()) &&
(memcmp(x.data(), y.data(), x.size()) == 0));
*/
}
}
impl Eq for Slice {}
impl From<&String> for Slice {
/**
| Create a slice that refers to the contents
| of "s"
|
*/
fn from(s: &String) -> Self {
todo!();
/*
: data(s.data()),
: size(s.size()),
*/
}
}
impl From<*const u8> for Slice {
/**
| Create a slice that refers to s[0,strlen(s)-1]
|
*/
fn from(s: *const u8) -> Self {
todo!();
/*
: data(s),
: size(strlen(s)),
*/
}
}
impl Slice {
/**
| Create a slice that refers to d[0,n-1].
|
*/
pub fn from_ptr_len(
d: *const u8,
n: usize) -> Self {
todo!();
/*
: data(d),
: size(n),
*/
}
/**
| Return a pointer to the beginning of
| the referenced data
|
*/
pub fn data(&self) -> *const u8 {
todo!();
/*
return data_;
*/
}
/**
| Return the length (in bytes) of the referenced
| data
|
*/
pub fn size(&self) -> usize {
todo!();
/*
return size_;
*/
}
/**
| Return true iff the length of the referenced
| data is zero
|
*/
pub fn empty(&self) -> bool {
todo!();
/*
return size_ == 0;
*/
}
/**
| Change this slice to refer to an empty
| array
|
*/
pub fn clear(&mut self) {
todo!();
/*
data_ = "";
size_ = 0;
*/
}
/**
| Drop the first "n" bytes from this slice.
|
*/
pub fn remove_prefix(&mut self, n: usize) {
todo!();
/*
assert(n <= size());
data_ += n;
size_ -= n;
*/
}
/**
| Return a string that contains the copy
| of the referenced data.
|
*/
pub fn to_string(&self) -> String {
todo!();
/*
return std::string(data_, size_);
*/
}
/**
| Return true iff "x" is a prefix of "*this"
|
*/
pub fn starts_with(&self, x: &Slice) -> bool {
todo!();
/*
return ((size_ >= x.size_) && (memcmp(data_, x.data_, x.size_) == 0));
*/
}
/**
| Three-way comparison. Returns value:
| < 0 iff "*this" < "b",
| == 0 iff "*this" == "b",
| > 0 iff "*this" > "b"
*/
#[inline] pub fn compare(&self, b: &Slice) -> i32 {
todo!();
/*
const size_t min_len = (size_ < b.size_) ? size_ : b.size_;
int r = memcmp(data_, b.data_, min_len);
if (r == 0) {
if (size_ < b.size_)
r = -1;
else if (size_ > b.size_)
r = +1;
}
return r;
*/
}
}