| 1 | pub mod builderrust-analyzer cargo yada 0.5.1 builder/; |
| 2 | pub mod unitrust-analyzer cargo yada 0.5.1 unit/; |
| 3 | |
| 4 | use craterust-analyzer cargo yada 0.5.1 crate/::unitrust-analyzer cargo yada 0.5.1 unit/::{Unitrust-analyzer cargo yada 0.5.1 unit/Unit#, UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID#, UNIT_SIZErust-analyzer cargo yada 0.5.1 unit/UNIT_SIZE.}; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#; |
| 7 | |
| 8 | /// A double array trie. |
| 9 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 10 | pub struct DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#<T>(pub T) |
| 11 | where |
| 12 | T: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = [u8]>; |
| 13 | |
| 14 | impl<T> DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#<T> |
| 15 | where |
| 16 | T: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = [u8]>, |
| 17 | { |
| 18 | /// Creates a new `DoubleArray` with a byte slice. |
| 19 | pub fn newrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]new().(bytes: T) -> Selfrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`] { |
| 20 | Selfrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`] { 0rust-analyzer cargo yada 0.5.1 DoubleArray#0.: bytes } |
| 21 | } |
| 22 | |
| 23 | /// Finds a value associated with a `key`. |
| 24 | pub fn exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().<K>(&self, key: K) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u32> |
| 25 | where |
| 26 | K: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>, |
| 27 | { |
| 28 | self.exact_match_search_bytesrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search_bytes().(key.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()) |
| 29 | } |
| 30 | |
| 31 | fn exact_match_search_bytesrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search_bytes().(&self, key: &[u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u32> { |
| 32 | // traverse from root node |
| 33 | let mut node_pos = 0 as UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID#; |
| 34 | let mut unit = self.get_unitrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]get_unit().(node_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 35 | |
| 36 | for &c in key.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(key.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) { |
| 37 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().unit.is_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]is_leaf().()); |
| 38 | assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(c, 0); // assumes characters don't have NULL ('\0') |
| 39 | |
| 40 | // try to traverse node |
| 41 | node_pos = (unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().node_pos as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().c as u32) as UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID#; |
| 42 | unit = self.get_unitrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]get_unit().(node_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 43 | |
| 44 | if unit.labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().c as u32 { |
| 45 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().unit.has_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]has_leaf().() { |
| 50 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 51 | } |
| 52 | |
| 53 | // traverse node by NULL ('\0') |
| 54 | let node_pos = (unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().node_pos as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().0u32) as UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID#; |
| 55 | unit = self.get_unitrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]get_unit().(node_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 56 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(unit.is_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]is_leaf().()); |
| 57 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(unit.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().() <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). (1 << 31)); |
| 58 | |
| 59 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unit.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().()) |
| 60 | } |
| 61 | |
| 62 | /// Finds all values and it's key length which have a common prefix with a `key`. |
| 63 | pub fn common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().<'b, K>( |
| 64 | &'b self, |
| 65 | key: &'b K, |
| 66 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (u32, usize)> + 'b |
| 67 | where |
| 68 | K: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>, |
| 69 | K: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 70 | { |
| 71 | self.common_prefix_search_bytesrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search_bytes().(key.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()) |
| 72 | } |
| 73 | |
| 74 | fn common_prefix_search_bytesrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search_bytes().<'b>( |
| 75 | &'b self, |
| 76 | key: &'b [u8], |
| 77 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (u32, usize)> + 'b { |
| 78 | CommonPrefixSearchrust-analyzer cargo yada 0.5.1 CommonPrefixSearch# { |
| 79 | keyrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key., |
| 80 | double_arrayrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#double_array.: self, |
| 81 | unit_idrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#unit_id.: 0, |
| 82 | key_posrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key_pos.: 0, |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | #[inline(always)] |
| 87 | fn get_unitrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]get_unit().(&self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Unitrust-analyzer cargo yada 0.5.1 unit/Unit#> { |
| 88 | let b = unsafe { |
| 89 | // This unsafe method call does not lead unexpected transitions |
| 90 | // when a double array was built properly. |
| 91 | self.0rust-analyzer cargo yada 0.5.1 DoubleArray#0. |
| 92 | .get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().UNIT_SIZErust-analyzer cargo yada 0.5.1 unit/UNIT_SIZE...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().UNIT_SIZErust-analyzer cargo yada 0.5.1 unit/UNIT_SIZE.) |
| 93 | }; |
| 94 | match b.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().() { |
| 95 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::from_u32rust-analyzer cargo yada 0.5.1 unit/impl#[Unit]from_u32().(u32::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_le_bytes().(bytes))), |
| 96 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /// An iterator that finds all values with a common prefix. |
| 102 | pub struct CommonPrefixSearchrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#<'k, 'd, T> |
| 103 | where |
| 104 | T: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = [u8]>, |
| 105 | { |
| 106 | keyrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key.: &'k [u8], |
| 107 | double_arrayrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#double_array.: &'d DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#<T>, |
| 108 | unit_idrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#unit_id.: UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID#, |
| 109 | key_posrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key_pos.: usize, |
| 110 | } |
| 111 | |
| 112 | impl<T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for CommonPrefixSearchrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#<'_, '_, T> |
| 113 | where |
| 114 | T: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = [u8]>, |
| 115 | { |
| 116 | type Itemrust-analyzer cargo yada 0.5.1 impl#[`CommonPrefixSearch<'_, '_, T>`][Iterator]Item# = (u32, usize); |
| 117 | |
| 118 | #[inline(always)] |
| 119 | fn nextrust-analyzer cargo yada 0.5.1 impl#[`CommonPrefixSearch<'_, '_, T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo yada 0.5.1 impl#[`CommonPrefixSearch<'_, '_, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 120 | while self.key_posrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.keyrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 121 | let unit = self.double_arrayrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#double_array..get_unitrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]get_unit().(self.unit_idrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#unit_id.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 122 | |
| 123 | let c = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.keyrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.key_posrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key_pos.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 124 | self.key_posrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key_pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 125 | |
| 126 | self.unit_idrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#unit_id. = (unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().self.unit_idrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#unit_id. as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().c as u32) as UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID#; |
| 127 | let unit = self.double_arrayrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#double_array..get_unitrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]get_unit().(self.unit_idrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#unit_id.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 128 | if unit.labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().c as u32 { |
| 129 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 130 | } |
| 131 | if unit.has_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]has_leaf().() { |
| 132 | let leaf_pos = unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitXor<Self>`]bitxor().self.unit_idrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#unit_id. as u32; |
| 133 | let leaf_unit = self.double_arrayrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#double_array..get_unitrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]get_unit().(leaf_pos as UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 134 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((leaf_unit.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().(), self.key_posrust-analyzer cargo yada 0.5.1 CommonPrefixSearch#key_pos.)); |
| 135 | } |
| 136 | } |
| 137 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | #[cfg(test)] |
| 142 | mod testsrust-analyzer cargo yada 0.5.1 tests/ { |
| 143 | use craterust-analyzer cargo yada 0.5.1 crate/::builderrust-analyzer cargo yada 0.5.1 builder/::DoubleArrayBuilderrust-analyzer cargo yada 0.5.1 builder/DoubleArrayBuilder#; |
| 144 | use craterust-analyzer cargo yada 0.5.1 crate/::DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#; |
| 145 | |
| 146 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 147 | fn test_build_searchrust-analyzer cargo yada 0.5.1 tests/test_build_search().() { |
| 148 | let keyset = &[ |
| 149 | ("a".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 0), |
| 150 | ("ab".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 1), |
| 151 | ("aba".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 2), |
| 152 | ("ac".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 3), |
| 153 | ("acb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 4), |
| 154 | ("acc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 5), |
| 155 | ("ad".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 6), |
| 156 | ("ba".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 7), |
| 157 | ("bb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 8), |
| 158 | ("bc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 9), |
| 159 | ("c".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 10), |
| 160 | ("caa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 11), |
| 161 | ]; |
| 162 | |
| 163 | let da_bytes = DoubleArrayBuilderrust-analyzer cargo yada 0.5.1 builder/DoubleArrayBuilder#::buildrust-analyzer cargo yada 0.5.1 builder/impl#[DoubleArrayBuilder]build().(keyset); |
| 164 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(da_bytes.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 165 | |
| 166 | let da = DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#::newrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]new().(da_bytes.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 167 | |
| 168 | for (key, value) in keyset { |
| 169 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().(key), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value as u32)); |
| 170 | } |
| 171 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("aa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 172 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("abc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 173 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("b".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 174 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("ca".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 175 | |
| 176 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 177 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("a".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 178 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1)] |
| 179 | ); |
| 180 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 181 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("aa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 182 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1)] |
| 183 | ); |
| 184 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 185 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("abbb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 186 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 187 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1), (1, 2)] |
| 188 | ); |
| 189 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 190 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("abaa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 191 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 192 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1), (1, 2), (2, 3)] |
| 193 | ); |
| 194 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 195 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("caa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 196 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 197 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(10, 1), (11, 3)] |
| 198 | ); |
| 199 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 200 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("d".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 201 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![] |
| 202 | ); |
| 203 | } |
| 204 | |
| 205 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 206 | fn test_exact_match_search_corner_caserust-analyzer cargo yada 0.5.1 tests/test_exact_match_search_corner_case().() { |
| 207 | // A corner case of `exact_match_search()`. |
| 208 | // See https://github.com/takuyaa/yada/pull/28 for more details. |
| 209 | let keyset = &[ |
| 210 | ("a".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 97), |
| 211 | ("ab".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 1), |
| 212 | ("de".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 2), |
| 213 | ]; |
| 214 | |
| 215 | let da_bytes = DoubleArrayBuilderrust-analyzer cargo yada 0.5.1 builder/DoubleArrayBuilder#::buildrust-analyzer cargo yada 0.5.1 builder/impl#[DoubleArrayBuilder]build().(keyset); |
| 216 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(da_bytes.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 217 | |
| 218 | let da = DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#::newrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]new().(da_bytes.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 219 | |
| 220 | for (key, value) in keyset { |
| 221 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().(key), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value as u32)); |
| 222 | } |
| 223 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("dasss"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 224 | } |
| 225 | |
| 226 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 227 | fn test_clone_and_searchrust-analyzer cargo yada 0.5.1 tests/test_clone_and_search().() { |
| 228 | let keyset = &[ |
| 229 | ("a".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 0), |
| 230 | ("ab".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 1), |
| 231 | ("aba".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 2), |
| 232 | ("ac".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 3), |
| 233 | ("acb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 4), |
| 234 | ("acc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 5), |
| 235 | ("ad".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 6), |
| 236 | ("ba".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 7), |
| 237 | ("bb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 8), |
| 238 | ("bc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 9), |
| 239 | ("c".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 10), |
| 240 | ("caa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 11), |
| 241 | ]; |
| 242 | |
| 243 | let da_bytes = DoubleArrayBuilderrust-analyzer cargo yada 0.5.1 builder/DoubleArrayBuilder#::buildrust-analyzer cargo yada 0.5.1 builder/impl#[DoubleArrayBuilder]build().(keyset); |
| 244 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(da_bytes.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 245 | |
| 246 | let da_orig = DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#::newrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]new().(da_bytes.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 247 | let da = da_orig.clonerust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`][Clone]clone().(); |
| 248 | |
| 249 | for (key, value) in keyset { |
| 250 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().(key), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value as u32)); |
| 251 | } |
| 252 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("aa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 253 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("abc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 254 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("b".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 255 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("ca".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 256 | |
| 257 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 258 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("a".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 259 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1)] |
| 260 | ); |
| 261 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 262 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("aa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 263 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1)] |
| 264 | ); |
| 265 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 266 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("abbb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 267 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 268 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1), (1, 2)] |
| 269 | ); |
| 270 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 271 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("abaa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 272 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 273 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1), (1, 2), (2, 3)] |
| 274 | ); |
| 275 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 276 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("caa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 277 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 278 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(10, 1), (11, 3)] |
| 279 | ); |
| 280 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 281 | da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("d".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 282 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![] |
| 283 | ); |
| 284 | } |
| 285 | } |