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
use crate::prelude::*;
impl FieldAddress for u128 {
fn root() -> Self {
17
}
#[inline]
fn child(&self, number: u64) -> Self {
profile_method!(child);
self.wrapping_mul(486_187_739).wrapping_add(number as u128)
}
#[inline]
fn unordered(&self) -> (Self, Self) {
(Self::root(), *self)
}
}
#[cfg(test)]
mod test {
use super::FieldAddress;
use std::collections::HashSet;
fn recurse(field_address: u128, depth: usize, length: usize, collector: &mut HashSet<u128>) {
for i in 0..6 {
let child = field_address.child(i);
assert!(collector.insert(child));
if depth != 0 {
recurse(child, depth - 1, length, collector);
}
}
for i in 0..(length * depth * depth) {
let child = field_address.child((i as u64) + 6);
assert!(collector.insert(child));
}
}
#[test]
fn no_collisions_for_common_prototypes_64() {
let mut collector = HashSet::new();
let root = u128::root();
collector.insert(root);
recurse(root, 4, 50, &mut collector);
assert_eq!(30831, collector.len());
}
}