@Override
	public void put(short key) {

        if ((key < 0) || (key >= size)) {
            throw new IndexOutOfBoundsException();
        }

        // The first "power2" number of bits are used for internal tree nodes.  The
        // leaf nodes start at index "power2".
        int nodeIndex = power2+key;

        // set the leaf bit on to indicate that the key is in the set.
        // if the bit is already on (The key is already in the set), then just return.
        if (!setBit(nodeIndex)) {
            return;
        }

        // increment the number of keys in the set.
        numKeys++;

        // go up the tree setting each parent bit to "on"
        while(nodeIndex != 1) {
            // compute parent index.
            nodeIndex /= 2;
            // if any parent bit is already on, then all its parents are already on,
            // so were done.
            if (!setBit(nodeIndex)) {
                return;
            }
        }
    }
Adds a key to the set.
@param key to be added.
@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