MCPcopy Create free account
hub / github.com/douchuan/algorithm / get_dth

Function get_dth

src/strings/tst.rs:123–138  ·  view source on GitHub ↗

return subtrie corresponding to given key

(x: Option<NonNull<Node<T>>>, key: &str, d: usize)

Source from the content-addressed store, hash-verified

121
122// return subtrie corresponding to given key
123unsafe fn get_dth<T>(x: Option<NonNull<Node<T>>>, key: &str, d: usize) -> Option<NonNull<Node<T>>> {
124 x.and_then(|x| {
125 let c = common::util::byte_at(key, d);
126 match c.cmp(&x.as_ref().c) {
127 Ordering::Less => get_dth(x.as_ref().left(), key, d),
128 Ordering::Greater => get_dth(x.as_ref().right(), key, d),
129 Ordering::Equal => {
130 if d < key.len() - 1 {
131 get_dth(x.as_ref().mid(), key, d + 1)
132 } else {
133 Some(x)
134 }
135 }
136 }
137 })
138}
139
140unsafe fn put_dth<T>(
141 x: Option<NonNull<Node<T>>>,

Callers 2

getMethod · 0.70
keys_with_prefixMethod · 0.70

Calls 6

byte_atFunction · 0.85
midMethod · 0.80
cmpMethod · 0.45
leftMethod · 0.45
rightMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected