remove method

bool remove(
  1. Envelope itemEnv,
  2. Object item
)

Removes a single item from this subtree.

@param itemEnv the envelope containing the item @param item the item to remove @return true if the item was found and removed

Implementation

bool remove(Envelope itemEnv, Object item) {
  // use envelope to restrict nodes scanned
  if (!isSearchMatch(itemEnv)) return false;

  bool found = false;
  for (int i = 0; i < 4; i++) {
    if (subnode[i] != null) {
      found = subnode[i]!.remove(itemEnv, item);
      if (found) {
        // trim subtree if empty
        if (subnode[i]!.isPrunable()) subnode[i] = null;
        break;
      }
    }
  }
  // if item was found lower down, don't need to search for it here
  if (found) return found;
  // otherwise, try and remove the item from the list of items in this node
  found = items.remove(item);
  return found;
}