@Override
	public short getNext(short key) {
        if ((key < 0) || (key >= size)) {
            throw new IndexOutOfBoundsException();
        }

        // compute leaf node.
        int nodeIndex = key + power2;


        // while we are not at the root, search upward until we find a right
        // sibling that is "on".
        while(nodeIndex != 1) {
            // see if we are odd (i.e. the right child)
            int odd = nodeIndex % 2;

            // if we are the left child see if my sibling on the right is on.
            // if so, then the next key must be in that subtree.
            if (odd == 0) {
                if (isBitSet(nodeIndex+1)) {
                    // we found a right sibling that is "on", set nodeIndex to
                    // that node.
                    nodeIndex++;
                    break;
                }
            }
            nodeIndex = nodeIndex/2;
        }

        // if we made it all the way up to the root node, then there is no key
        // greater than, so return -1;
        if (nodeIndex == 1) {
            return (short)-1;
        }

        // now that we found a right sibling that is "on",
        // follow the leftmost trail of "on" bits to an "on" leaf bit.  This bit
        // represents the next key in the set.
        while (nodeIndex < power2) {
            nodeIndex *= 2;
            // if the left child is not on, then the right child must be "on".
            if (!isBitSet(nodeIndex))  {
                nodeIndex++;
            }
        }
        short nextKey = (short)(nodeIndex-power2);
        if (nextKey >= size) {
            nextKey = -1;
        }
        return nextKey;
    }
finds the next key that is in the set that is greater than the given key.
@param key from which to search forward.
@return the next key greater than the given key or -1 if there is no key
greater than the given key.
@exception IndexOutOfBoundsException if the given key is not
in the range [0, size-1].
Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/BitTree.java