public static < K , V > void traverseMaps ( final KeyMap < K , V > [ ] maps , final TraversalEvaluator < K , V > visitor , final long touchedTag ) throws Exception { // we need to work on the maps in descending size Arrays . sort ( maps , CapacityDescendingComparator . INSTANCE ) ; final int [ ] shifts = new int [ maps . length ] ; final int [ ] lowBitsMask = new int [ maps . length ] ; final int numSlots = maps [ 0 ] . table . length ; final int numTables = maps . length ; // figure out how much each hash table collapses the entries for ( int i = 0 ; i < numTables ; i ++ ) { shifts [ i ] = maps [ 0 ] . log2size - maps [ i ] . log2size ; lowBitsMask [ i ] = ( 1 << shifts [ i ] ) - 1 ; } // go over all slots (based on the largest hash table) for ( int pos = 0 ; pos < numSlots ; pos ++ ) { // for each slot, go over all tables, until the table does not have that slot any more // for tables where multiple slots collapse into one, we visit that one when we process the // latest of all slots that collapse to that one int mask ; for ( int rootTable = 0 ; rootTable < numTables && ( ( mask = lowBitsMask [ rootTable ] ) & pos ) == mask ; rootTable ++ ) { // use that table to gather keys and start collecting keys from the following tables // go over all entries of that slot in the table Entry < K , V > entry = maps [ rootTable ] . table [ pos >> shifts [ rootTable ] ] ; while ( entry != null ) { // take only entries that have not been collected as part of other tables if ( entry . touchedTag < touchedTag ) { entry . touchedTag = touchedTag ; final K key = entry . key ; final int hashCode = entry . hashCode ; visitor . startNewKey ( key ) ; visitor . nextValue ( entry . value ) ; addEntriesFromChain ( entry . next , visitor , key , touchedTag , hashCode ) ; // go over the other hash tables and collect their entries for the key for ( int followupTable = rootTable + 1 ; followupTable < numTables ; followupTable ++ ) { Entry < K , V > followupEntry = maps [ followupTable ] . table [ pos >> shifts [ followupTable ] ] ; if ( followupEntry != null ) { addEntriesFromChain ( followupEntry , visitor , key , touchedTag , hashCode ) ; } } visitor . keyDone ( ) ; } entry = entry . next ; } } } }
Performs a traversal about logical the multi - map that results from the union of the given maps . This method does not actually build a union of the map but traverses the hash maps together .