h2/src/main/org/h2/mvstore/MVMap.java
/**
     * Add or update a key-value pair.
     *
     * @param p the page
     * @param writeVersion the write version
     * @param key the key (may not be null)
     * @param value the value (may not be null)
     * @return the old value, or null
     */
Add or update a key-value pair.
Add or update a key - value pair .
protected Object put(Page p, long writeVersion, Object key, Object value) {
        int index = p.binarySearch(key);
        if (p.isLeaf()) {
            if (index < 0) {
                index = -index - 1;
                p.insertLeaf(index, key, value);
                return null;
            }
            return p.setValue(index, value);
        }
        if (index < 0) {
            index = -index - 1;
        } else {
            index++;
        }
        Page c = copyOnWrite(p.getChildPage(index), writeVersion);
        if (c.getMemory() > store.getPageSplitSize() && c.getKeyCount() > 1) {
            int at = c.getKeyCount() / 2;
            Object k = c.getKey(at);
            Page split = c.split(at);
            p.setChild(index, split);
            p.setCounts(index, split);
            p.insertNode(index, k, c);
            return put(p, writeVersion, key, value);
        }
        p.setChild(index, c);
        Object result = put(c, writeVersion, key, value);
        p.setCounts(index, c);
        return result;
    }
protected Object put ( Page p , long writeVersion , Object key , Object value ) { int index = p . binarySearch ( key ) ; if ( p . isLeaf ( ) ) { if ( index < 0 ) { index = - index - 1 ; p . insertLeaf ( index , key , value ) ; return null ; } return p . setValue ( index , value ) ; } if ( index < 0 ) { index = - index - 1 ; } else { index ++ ; } Page c = copyOnWrite ( p . getChildPage ( index ) , writeVersion ) ; if ( c . getMemory ( ) > store . getPageSplitSize ( ) && c . getKeyCount ( ) > 1 ) { int at = c . getKeyCount ( ) / 2 ; Object k = c . getKey ( at ) ; Page split = c . split ( at ) ; p . setChild ( index , split ) ; p . setCounts ( index , split ) ; p . insertNode ( index , k , c ) ; return put ( p , writeVersion , key , value ) ; } p . setChild ( index , c ) ; Object result = put ( c , writeVersion , key , value ) ; p . setCounts ( index , c ) ; return result ; }
Add or update a key-value pair.
Add or update a key - value pair .
// p is a node // split on the way down // now we are not sure where to add