@ Override public void clear ( IntSet segments ) { IntSet extraSegments = null ; PrimitiveIterator . OfInt iter = segments . iterator ( ) ; // First try to just clear the respective maps while ( iter . hasNext ( ) ) { int segment = iter . nextInt ( ) ; ConcurrentMap < K , InternalCacheEntry < K , V > > map = maps . get ( segment ) ; if ( map != null ) { map . clear ( ) ; } else { // If we don't have a map for a segment we have to later go through the unowned segments and remove // those entries separately if ( extraSegments == null ) { extraSegments = IntSets . mutableEmptySet ( segments . size ( ) ) ; } extraSegments . set ( segment ) ; } } if ( extraSegments != null ) { IntSet finalExtraSegments = extraSegments ; nonOwnedEntries . keySet ( ) . removeIf ( k -> finalExtraSegments . contains ( getSegmentForKey ( k ) ) ) ; } }
Removes all entries that map to the given segments