[
https://issues.apache.org/jira/browse/LUCENE-10269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17451545#comment-17451545
]
Ignacio Vera commented on LUCENE-10269:
---------------------------------------
Currently to navigate the children of a node we do the following:
{code:java}
if (pointTree.moveToChild()) {
do {
// do something
} while (pointTree.moveToSibling());
pointTree.moveToParent();
}
{code}
What I would like to do is:
{code:java}
if (pointTree.moveToLastChild()) {
do {
// do something
} while (pointTree.moveToPreviousSibling());
pointTree.moveToParent();
}
{code}
I just realise, this can be achieved with the current interface, it is just not
very efficient. It will look like:
{code:java}
int numberChildren = moveToLastChild(pointTree);
if (numberChildren > 0) {
do {
// do something
} while (moveToPreviousSibling(pointTree, --numberChildren));
pointTree.moveToParent();
}
{code}
With the methods looking like:
{code:java}
private int moveToLastChild(PointTree pointTree) throws IOException {
int numChildren = 0;
if (pointTree.moveToChild()) {
do {
numChildren++;
} while (pointTree.moveToSibling());
}
return numChildren;
}
private boolean moveToPreviousSibling(PointTree pointTree, int siblingPos)
throws IOException {
if (siblingPos == 0) {
return false;
}
pointTree.moveToParent();
pointTree.moveToChild();
for (int i = 1; i < siblingPos; i++) {
pointTree.moveToSibling();
}
return true;
}
{code}
So I guess the question here is if we want to optimise this way of navigating
the tree?
> Add the ability to read KD trees from right to left
> ---------------------------------------------------
>
> Key: LUCENE-10269
> URL: https://issues.apache.org/jira/browse/LUCENE-10269
> Project: Lucene - Core
> Issue Type: Improvement
> Reporter: Ignacio Vera
> Priority: Major
>
> In LUCENE-9820 we exposed a programatic API to navigate Lucene Kd-trees. It
> is currently only possible to navigate those trees from left to right via the
> methods #moveToChild and #moveToSibling.
>
> In LUCENE-10262 we improve the Kd tree so we remove the constraint of having
> to read the tree always forward. This added the possibility to introduce an
> API to read the tree from right to left. This will allow for example to get
> the maximum value for a dimension stored in a kd-tree that contains deleted
> documents,
>
> The idea will be something like:
>
>
> {code:java}
> /**
> * Move to the first child node and return {@code true} upon success. Returns
> {@code false} for
> * leaf nodes and {@code true} otherwise.
> */
> boolean moveToFirstChild() throws IOException;
> /**
> * Move to the next sibling node and return {@code true} upon success.
> Returns {@code false} if
> * the current node is the last child.
> */
> boolean moveToNextSibling() throws IOException;
> /**
> * Move to the last child node and return {@code true} upon success. Returns
> {@code false} for
> * leaf nodes and {@code true} otherwise.
> */
> boolean moveToLastChild() throws IOException;
> /**
> * Move to the previous sibling node and return {@code true} upon success.
> Returns {@code false} if
> * the current node is the first child.
> */
> boolean moveToPreviousSibling() throws IOException;
> {code}
>
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]