1 use core
::borrow
::Borrow
;
2 use core
::cmp
::Ordering
;
4 use super::node
::{Handle, NodeRef, marker, ForceResult::*}
;
8 pub enum SearchResult
<BorrowType
, K
, V
, FoundType
, GoDownType
> {
9 Found(Handle
<NodeRef
<BorrowType
, K
, V
, FoundType
>, marker
::KV
>),
10 GoDown(Handle
<NodeRef
<BorrowType
, K
, V
, GoDownType
>, marker
::Edge
>)
13 pub fn search_tree
<BorrowType
, K
, V
, Q
: ?Sized
>(
14 mut node
: NodeRef
<BorrowType
, K
, V
, marker
::LeafOrInternal
>,
16 ) -> SearchResult
<BorrowType
, K
, V
, marker
::LeafOrInternal
, marker
::Leaf
>
17 where Q
: Ord
, K
: Borrow
<Q
> {
20 match search_node(node
, key
) {
21 Found(handle
) => return Found(handle
),
22 GoDown(handle
) => match handle
.force() {
23 Leaf(leaf
) => return GoDown(leaf
),
24 Internal(internal
) => {
25 node
= internal
.descend();
33 pub fn search_node
<BorrowType
, K
, V
, Type
, Q
: ?Sized
>(
34 node
: NodeRef
<BorrowType
, K
, V
, Type
>,
36 ) -> SearchResult
<BorrowType
, K
, V
, Type
, Type
>
37 where Q
: Ord
, K
: Borrow
<Q
> {
39 match search_linear(&node
, key
) {
41 Handle
::new_kv(node
, idx
)
43 (idx
, false) => SearchResult
::GoDown(
44 Handle
::new_edge(node
, idx
)
49 pub fn search_linear
<BorrowType
, K
, V
, Type
, Q
: ?Sized
>(
50 node
: &NodeRef
<BorrowType
, K
, V
, Type
>,
53 where Q
: Ord
, K
: Borrow
<Q
> {
55 for (i
, k
) in node
.keys().iter().enumerate() {
56 match key
.cmp(k
.borrow()) {
57 Ordering
::Greater
=> {}
,
58 Ordering
::Equal
=> return (i
, true),
59 Ordering
::Less
=> return (i
, false)
62 (node
.keys().len(), false)