Is invoked on the leaf deletion only.

@param left  left page.
@param right right page.
@return true if the left page ought to be merged with the right one.
169222
public boolean needMerge(@NotNull final BasePage left, @NotNull final BasePage right) {
        final int leftSize = left.getSize();
        final int rightSize = right.getSize();
        return leftSize == 0 || rightSize == 0 ||
            leftSize + rightSize <= (((isDupTree(left) ? getDupPageMaxSize() : getPageMaxSize()) * 7) >> 3);
    }
610065
public static boolean tryMergeBlock(Node block, boolean alwaysMerge) {
    checkState(block.isBlock());
    Node parent = block.getParent();
    boolean canMerge = alwaysMerge || canMergeBlock(block);
    // Try to remove the block if its parent is a block/script or if its
    // parent is label and it has exactly one child.
    if (isStatementBlock(parent) && canMerge) {
      Node previous = block;
      while (block.hasChildren()) {
        Node child = block.removeFirstChild();
        parent.addChildAfter(child, previous);
        previous = child;
      }
      parent.removeChild(block);
      return true;
    } else {
      return false;
    }
  }
753968
final protected AbstractIndexPage getNextLeafPage(AbstractIndexPage indexPage) {
		int pos = getPagePosition(indexPage);
		if (pos < getNKeys()) {
			AbstractIndexPage page = getPageByPos(pos+1);
			return page.getFirstLeafPage();
		}
		if (getParent() == null) {
			return null;
		}
		//TODO we really should return the last leaf page of the previous inner page.
		//But if they get merged, then we have to shift minimal values, which is
		//complicated. For now we ignore this case, hoping that it doesn't matter much.
		return null;
	}
120999
public Diff compare(CtElement left, CtElement right) {
		final SpoonGumTreeBuilder scanner = new SpoonGumTreeBuilder();
		return new DiffImpl(scanner.getTreeContext(), scanner.getTree(left), scanner.getTree(right));
	}
154376
private Boolean compareValues(Session session, Object[] left,
                                  Object[] right) {

        int     result  = 0;
        boolean hasNull = false;

        if (left == null || right == null) {
            return null;
        }

        Object[] leftList  = left;
        Object[] rightList = right;

        for (int i = 0; i < nodes[LEFT].nodes.length; i++) {
            if (leftList[i] == null) {
                if (opType == OpTypes.MATCH_PARTIAL
                        || opType == OpTypes.MATCH_UNIQUE_PARTIAL) {
                    continue;
                }

                hasNull = true;
            }

            if (rightList[i] == null) {
                hasNull = true;
            }

            Object leftValue  = leftList[i];
            Object rightValue = rightList[i];
            Type[] types      = nodes[LEFT].nodeDataTypes;

            result = types[i].compare(leftValue, rightValue);

            if (result != 0) {
                break;
            }
        }

        switch (opType) {

            case OpTypes.MATCH_SIMPLE :
            case OpTypes.MATCH_UNIQUE_SIMPLE :
            case OpTypes.MATCH_PARTIAL :
            case OpTypes.MATCH_UNIQUE_PARTIAL :
            case OpTypes.MATCH_FULL :
            case OpTypes.MATCH_UNIQUE_FULL :
            case OpTypes.NOT_DISTINCT :
                return result == 0 ? Boolean.TRUE
                                   : Boolean.FALSE;

            case OpTypes.IN :
            case OpTypes.EQUAL :
                if (hasNull) {
                    return null;
                }

                return result == 0 ? Boolean.TRUE
                                   : Boolean.FALSE;

            case OpTypes.NOT_EQUAL :
                if (hasNull) {
                    return null;
                }

                return result != 0 ? Boolean.TRUE
                                   : Boolean.FALSE;

            case OpTypes.GREATER :
                if (hasNull) {
                    return null;
                }

                return result > 0 ? Boolean.TRUE
                                  : Boolean.FALSE;

            case OpTypes.GREATER_EQUAL :
                if (hasNull) {
                    return null;
                }

                return result >= 0 ? Boolean.TRUE
                                   : Boolean.FALSE;

            case OpTypes.SMALLER_EQUAL :
                if (hasNull) {
                    return null;
                }

                return result <= 0 ? Boolean.TRUE
                                   : Boolean.FALSE;

            case OpTypes.SMALLER :
                if (hasNull) {
                    return null;
                }

                return result < 0 ? Boolean.TRUE
                                  : Boolean.FALSE;

            default :
                throw Error.runtimeError(ErrorCode.U_S0500, "Expression");
        }
    }
730012
def delete_node(self, root, key):
        
        if not root: return None

        if root.val == key:
            if root.left:
                # Find the right most leaf of the left sub-tree
                left_right_most = root.left
                while left_right_most.right:
                    left_right_most = left_right_most.right
                # Attach right child to the right of that leaf
                left_right_most.right = root.right
                # Return left child instead of root, a.k.a delete root
                return root.left
            else:
                return root.right
        # If left or right child got deleted, the returned root is the child of the deleted node.
        elif root.val > key:
            root.left = self.deleteNode(root.left, key)
        else:
            root.right = self.deleteNode(root.right, key)
        return root
1231448
public boolean canEdit(Page page) {
        List<String> permTypes = new ArrayList<String>();
        permTypes.add(SpacePermission.CREATEEDIT_PAGE_PERMISSION);
        return getSpacePermissionManager().hasPermissionForSpace(getRemoteUser(), permTypes, page.getSpace());
    }
604443
private void processModifiedPage(PageModificationContext context) {
        PageWrapper page = context.getPageWrapper();
        boolean emptyPage = page.getPage().getCount() == 0;
        ByteArraySegment pageKey = page.getPageKey();
        if (emptyPage && page.getParent() != null) {
            // This page is empty. Remove it from the PageCollection (so we don't write it back to our data source)
            // and remember its Page Key so we can delete its pointer from its parent page.
            context.getPageCollection().remove(page);
            context.setDeletedPageKey(pageKey);
        } else {
            // This page needs to be kept around.
            if (emptyPage && page.getPage().getConfig().isIndexPage()) {
                // We have an empty Index Root Page. We must convert this to a Leaf Page before moving on.
                page.setPage(createEmptyLeafPage());
            }

            // Assign a new offset to the page and record its new Page Pointer.
            context.pageCollection.complete(page);
            page.setMinOffset(calculateMinOffset(page));
            context.updatePagePointer(new PagePointer(pageKey, page.getOffset(), page.getPage().getLength(), page.getMinOffset()));
        }
    }
395892
public void mergeWith(OptionalBoolean other) {
		if (state == other.state) {
			// no change in state
		} else if (state == State.UNSET) {
			state = other.state;
		} else if (other.state == State.UNSET) {
			// no change in state
		} else {
			state = State.CONFLICTING;
		}
	}
72583
public function removeNodes($left, $right, $root=null)
    {
        $hasManyRoots = $this->getConfiguration()->hasManyRoots();

        $removed = array();
        foreach($this->wrappers as $oid => $wrapper)
        {
            if(!$hasManyRoots || ($wrapper->getRootValue() == $root))
            {
                if($wrapper->getLeftValue() >= $left && $wrapper->getRightValue() <= $right)
                {
                    $removed[$oid] = $wrapper;
                }
            }
        }

        foreach($removed as $key => $wrapper)
        {
            unset($this->wrappers[$key]);
            $wrapper->setLeftValue(0);
            $wrapper->setRightValue(0);
            if($hasManyRoots)
            {
                $wrapper->setRootValue(0);
            }
            $this->getEntityManager()->detach($wrapper->getNode());
        }
    }
149836
public boolean isLeafNode()
  {
    boolean leaf = false;
    if ( (_leftChild  == null) &&
         (_rightChild == null) )
      leaf = true;
    return leaf;
  }
1336024
public boolean lessThan(Object left, Object right) {
    if ((left == right) || (left == null) || (right == null)) {
      return false;
    }
    else {
      return compare(left, right, "<") < 0;
    }

  }
90651
private LeftJoinNode updateRightNodesAndLJ(LeftJoinNode leftJoinNode,
                                               DataNodeAndSubstitution rightComponent,
                                               Optional<ImmutableExpression> newLJCondition,
                                               Optional<DataNode> proposedRightDataNode,
                                               QueryTreeComponent treeComponent) {
        rightComponent.constructionNode
                .ifPresent(n -> treeComponent.replaceNodeByChild(n, Optional.empty()));
        rightComponent.filterNode
                .ifPresent(n -> treeComponent.replaceNodeByChild(n, Optional.empty()));
        proposedRightDataNode
                .ifPresent(n -> treeComponent.replaceNode(rightComponent.dataNode, n));
        LeftJoinNode newLeftJoinNode = leftJoinNode.changeOptionalFilterCondition(newLJCondition);
        treeComponent.replaceNode(leftJoinNode, newLeftJoinNode);

        return newLeftJoinNode;
    }
1168665
public boolean canMerge(Space other) {
		if (!hasJoinedEdge(other)) {
			return false;
		}
		
		if ((x == other.x) && (width == other.width)) {
			return true;
		}
		if ((y == other.y) && (height == other.height)) {
			return true;
		}
		
		return false;
	}
152444
boolean compareAndSetLeaf(Page oldPage, Page page)
  {
    if (oldPage == page) {
      return true;
    }
    
    int pid = (int) page.getId();
    
    updateTailPid(pid);
    
    if (oldPage instanceof PageLeafImpl && page instanceof PageLeafImpl) {
      PageLeafImpl oldLeaf = (PageLeafImpl) oldPage;
      PageLeafImpl newLeaf = (PageLeafImpl) page;
      
      if (BlockTree.compareKey(oldLeaf.getMaxKey(), newLeaf.getMaxKey(), 0) < 0) {
        System.err.println(" DERP: " + oldPage + " " + page);
        Thread.dumpStack();
        /*
        throw new IllegalStateException("DERP: old=" + oldPage + " " + page
                                        + " old-dirt:" + oldPage.isDirty());
                                        */
      }
    }
    
    boolean result = _pages.compareAndSet(pid, oldPage, page);
    
    return result;
  }
522551
public void add(final LeftTupleSinkNode node) {
        if ( this.firstNode == null ) {
            this.firstNode = node;
            this.lastNode = node;;
        } else {
            this.lastNode.setNextLeftTupleSinkNode( node );
            node.setPreviousLeftTupleSinkNode( this.lastNode );
            this.lastNode = node;
        }
        this.size++;
    }
1266627
private void fixDocumentElements(final Page page) {

		final NodeList heads = page.getElementsByTagName("head");
		if (heads.getLength() > 1) {

			final Node head1   = heads.item(0);
			final Node head2   = heads.item(1);
			final Node parent  = head1.getParentNode();

			final boolean h1 = head1.hasChildNodes();
			final boolean h2 = head2.hasChildNodes();

			if (h1 && h2) {

				// merge
				for (Node child = head2.getFirstChild(); child != null; child = child.getNextSibling()) {

					head2.removeChild(child);
					head1.appendChild(child);
				}

				parent.removeChild(head2);

			} else if (h1 && !h2) {

				// remove head2
				parent.removeChild(head2);

			} else if (!h1 && h2) {

				// remove head1
				parent.removeChild(head1);

			} else {

				// remove first, doesn't matter
				parent.removeChild(head1);
			}
		}
	}