Showing 1 of 1 files from the diff.

@@ -6,7 +6,10 @@
Loading
6 6
        keeper::Container,
7 7
        nodes::{Leaf, LeafEntry, Node, NodeRef, Nodes, Value},
8 8
    },
9 -
    io::{InfallibleRead, InfallibleReadFormat, InfallibleWrite, InfallibleWriteFormat},
9 +
    io::{
10 +
        InfallibleRead, InfallibleReadFormat, InfallibleReadVarInt, InfallibleWrite, InfallibleWriteFormat,
11 +
        InfallibleWriteVarInt,
12 +
    },
10 13
};
11 14
use std::io::Cursor;
12 15
@@ -55,21 +58,21 @@
Loading
55 58
56 59
pub fn deserialize_v0<K: IndexType, V: IndexType>(value: &[u8]) -> PRes<Node<K, V>> {
57 60
    let mut reader = Cursor::new(value);
58 -
    let t = reader.read_u8();
61 +
    let t = reader.read_varint_u8();
59 62
    match t {
60 63
        1 => {
61 -
            let prev = if reader.read_u8() == 1 {
64 +
            let prev = if reader.read_varint_u8() == 1 {
62 65
                Some(K::deserialize(&mut reader)?)
63 66
            } else {
64 67
                None
65 68
            };
66 -
            let size = reader.read_u32();
69 +
            let size = reader.read_varint_u32();
67 70
            let mut entries = Vec::with_capacity(size as usize);
68 71
            for _ in 0..size {
69 72
                let key = K::deserialize(&mut reader)?;
70 -
                let value_type = reader.read_u8();
73 +
                let value_type = reader.read_varint_u8();
71 74
                if value_type == 1 {
72 -
                    let val_size = reader.read_u32();
75 +
                    let val_size = reader.read_varint_u32();
73 76
                    let mut value = Vec::with_capacity(val_size as usize);
74 77
                    for _ in 0..val_size {
75 78
                        value.push(V::deserialize(&mut reader)?);
@@ -86,7 +89,7 @@
Loading
86 89
                    });
87 90
                }
88 91
            }
89 -
            let next = if reader.read_u8() == 1 {
92 +
            let next = if reader.read_varint_u8() == 1 {
90 93
                Some(K::deserialize(&mut reader)?)
91 94
            } else {
92 95
                None
@@ -94,25 +97,25 @@
Loading
94 97
            Ok(Node::LEAF(Leaf { entries, prev, next }))
95 98
        }
96 99
        2 => {
97 -
            let prev = if reader.read_u8() == 1 {
100 +
            let prev = if reader.read_varint_u8() == 1 {
98 101
                Some(K::deserialize(&mut reader)?)
99 102
            } else {
100 103
                None
101 104
            };
102 -
            let size = reader.read_u32();
105 +
            let size = reader.read_varint_u32();
103 106
            let mut keys = Vec::with_capacity(size as usize);
104 107
            for _ in 0..size {
105 108
                let key = K::deserialize(&mut reader)?;
106 109
                keys.push(key);
107 110
            }
108 -
            let size = reader.read_u32();
111 +
            let size = reader.read_varint_u32();
109 112
            let mut pointers = Vec::with_capacity(size as usize);
110 113
            for _ in 0..size {
111 -
                let page = reader.read_u64();
112 -
                let pos = reader.read_u32();
114 +
                let page = reader.read_varint_u64();
115 +
                let pos = reader.read_varint_u32();
113 116
                pointers.push(RecRef::new(page, pos));
114 117
            }
115 -
            let next = if reader.read_u8() == 1 {
118 +
            let next = if reader.read_varint_u8() == 1 {
116 119
                Some(K::deserialize(&mut reader)?)
117 120
            } else {
118 121
                None
@@ -136,8 +139,8 @@
Loading
136 139
}
137 140
pub fn serialize_v0<K: IndexType, V: IndexType>(node: &Node<K, V>, dest: &mut dyn InfallibleWrite) -> PRes<()> {
138 141
    let write_page_and_pos = |dest: &mut dyn InfallibleWrite, page, pos| -> PRes<()> {
139 -
        dest.write_u64(page);
140 -
        dest.write_u32(pos);
142 +
        dest.write_varint_u64(page);
143 +
        dest.write_varint_u32(pos);
141 144
        Ok(())
142 145
    };
143 146
@@ -152,58 +155,58 @@
Loading
152 155
153 156
    match node {
154 157
        Node::LEAF(leaf) => {
155 -
            dest.write_u8(1);
158 +
            dest.write_varint_u8(1);
156 159
            if let Some(pk) = &leaf.prev {
157 -
                dest.write_u8(1);
160 +
                dest.write_varint_u8(1);
158 161
                pk.serialize(dest)?;
159 162
            } else {
160 -
                dest.write_u8(0);
163 +
                dest.write_varint_u8(0);
161 164
            }
162 -
            dest.write_u32(leaf.entries.len() as u32);
165 +
            dest.write_varint_u32(leaf.entries.len() as u32);
163 166
            for entry in &leaf.entries {
164 167
                entry.key.serialize(dest)?;
165 168
                match &entry.value {
166 169
                    Value::CLUSTER(cluster) => {
167 -
                        dest.write_u8(1);
168 -
                        dest.write_u32(cluster.len() as u32);
170 +
                        dest.write_varint_u8(1);
171 +
                        dest.write_varint_u32(cluster.len() as u32);
169 172
                        for val in cluster {
170 173
                            val.serialize(dest)?;
171 174
                        }
172 175
                    }
173 176
                    Value::SINGLE(val) => {
174 -
                        dest.write_u8(2);
177 +
                        dest.write_varint_u8(2);
175 178
                        val.serialize(dest)?;
176 179
                    }
177 180
                }
178 181
            }
179 182
            if let Some(pk) = &leaf.next {
180 -
                dest.write_u8(1);
183 +
                dest.write_varint_u8(1);
181 184
                pk.serialize(dest)?;
182 185
            } else {
183 -
                dest.write_u8(0);
186 +
                dest.write_varint_u8(0);
184 187
            }
185 188
        }
186 189
        Node::NODE(node) => {
187 -
            dest.write_u8(2);
190 +
            dest.write_varint_u8(2);
188 191
            if let Some(pk) = &node.prev {
189 -
                dest.write_u8(1);
192 +
                dest.write_varint_u8(1);
190 193
                pk.serialize(dest)?;
191 194
            } else {
192 -
                dest.write_u8(0);
195 +
                dest.write_varint_u8(0);
193 196
            }
194 -
            dest.write_u32(node.keys.len() as u32);
197 +
            dest.write_varint_u32(node.keys.len() as u32);
195 198
            for k in &node.keys {
196 199
                k.serialize(dest)?;
197 200
            }
198 -
            dest.write_u32(node.pointers.len() as u32);
201 +
            dest.write_varint_u32(node.pointers.len() as u32);
199 202
            for p in &node.pointers {
200 203
                write_opt_leafptr(dest, Some(p))?;
201 204
            }
202 205
            if let Some(pk) = &node.next {
203 -
                dest.write_u8(1);
206 +
                dest.write_varint_u8(1);
204 207
                pk.serialize(dest)?;
205 208
            } else {
206 -
                dest.write_u8(0);
209 +
                dest.write_varint_u8(0);
207 210
            }
208 211
        }
209 212
    }
@@ -212,101 +215,101 @@
Loading
212 215
213 216
impl IndexSerialization for u8 {
214 217
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
215 -
        buffer.write_u8(*self);
218 +
        buffer.write_varint_u8(*self);
216 219
        Ok(())
217 220
    }
218 221
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
219 -
        Ok(value.read_u8())
222 +
        Ok(value.read_varint_u8())
220 223
    }
221 224
}
222 225
223 226
impl IndexSerialization for u16 {
224 227
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
225 -
        buffer.write_u16(*self);
228 +
        buffer.write_varint_u16(*self);
226 229
        Ok(())
227 230
    }
228 231
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
229 -
        Ok(value.read_u16())
232 +
        Ok(value.read_varint_u16())
230 233
    }
231 234
}
232 235
233 236
impl IndexSerialization for u32 {
234 237
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
235 -
        buffer.write_u32(*self);
238 +
        buffer.write_varint_u32(*self);
236 239
        Ok(())
237 240
    }
238 241
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
239 -
        Ok(value.read_u32())
242 +
        Ok(value.read_varint_u32())
240 243
    }
241 244
}
242 245
243 246
impl IndexSerialization for u64 {
244 247
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
245 -
        buffer.write_u64(*self);
248 +
        buffer.write_varint_u64(*self);
246 249
        Ok(())
247 250
    }
248 251
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
249 -
        Ok(value.read_u64())
252 +
        Ok(value.read_varint_u64())
250 253
    }
251 254
}
252 255
253 256
impl IndexSerialization for u128 {
254 257
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
255 -
        buffer.write_u128(*self);
258 +
        buffer.write_varint_u128(*self);
256 259
        Ok(())
257 260
    }
258 261
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
259 -
        Ok(value.read_u128())
262 +
        Ok(value.read_varint_u128())
260 263
    }
261 264
}
262 265
263 266
impl IndexSerialization for i8 {
264 267
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
265 -
        buffer.write_i8(*self);
268 +
        buffer.write_varint_i8(*self);
266 269
        Ok(())
267 270
    }
268 271
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
269 -
        Ok(value.read_i8())
272 +
        Ok(value.read_varint_i8())
270 273
    }
271 274
}
272 275
273 276
impl IndexSerialization for i16 {
274 277
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
275 -
        buffer.write_i16(*self);
278 +
        buffer.write_varint_i16(*self);
276 279
        Ok(())
277 280
    }
278 281
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
279 -
        Ok(value.read_i16())
282 +
        Ok(value.read_varint_i16())
280 283
    }
281 284
}
282 285
283 286
impl IndexSerialization for i32 {
284 287
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
285 -
        buffer.write_i32(*self);
288 +
        buffer.write_varint_i32(*self);
286 289
        Ok(())
287 290
    }
288 291
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
289 -
        Ok(value.read_i32())
292 +
        Ok(value.read_varint_i32())
290 293
    }
291 294
}
292 295
293 296
impl IndexSerialization for i64 {
294 297
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
295 -
        buffer.write_i64(*self);
298 +
        buffer.write_varint_i64(*self);
296 299
        Ok(())
297 300
    }
298 301
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
299 -
        Ok(value.read_i64())
302 +
        Ok(value.read_varint_i64())
300 303
    }
301 304
}
302 305
303 306
impl IndexSerialization for i128 {
304 307
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
305 -
        buffer.write_i128(*self);
308 +
        buffer.write_varint_i128(*self);
306 309
        Ok(())
307 310
    }
308 311
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
309 -
        Ok(value.read_i128())
312 +
        Ok(value.read_varint_i128())
310 313
    }
311 314
}
312 315
@@ -332,25 +335,25 @@
Loading
332 335
333 336
impl IndexSerialization for PersyId {
334 337
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
335 -
        buffer.write_u64(self.0.page);
336 -
        buffer.write_u32(self.0.pos);
338 +
        buffer.write_varint_u64(self.0.page);
339 +
        buffer.write_varint_u32(self.0.pos);
337 340
        Ok(())
338 341
    }
339 342
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
340 -
        let page = value.read_u64();
341 -
        let pos = value.read_u32();
343 +
        let page = value.read_varint_u64();
344 +
        let pos = value.read_varint_u32();
342 345
        Ok(PersyId(RecRef::new(page, pos)))
343 346
    }
344 347
}
345 348
346 349
impl IndexSerialization for String {
347 350
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
348 -
        buffer.write_u16(self.len() as u16);
351 +
        buffer.write_varint_u32(self.len() as u32);
349 352
        buffer.write_all(self.as_bytes());
350 353
        Ok(())
351 354
    }
352 355
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
353 -
        let string_size = value.read_u16();
356 +
        let string_size = value.read_varint_u32();
354 357
        let mut buff = vec![0; string_size as usize];
355 358
        value.read_exact(&mut buff);
356 359
        let string = String::from_utf8(buff).map_err(|e| PersyError::DecodingUtf8(e.utf8_error()))?;
@@ -360,12 +363,12 @@
Loading
360 363
361 364
impl IndexSerialization for ByteVec {
362 365
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PRes<()> {
363 -
        buffer.write_u16(self.0.len() as u16);
366 +
        buffer.write_varint_u32(self.0.len() as u32);
364 367
        buffer.write_all(self.0.as_slice());
365 368
        Ok(())
366 369
    }
367 370
    fn deserialize(value: &mut dyn InfallibleRead) -> PRes<Self> {
368 -
        let vec_size = value.read_u16();
371 +
        let vec_size = value.read_varint_u32();
369 372
        let mut slice: Vec<u8> = vec![0; vec_size as usize];
370 373
        value.read_exact(&mut slice);
371 374
        Ok(ByteVec(slice))
Files Coverage
src 93.14%
tests 98.56%
Project Totals (29 files) 94.13%
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading