-
Notifications
You must be signed in to change notification settings - Fork 13.4k
BtreeMap range_search spruced up #68499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,10 @@ pub enum SearchResult<BorrowType, K, V, FoundType, GoDownType> { | |
GoDown(Handle<NodeRef<BorrowType, K, V, GoDownType>, marker::Edge>), | ||
} | ||
|
||
/// Looks up a given key in a (sub)tree headed by the given node, recursively. | ||
/// Returns a `Found` with the handle of the matching KV, if any. Otherwise, | ||
/// returns a `GoDown` with the handle of the possible leaf edge where the key | ||
/// belongs. | ||
pub fn search_tree<BorrowType, K, V, Q: ?Sized>( | ||
mut node: NodeRef<BorrowType, K, V, marker::LeafOrInternal>, | ||
key: &Q, | ||
|
@@ -32,6 +36,10 @@ where | |
} | ||
} | ||
|
||
/// Looks up a given key in a given node, without recursion. | ||
/// Returns a `Found` with the handle of the matching KV, if any. Otherwise, | ||
/// returns a `GoDown` with the handle of the edge where the key might be found. | ||
/// If the node is a leaf, a `GoDown` edge is not an actual edge but a possible edge. | ||
pub fn search_node<BorrowType, K, V, Type, Q: ?Sized>( | ||
node: NodeRef<BorrowType, K, V, Type>, | ||
key: &Q, | ||
|
@@ -50,8 +58,8 @@ where | |
/// or could exist, and whether it exists in the node itself. If it doesn't | ||
/// exist in the node itself, it may exist in the subtree with that index | ||
/// (if the node has subtrees). If the key doesn't exist in node or subtree, | ||
/// the returned index is the position or subtree to insert at. | ||
pub fn search_linear<BorrowType, K, V, Type, Q: ?Sized>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we move/copy the doc comment here onto search_range since that's the common "entry point" now? Doesn't have to be in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, though I couldn't find any other documentation describing a returned enum (other than Result or Option). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh, not sure how that's relevant? We rarely encounter returned enums in the wild, I think (though I'm sure now that I've said it I'll think of dozens of examples once I post this). If you're looking for a format or so to follow, I wouldn't worry that much about that. I'd be far more interested in just some docs pointing out what the variants mean; basically same as the docs here do wrt to false/true and the index, but applied to the enum. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found it hard to describe without mentioning the variant (or at least, the GoDown variant which is somewhat confusing). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentioning the variant is good (and indeed I would expect the docs to do so). |
||
/// the returned index is the position or subtree where the key belongs. | ||
fn search_linear<BorrowType, K, V, Type, Q: ?Sized>( | ||
node: &NodeRef<BorrowType, K, V, Type>, | ||
key: &Q, | ||
) -> (usize, bool) | ||
|
Uh oh!
There was an error while loading. Please reload this page.