Compare 0e11be4 ... +0 ... 924db1c


@@ -0,0 +1,516 @@
Loading
1 +
use super::{
2 +
    Index, IndexApply, IndexKeeper, IndexModify, IndexType, KeyChanges, Leaf, Node, NodeRef, Nodes, PRes, Value,
3 +
    ValueChange, ValueMode,
4 +
};
5 +
use crate::{error::PersyError, id::RecRef};
6 +
use rand::random;
7 +
use std::{collections::HashMap, ops::Bound, rc::Rc};
8 +
9 +
impl<V> std::fmt::Display for Value<V>
10 +
where
11 +
    V: std::fmt::Display,
12 +
{
13 +
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14 +
        match self {
15 +
            Value::CLUSTER(x) => {
16 +
                write!(f, "{} values: [", x.len())?;
17 +
                for v in x {
18 +
                    write!(f, " {}, ", v)?;
19 +
                }
20 +
                write!(f, "]")?;
21 +
            }
22 +
            Value::SINGLE(v) => {
23 +
                write!(f, "value: {}", v)?;
24 +
            }
25 +
        }
26 +
        Ok(())
27 +
    }
28 +
}
29 +
30 +
fn print_nodes<K: IndexType, V: IndexType>(
31 +
    tree: &mut dyn IndexKeeper<K, V>,
32 +
    node: &Nodes<K>,
33 +
    depth: usize,
34 +
) -> PRes<()> {
35 +
    let padding = String::from_utf8(vec![b' '; depth]).unwrap();
36 +
    for i in 0..node.len() {
37 +
        if i == 0 {
38 +
            println!("{} __ ", padding);
39 +
        } else {
40 +
            println!("{} {}  ", padding, node.keys[i - 1]);
41 +
        }
42 +
        print_node(tree, &node.pointers[i], depth + 1)?;
43 +
    }
44 +
    Ok(())
45 +
}
46 +
47 +
fn print_leaf<K: IndexType, V: IndexType>(
48 +
    _tree: &mut dyn IndexKeeper<K, V>,
49 +
    leaf: &Leaf<K, V>,
50 +
    depth: usize,
51 +
) -> PRes<()> {
52 +
    let padding = String::from_utf8(vec![b' '; depth]).unwrap();
53 +
    println!("{} ", padding);
54 +
    for i in 0..leaf.len() {
55 +
        println!("{} {} {} ", padding, leaf.entries[i].key, leaf.entries[i].value);
56 +
    }
57 +
    println!("{} ", padding);
58 +
    Ok(())
59 +
}
60 +
61 +
fn print_node<K: IndexType, V: IndexType>(tree: &mut dyn IndexKeeper<K, V>, node: &NodeRef, depth: usize) -> PRes<()> {
62 +
    match tree.load(node)? {
63 +
        Node::NODE(n) => {
64 +
            print_nodes(tree, &n, depth)?;
65 +
        }
66 +
        Node::LEAF(l) => {
67 +
            print_leaf(tree, &l, depth)?;
68 +
        }
69 +
    }
70 +
    Ok(())
71 +
}
72 +
73 +
fn print_tree<K: IndexType, V: IndexType>(tree: &mut dyn IndexKeeper<K, V>) -> PRes<()> {
74 +
    let root = tree.get_root()?;
75 +
    if let Some(r) = root {
76 +
        print_node(tree, &r, 0)?;
77 +
    } else {
78 +
        println!(" Empty Root");
79 +
    }
80 +
81 +
    Ok(())
82 +
}
83 +
fn random_pointer() -> NodeRef {
84 +
    RecRef::new(random::<u64>(), random::<u32>())
85 +
}
86 +
87 +
struct MockIndexKeeper<K: Clone + Ord, V: Clone> {
88 +
    store: HashMap<NodeRef, Node<K, V>>,
89 +
    root: Option<NodeRef>,
90 +
    v: ValueMode,
91 +
    name: String,
92 +
}
93 +
94 +
impl<K: Clone + Ord, V: Clone> MockIndexKeeper<K, V> {
95 +
    fn new() -> MockIndexKeeper<K, V> {
96 +
        MockIndexKeeper {
97 +
            store: HashMap::new(),
98 +
            root: None,
99 +
            v: ValueMode::REPLACE,
100 +
            name: "test_index".to_string(),
101 +
        }
102 +
    }
103 +
104 +
    fn new_mode(v: ValueMode) -> MockIndexKeeper<K, V> {
105 +
        MockIndexKeeper {
106 +
            store: HashMap::new(),
107 +
            root: None,
108 +
            v,
109 +
            name: "test_index".to_string(),
110 +
        }
111 +
    }
112 +
}
113 +
114 +
impl<K: Clone + Ord, V: Clone> IndexKeeper<K, V> for MockIndexKeeper<K, V> {
115 +
    fn load(&self, node: &NodeRef) -> PRes<Node<K, V>> {
116 +
        Ok(self.store.get(&node).unwrap().clone())
117 +
    }
118 +
    fn get_root(&self) -> PRes<Option<NodeRef>> {
119 +
        Ok(self.root.clone())
120 +
    }
121 +
122 +
    fn value_mode(&self) -> ValueMode {
123 +
        self.v.clone()
124 +
    }
125 +
126 +
    fn index_name(&self) -> &String {
127 +
        &self.name
128 +
    }
129 +
}
130 +
131 +
impl<K: Clone + Ord, V: Clone> IndexModify<K, V> for MockIndexKeeper<K, V> {
132 +
    fn load_modify(&self, node: &NodeRef) -> PRes<Option<(Rc<Node<K, V>>, u16)>> {
133 +
        Ok(Some((Rc::new(self.store.get(&node).unwrap().clone()), 0)))
134 +
    }
135 +
136 +
    fn lock(&mut self, _node: &NodeRef, _version: u16) -> PRes<bool> {
137 +
        Ok(true)
138 +
    }
139 +
140 +
    fn unlock(&mut self, _node: &NodeRef) -> PRes<bool> {
141 +
        Ok(true)
142 +
    }
143 +
    fn unlock_config(&mut self) -> PRes<bool> {
144 +
        Ok(true)
145 +
    }
146 +
147 +
    fn lock_config(&mut self) -> PRes<bool> {
148 +
        Ok(true)
149 +
    }
150 +
151 +
    fn owned(&mut self, _node_ref: &NodeRef, mut node: Rc<Node<K, V>>) -> Node<K, V> {
152 +
        Rc::make_mut(&mut node);
153 +
        Rc::try_unwrap(node).ok().unwrap()
154 +
    }
155 +
    fn insert(&mut self, node: Node<K, V>) -> PRes<NodeRef> {
156 +
        let node_ref = random_pointer();
157 +
        self.store.insert(node_ref.clone(), node.clone());
158 +
        Ok(node_ref)
159 +
    }
160 +
161 +
    fn update(&mut self, node_ref: &NodeRef, node: Node<K, V>, _version: u16) -> PRes<()> {
162 +
        self.store.insert(node_ref.clone(), node);
163 +
        Ok(())
164 +
    }
165 +
166 +
    fn get_root_refresh(&mut self) -> PRes<Option<NodeRef>> {
167 +
        Ok(self.root.clone())
168 +
    }
169 +
170 +
    fn set_root(&mut self, root: Option<NodeRef>) -> PRes<()> {
171 +
        Ok(self.root = root)
172 +
    }
173 +
174 +
    fn delete(&mut self, node: &NodeRef, _version: u16) -> PRes<()> {
175 +
        self.store.remove(&node);
176 +
        Ok(())
177 +
    }
178 +
    fn bottom_limit(&self) -> usize {
179 +
        10
180 +
    }
181 +
    fn top_limit(&self) -> usize {
182 +
        30
183 +
    }
184 +
}
185 +
186 +
#[test]
187 +
fn test_single_add() {
188 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
189 +
    let mut changes = Vec::new();
190 +
    changes.push(KeyChanges::single_add(1, 1));
191 +
    changes.push(KeyChanges::single_add(2, 2));
192 +
    changes.push(KeyChanges::single_add(3, 4));
193 +
    keeper.apply(&changes).unwrap();
194 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(2))));
195 +
}
196 +
197 +
#[test]
198 +
fn test_many_add() {
199 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
200 +
    let mut changes = Vec::new();
201 +
    for i in 0..200 {
202 +
        changes.push(KeyChanges::single_add(i, i));
203 +
    }
204 +
    keeper.apply(&changes).unwrap();
205 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(2))));
206 +
    assert_eq!(keeper.get(&100).ok(), Some(Some(Value::SINGLE(100))));
207 +
    assert_eq!(keeper.get(&201).ok(), Some(None));
208 +
}
209 +
210 +
#[test]
211 +
fn test_many_add_multiple_times() {
212 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
213 +
    let mut changes = Vec::new();
214 +
    for n in 0..8 {
215 +
        for i in 0..20 {
216 +
            changes.push(KeyChanges::single_add(i, i));
217 +
        }
218 +
        keeper.apply(&changes).unwrap();
219 +
        assert_eq!(keeper.get(&(n + 2)).ok(), Some(Some(Value::SINGLE(n + 2))));
220 +
    }
221 +
}
222 +
223 +
#[test]
224 +
fn test_single_add_remove() {
225 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
226 +
    let mut changes = Vec::new();
227 +
    changes.push(KeyChanges::single_add(1, 1));
228 +
    changes.push(KeyChanges::single_add(2, 2));
229 +
    changes.push(KeyChanges::single_add(3, 4));
230 +
    keeper.apply(&changes).unwrap();
231 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(2))));
232 +
233 +
    let mut changes = Vec::new();
234 +
    changes.push(KeyChanges::single_delete(1, Some(1)));
235 +
    changes.push(KeyChanges::single_delete(2, Some(2)));
236 +
    changes.push(KeyChanges::single_delete(3, Some(4)));
237 +
    keeper.apply(&changes).unwrap();
238 +
    assert_eq!(keeper.get(&2).ok(), Some(None));
239 +
}
240 +
241 +
#[test]
242 +
fn test_aggregate_add_remove() {
243 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
244 +
    let mut changes = Vec::new();
245 +
    changes.push(KeyChanges::new(
246 +
        2,
247 +
        vec![ValueChange::ADD(1), ValueChange::REMOVE(Some(1)), ValueChange::ADD(2)],
248 +
    ));
249 +
    keeper.apply(&changes).unwrap();
250 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(2))));
251 +
252 +
    let mut changes = Vec::new();
253 +
    changes.push(KeyChanges::new(
254 +
        2,
255 +
        vec![
256 +
            ValueChange::REMOVE(Some(2)),
257 +
            ValueChange::ADD(1),
258 +
            ValueChange::REMOVE(Some(1)),
259 +
        ],
260 +
    ));
261 +
    keeper.apply(&changes).unwrap();
262 +
    assert_eq!(keeper.get(&2).ok(), Some(None));
263 +
}
264 +
265 +
#[test]
266 +
fn test_group_replace_remove() {
267 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
268 +
    let mut changes = Vec::new();
269 +
    changes.push(KeyChanges::new(2, vec![ValueChange::ADD(1), ValueChange::ADD(2)]));
270 +
    keeper.apply(&changes).unwrap();
271 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(2))));
272 +
273 +
    let mut changes = Vec::new();
274 +
    changes.push(KeyChanges::new(2, vec![ValueChange::REMOVE(Some(2))]));
275 +
    keeper.apply(&changes).unwrap();
276 +
    assert_eq!(keeper.get(&2).ok(), Some(None));
277 +
}
278 +
279 +
#[test]
280 +
fn test_group_values_remove() {
281 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new_mode(ValueMode::CLUSTER);
282 +
    let mut changes = Vec::new();
283 +
    changes.push(KeyChanges::new(
284 +
        2,
285 +
        vec![ValueChange::ADD(1), ValueChange::ADD(2), ValueChange::ADD(3)],
286 +
    ));
287 +
    keeper.apply(&changes).unwrap();
288 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::CLUSTER(vec![1, 2, 3]))));
289 +
290 +
    let mut changes = Vec::new();
291 +
    changes.push(KeyChanges::new(
292 +
        2,
293 +
        vec![ValueChange::REMOVE(Some(1)), ValueChange::REMOVE(Some(2))],
294 +
    ));
295 +
    keeper.apply(&changes).unwrap();
296 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(3))));
297 +
}
298 +
299 +
#[test]
300 +
fn test_group_values_remove_no_order() {
301 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new_mode(ValueMode::CLUSTER);
302 +
    let mut changes = Vec::new();
303 +
    changes.push(KeyChanges::new(
304 +
        2,
305 +
        vec![ValueChange::ADD(3), ValueChange::ADD(1), ValueChange::ADD(2)],
306 +
    ));
307 +
    keeper.apply(&changes).unwrap();
308 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::CLUSTER(vec![3, 1, 2]))));
309 +
310 +
    let mut changes = Vec::new();
311 +
    changes.push(KeyChanges::new(
312 +
        2,
313 +
        vec![ValueChange::REMOVE(Some(1)), ValueChange::REMOVE(Some(2))],
314 +
    ));
315 +
    keeper.apply(&changes).unwrap();
316 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(3))));
317 +
}
318 +
319 +
#[test]
320 +
fn test_add_same_value_twice() {
321 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new_mode(ValueMode::CLUSTER);
322 +
    let mut changes = Vec::new();
323 +
    changes.push(KeyChanges::new(
324 +
        2,
325 +
        vec![ValueChange::ADD(1), ValueChange::ADD(2), ValueChange::ADD(1)],
326 +
    ));
327 +
328 +
    changes.push(KeyChanges::new(1, vec![ValueChange::ADD(1), ValueChange::ADD(1)]));
329 +
    keeper.apply(&changes).unwrap();
330 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::CLUSTER(vec![1, 2]))));
331 +
    assert_eq!(keeper.get(&1).ok(), Some(Some(Value::SINGLE(1))));
332 +
}
333 +
334 +
#[test]
335 +
fn test_add_to_esclusive() {
336 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new_mode(ValueMode::EXCLUSIVE);
337 +
    let mut changes = Vec::new();
338 +
    changes.push(KeyChanges::new(2, vec![ValueChange::ADD(1)]));
339 +
    keeper.apply(&changes).unwrap();
340 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(1))));
341 +
    let mut changes = Vec::new();
342 +
    changes.push(KeyChanges::new(2, vec![ValueChange::ADD(1)]));
343 +
344 +
    keeper.apply(&changes).unwrap();
345 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(1))));
346 +
    let mut changes = Vec::new();
347 +
    changes.push(KeyChanges::new(2, vec![ValueChange::ADD(2)]));
348 +
    assert!(match keeper.apply(&changes) {
349 +
        Err(PersyError::IndexDuplicateKey(ref idxname, ref keyname)) if (idxname == "test_index" && keyname == "2") => {
350 +
            true
351 +
        }
352 +
        _ => false,
353 +
    });
354 +
}
355 +
356 +
#[test]
357 +
fn test_group_key_remove() {
358 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new_mode(ValueMode::CLUSTER);
359 +
    let mut changes = Vec::new();
360 +
    changes.push(KeyChanges::new(2, vec![ValueChange::ADD(1), ValueChange::ADD(2)]));
361 +
    keeper.apply(&changes).unwrap();
362 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::CLUSTER(vec![1, 2]))));
363 +
364 +
    let mut changes = Vec::new();
365 +
    changes.push(KeyChanges::new(2, vec![ValueChange::REMOVE(None)]));
366 +
    keeper.apply(&changes).unwrap();
367 +
    assert_eq!(keeper.get(&2).ok(), Some(None));
368 +
}
369 +
370 +
#[test]
371 +
fn test_many_add_remove() {
372 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
373 +
    let mut changes = Vec::new();
374 +
    for i in 0..200 {
375 +
        changes.push(KeyChanges::single_add(i, i));
376 +
    }
377 +
    changes.sort_by_key(|k| k.k);
378 +
    keeper.apply(&changes).unwrap();
379 +
    print_tree(&mut keeper).unwrap();
380 +
    assert_eq!(keeper.get(&2).ok(), Some(Some(Value::SINGLE(2))));
381 +
    assert_eq!(keeper.get(&100).ok(), Some(Some(Value::SINGLE(100))));
382 +
    assert_eq!(keeper.get(&201).ok(), Some(None));
383 +
    let mut changes = Vec::new();
384 +
    for i in 0..200 {
385 +
        changes.push(KeyChanges::single_delete(i, Some(i)));
386 +
    }
387 +
    changes.sort_by_key(|k| k.k);
388 +
    keeper.apply(&changes).unwrap();
389 +
    print_tree(&mut keeper).unwrap();
390 +
    assert_eq!(keeper.get_root().ok(), Some(None));
391 +
    assert_eq!(keeper.get(&2).ok(), Some(None));
392 +
    assert_eq!(keeper.get(&100).ok(), Some(None));
393 +
}
394 +
395 +
#[test]
396 +
fn test_many_add_remove_multiple_times() {
397 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
398 +
    let mut changes = Vec::new();
399 +
    let mut rchanges = Vec::new();
400 +
    for n in 0..8 {
401 +
        for i in 0..20 {
402 +
            changes.push(KeyChanges::single_add(i, i));
403 +
            rchanges.push(KeyChanges::single_delete(i, Some(i)));
404 +
        }
405 +
        changes.sort_by_key(|k| k.k);
406 +
        keeper.apply(&changes).unwrap();
407 +
        assert_eq!(keeper.get(&(n + 2)).ok(), Some(Some(Value::SINGLE(n + 2))));
408 +
        rchanges.sort_by_key(|k| k.k);
409 +
        keeper.apply(&rchanges).unwrap();
410 +
        assert_eq!(keeper.get(&(n + 2)).ok(), Some(None));
411 +
    }
412 +
}
413 +
414 +
#[test]
415 +
fn test_iter_from() {
416 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
417 +
    let mut changes = Vec::new();
418 +
    for i in 0..50 {
419 +
        changes.push(KeyChanges::single_add(i, i));
420 +
    }
421 +
    keeper.apply(&changes).unwrap();
422 +
    print_tree(&mut keeper).unwrap();
423 +
    let mut iter = keeper.iter_from(Bound::Included(&5)).unwrap();
424 +
    let next = iter.iter.next();
425 +
426 +
    assert_eq!(5, next.unwrap().key);
427 +
    let next = iter.iter.next();
428 +
    assert_eq!(6, next.unwrap().key);
429 +
    let mut last_val = None;
430 +
    for v in iter.iter {
431 +
        last_val = Some(v);
432 +
    }
433 +
    let mut next_page = keeper
434 +
        .iter_from(Bound::Excluded(&last_val.clone().unwrap().key))
435 +
        .unwrap();
436 +
    let next = next_page.iter.next();
437 +
    assert_eq!(last_val.unwrap().key + 1, next.unwrap().key);
438 +
}
439 +
440 +
#[test]
441 +
fn test_iter() {
442 +
    let mut keeper = MockIndexKeeper::<u8, u8>::new();
443 +
    let mut changes = Vec::new();
444 +
    for i in 0..50 {
445 +
        changes.push(KeyChanges::single_add(i, i));
446 +
    }
447 +
    keeper.apply(&changes).unwrap();
448 +
    print_tree(&mut keeper).unwrap();
449 +
    let mut iter = keeper.iter_from(Bound::Unbounded).unwrap();
450 +
    let next = iter.iter.next();
451 +
452 +
    assert_eq!(0, next.unwrap().key);
453 +
    let mut last_val = None;
454 +
    for v in iter.iter {
455 +
        last_val = Some(v);
456 +
    }
457 +
    let mut next_page = keeper
458 +
        .iter_from(Bound::Excluded(&last_val.clone().unwrap().key))
459 +
        .unwrap();
460 +
    let next = next_page.iter.next();
461 +
    assert_eq!(last_val.unwrap().key + 1, next.unwrap().key);
462 +
    let mut last_val = None;
463 +
    for v in next_page.iter {
464 +
        last_val = Some(v);
465 +
    }
466 +
    assert_eq!(last_val.unwrap().key, 49);
467 +
    let mut next_page = keeper.iter_from(Bound::Excluded(&49)).unwrap();
468 +
    assert!(next_page.iter.next().is_none());
469 +
}
470 +
471 +
#[test]
472 +
fn test_a_lot_add_remove_multiple_times() {
473 +
    let mut keeper = MockIndexKeeper::<u32, u32>::new();
474 +
    let mut changes = Vec::new();
475 +
    let mut remove = Vec::new();
476 +
    for n in 1..30 {
477 +
        for i in 1..200 {
478 +
            changes.push(KeyChanges::single_add(i * n, i * n));
479 +
            if i % 2 == 0 {
480 +
                remove.push(KeyChanges::single_delete(i * n, Some(i * n)));
481 +
            }
482 +
        }
483 +
        changes.sort_by_key(|k| k.k);
484 +
        keeper.apply(&changes).unwrap();
485 +
        assert_eq!(keeper.get(&(2 * n)).ok(), Some(Some(Value::SINGLE(2 * n))));
486 +
        assert_eq!(keeper.get(&(100 * n)).ok(), Some(Some(Value::SINGLE(100 * n))));
487 +
        assert_eq!(keeper.get(&20001).ok(), Some(None));
488 +
        remove.sort_by_key(|k| k.k);
489 +
        keeper.apply(&remove).unwrap();
490 +
        assert_eq!(keeper.get(&(2 * n)).ok(), Some(None));
491 +
        assert_eq!(keeper.get(&(100 * n)).ok(), Some(None));
492 +
    }
493 +
}
494 +
495 +
#[test]
496 +
fn test_big_tree() {
497 +
    let mut keeper = MockIndexKeeper::<u32, u32>::new();
498 +
    for n in 1..20 {
499 +
        let mut changes = Vec::new();
500 +
        let mut remove = Vec::new();
501 +
        for i in 1..301 {
502 +
            changes.push(KeyChanges::single_add(i * n, i * n));
503 +
            if i % 2 == 0 {
504 +
                remove.push(KeyChanges::single_delete(i * n, Some(i * n)));
505 +
            }
506 +
        }
507 +
        keeper.apply(&changes).unwrap();
508 +
        assert_eq!(keeper.get(&(2 * n)).ok(), Some(Some(Value::SINGLE(2 * n))));
509 +
        assert_eq!(keeper.get(&(100 * n)).ok(), Some(Some(Value::SINGLE(100 * n))));
510 +
        assert_eq!(keeper.get(&20001).ok(), Some(None));
511 +
512 +
        keeper.apply(&remove).unwrap();
513 +
        assert_eq!(keeper.get(&(2 * n)).ok(), Some(None));
514 +
        assert_eq!(keeper.get(&(100 * n)).ok(), Some(None));
515 +
    }
516 +
}

@@ -14,8 +14,10 @@
Loading
14 14
use crate::index::{
15 15
    config::{IndexType, IndexTypeId, Indexes, ValueMode, INDEX_DATA_PREFIX, INDEX_META_PREFIX},
16 16
    keeper::{IndexKeeper, IndexRawIter},
17 -
    nodes::{PageIter, PageIterBack, Value},
18 -
    tree::Index,
17 +
    tree::{
18 +
        nodes::{PageIter, PageIterBack, Value},
19 +
        Index,
20 +
    },
19 21
};
20 22
use crate::transaction::{
21 23
    PreparedState, SyncMode, Transaction, TxRead,
@@ -503,10 +505,7 @@
Loading
503 505
        self.read_page_fn(match_id, page, |x| Vec::from(x))
504 506
    }
505 507
506 -
    fn read_page_fn<T, F>(&self, match_id: &RecRef, page: u64, f: F) -> PRes<Option<T>>
507 -
    where
508 -
        F: Fn(&[u8]) -> T,
509 -
    {
508 +
    fn read_page_fn<T>(&self, match_id: &RecRef, page: u64, f: fn(&[u8]) -> T) -> PRes<Option<T>> {
510 509
        if let Some(mut pg) = self.allocator.load_page_not_free(page)? {
511 510
            let (len, id) = PersyImpl::read_record_metadata(&mut pg);
512 511
            if id.page == match_id.page && id.pos == match_id.pos {
@@ -519,19 +518,16 @@
Loading
519 518
        }
520 519
    }
521 520
522 -
    pub fn read_tx_internal_fn<T, F>(
521 +
    pub fn read_tx_internal_fn<T>(
523 522
        &self,
524 523
        tx: &Transaction,
525 524
        segment_id: SegmentId,
526 525
        id: &RecRef,
527 -
        f: F,
528 -
    ) -> PRes<Option<(T, u16)>>
529 -
    where
530 -
        F: Fn(&[u8]) -> T,
531 -
    {
526 +
        f: fn(&[u8]) -> T,
527 +
    ) -> PRes<Option<(T, u16)>> {
532 528
        loop {
533 529
            if let Some((page, version, _)) = self.read_ref_segment(tx, segment_id, id)? {
534 -
                if let Some(record) = self.read_page_fn(id, page, &f)? {
530 +
                if let Some(record) = self.read_page_fn(id, page, f)? {
535 531
                    break Ok(Some((record, version)));
536 532
                }
537 533
            } else {
@@ -590,22 +586,19 @@
Loading
590 586
        self.read_snap_fn(segment, rec_ref, snapshot, |x| Vec::from(x))
591 587
    }
592 588
593 -
    pub fn read_snap_fn<T, F>(
589 +
    pub fn read_snap_fn<T>(
594 590
        &self,
595 591
        segment: SegmentId,
596 592
        rec_ref: &RecRef,
597 593
        snapshot: SnapshotId,
598 -
        f: F,
599 -
    ) -> PRes<Option<T>>
600 -
    where
601 -
        F: Fn(&[u8]) -> T,
602 -
    {
594 +
        f: fn(&[u8]) -> T,
595 +
    ) -> PRes<Option<T>> {
603 596
        let segment_id = segment;
604 597
        loop {
605 598
            if let Some(rec_vers) = self.snapshots.read(snapshot, rec_ref)? {
606 599
                match rec_vers.case {
607 600
                    EntryCase::Change(change) => {
608 -
                        if let Some(record) = self.read_page_fn(rec_ref, change.pos, &f)? {
601 +
                        if let Some(record) = self.read_page_fn(rec_ref, change.pos, f)? {
609 602
                            break Ok(Some(record));
610 603
                        }
611 604
                    }
@@ -614,7 +607,7 @@
Loading
614 607
                    }
615 608
                }
616 609
            } else if let Some((page, _)) = self.address.read(rec_ref, segment_id)? {
617 -
                if let Some(record) = self.read_page_fn(rec_ref, page, &f)? {
610 +
                if let Some(record) = self.read_page_fn(rec_ref, page, f)? {
618 611
                    break Ok(Some(record));
619 612
                }
620 613
            } else {

@@ -446,7 +446,7 @@
Loading
446 446
        let mut current = self.size.lock()?;
447 447
        let page = *current;
448 448
        *current += size;
449 -
        return Ok(page);
449 +
        Ok(page)
450 450
    }
451 451
    fn trim_if_possible(&self, page: u64, size: u64) -> PRes<bool> {
452 452
        let mut current = self.size.lock()?;

@@ -53,7 +53,7 @@
Loading
53 53
    error::{PRes, PersyError},
54 54
    id::{IndexId, PersyId, SegmentId, ToIndexId, ToSegmentId},
55 55
    index::config::{ByteVec, IndexType, IndexTypeId, ValueMode},
56 -
    index::nodes::Value,
56 +
    index::tree::nodes::Value,
57 57
    persy::{IndexInfo, RecoverStatus},
58 58
};
59 59
use crate::{

@@ -1,8 +1,10 @@
Loading
1 1
use crate::index::{
2 2
    config::{ByteVec, IndexOrd, IndexType, Indexes, ValueMode, WrapperType},
3 -
    nodes::{compare, Node, NodeRef, PageIter, PageIterBack, Value},
4 3
    serialization::{deserialize, serialize},
5 -
    tree::{IndexApply, KeyChanges, ValueChange as TreeValue},
4 +
    tree::{
5 +
        nodes::{compare, Node, NodeRef, PageIter, PageIterBack, Value},
6 +
        IndexApply, KeyChanges, ValueChange as TreeValue,
7 +
    },
6 8
};
7 9
use crate::{
8 10
    error::{PRes, PersyError},

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 9 files with coverage changes found.

Changes in src/index/tree.rs
+1
Loading file...
New file src/index/tree/tests.rs
New
Loading file...
Changes in src/index/tree/nodes.rs
+2
Loading file...
Changes in src/index/serialization.rs
+2
Loading file...
Changes in src/index/config.rs
+1
Loading file...
Changes in src/journal.rs
-1
+1
Loading file...
Changes in src/persy.rs
-2
Loading file...
Changes in src/config.rs
+4
Loading file...
Changes in src/transaction.rs
-4
+6
Loading file...
Files Coverage
src 0.07% 92.85%
tests 98.56%
Project Totals (30 files) 93.87%
Loading