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

        // find the leaf node for the given key.
        int nodeIndex = key + power2;

        // while we are not at the root, search upward until we find a left
        // sibling that is "on".
        while(nodeIndex != 1) {

            // check if we are a right node.
            int odd = nodeIndex % 2;

            // if we are the right child see if my sibling on the left is "on".
            // if so, then the previous key must be in that subtree.
            if (odd == 1) {
                if (isBitSet(nodeIndex-1)) {
                    nodeIndex--;
                    break;
                }
            }
            nodeIndex = nodeIndex/2;
        }
        // If we went all the way to the root then there is no previous key, return -1.
        if (nodeIndex == 1) {
            return (short)-1;
        }

        // follow the rightmost trail of "on" bits to an "on" leaf bit.  This bit
        // represents the previous key in the set.
        while (nodeIndex < power2) {
            nodeIndex *= 2;
            if (isBitSet(nodeIndex+1))  {
                nodeIndex++;
            }
        }
        return (short)(nodeIndex-power2);
    }
Finds the next key that is in the set that is less than the given key.
@param key the key to search before.
@return the next key less than the given key or -1 if there is no key
less 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