a-foundation/src/main/java/com/ajjpj/afoundation/collection/immutable/AHashMap.java
private static<K,V> HashTrieMap<K,V> mergeLeafMaps(int hash0, AHashMap<K,V> elem0, int hash1, AHashMap<K,V> elem1, int level, int size, AEquality equality) {
        final int index0 = (hash0 >>> level) & 0x1f;
        final int index1 = (hash1 >>> level) & 0x1f;
        if(index0 != index1) {
            final int bitmap = (1 << index0) | (1 << index1);
            final AHashMap<K,V>[] elems = createArray(2);
            if(index0 < index1) {
                elems[0] = elem0;
                elems[1] = elem1;
            }
            else {
                elems[0] = elem1;
                elems[1] = elem0;
            }
            return new HashTrieMap<>(bitmap, elems, size, equality);
        }
        else {
            final AHashMap<K,V>[] elems = createArray(1);
            final int bitmap = (1 << index0);
            // try again, based on the
            elems[0] = mergeLeafMaps(hash0, elem0, hash1, elem1, level + LEVEL_INCREMENT, size, equality);
            return new HashTrieMap<>(bitmap, elems, size, equality);
        }
    }
private static<K,V> HashTrieMap<K,V> mergeLeafMaps(int hash0, AHashMap<K,V> elem0, int hash1, AHashMap<K,V> elem1, int level, int size, AEquality equality) {
        final int index0 = (hash0 >>> level) & 0x1f;
        final int index1 = (hash1 >>> level) & 0x1f;
        if(index0 != index1) {
            final int bitmap = (1 << index0) | (1 << index1);
            final AHashMap<K,V>[] elems = createArray(2);
            if(index0 < index1) {
                elems[0] = elem0;
                elems[1] = elem1;
            }
            else {
                elems[0] = elem1;
                elems[1] = elem0;
            }
            return new HashTrieMap<>(bitmap, elems, size, equality);
        }
        else {
            final AHashMap<K,V>[] elems = createArray(1);
            final int bitmap = (1 << index0);
            // try again, based on the
            elems[0] = mergeLeafMaps(hash0, elem0, hash1, elem1, level + LEVEL_INCREMENT, size, equality);
            return new HashTrieMap<>(bitmap, elems, size, equality);
        }
    }
private static < K , V > HashTrieMap < K , V > mergeLeafMaps ( int hash0 , AHashMap < K , V > elem0 , int hash1 , AHashMap < K , V > elem1 , int level , int size , AEquality equality ) { final int index0 = ( hash0 >>> level ) & 0x1f ; final int index1 = ( hash1 >>> level ) & 0x1f ; if ( index0 != index1 ) { final int bitmap = ( 1 << index0 ) | ( 1 << index1 ) ; final AHashMap < K , V > [ ] elems = createArray ( 2 ) ; if ( index0 < index1 ) { elems [ 0 ] = elem0 ; elems [ 1 ] = elem1 ; } else { elems [ 0 ] = elem1 ; elems [ 1 ] = elem0 ; } return new HashTrieMap <> ( bitmap , elems , size , equality ) ; } else { final AHashMap < K , V > [ ] elems = createArray ( 1 ) ; final int bitmap = ( 1 << index0 ) ; // try again, based on the elems [ 0 ] = mergeLeafMaps ( hash0 , elem0 , hash1 , elem1 , level + LEVEL_INCREMENT , size , equality ) ; return new HashTrieMap <> ( bitmap , elems , size , equality ) ; } }
very internal method. It assumes hash0 != hash1.
very internal method . It assumes hash0 ! = hash1 .