mirror of
https://github.com/XRPLF/rippled.git
synced 2026-09-27 15:28:03 +00:00
refactor: Unify upperBound and lowerBound into boundHelper
The two functions were near duplicates: walk to the key, then look for the nearest leaf on one side. Only the scan direction, the comparison deciding a leaf qualifies, and whether to take the first or last leaf below the subtree differed, exactly the distinction `BelowDirection` already draws for `belowHelper`, so the pair collapse into one parameterised walk. Also drops the stale `// TODO: what to return here?` above `lowerBound`'s `return end()`: no predecessor is the correct answer for the smallest key, and the tests pin it. Existing coverage only exercised `boundHelper`'s inner-node branch, every test map had at least three items, so the root was always an inner node and the leaf branch at the top of the function was never reached with a real answer to give. Adds coverage for a single-item map, the smallest map that reaches that branch, and an empty map, where the scan must find nothing on every branch before falling through to `end()`. Fixes the single-item test's own comment, which claimed `root_` becomes a leaf, when in fact `root_` stays the inner node it was constructed with for any map built via `addItem`; only a single-item map synced from a peer (`addRootNode`) ever replaces `root_` with a leaf directly. The same comment also claimed the leaf branch settles every probe before `root_`'s inner-node scan could run, which only holds for a probe the leaf qualifies against: for the rest the leaf is popped and that scan is exactly what reaches `end()`. The test name said `leaf root` for the same reason, and now names the leaf below the root.
This commit is contained in:
@@ -592,6 +592,10 @@ private:
|
||||
SHAMapLeafNode*
|
||||
belowHelper(NodePathStack& stack, BelowDirection direction) const;
|
||||
|
||||
// helper function for upperBound and lowerBound
|
||||
ConstIterator
|
||||
boundHelper(uint256 const& id, BelowDirection direction) const;
|
||||
|
||||
// Simple descent
|
||||
// Get a child of the specified node
|
||||
SHAMapTreeNode*
|
||||
|
||||
Reference in New Issue
Block a user