public short put ( String value ) { // Do we already have this value? if ( dataMap . containsKey ( value ) ) { dictionaryHit ++ ; return dataMap . get ( value ) ; } // Are we filled up? if ( next == MAX_SIZE ) { dictionaryMiss ++ ; return - 1 ; } // Should we add values without actual repetitions? if ( minRepetitions == 0 ) { data [ next ] = value ; dataMap . put ( value , next ) ; dirty = true ; dictionaryHit ++ ; return next ++ ; } // Have we seen this value before? if ( slidingWindow . containsKey ( value ) ) { int count = slidingWindow . get ( value ) + 1 ; // Does it satisfy the minimum repetition count? if ( count > minRepetitions ) { slidingWindow . remove ( value ) ; data [ next ] = value ; dataMap . put ( value , next ) ; dirty = true ; dictionaryHit ++ ; return next ++ ; } else { slidingWindow . put ( value , count ) ; } } else { // Add this new value to the map slidingWindow . put ( value , 1 ) ; } dictionaryMiss ++ ; return - 1 ; }
Add a new value to the dictionary if we have seen it a certain number of times within the current sliding window . If not return - 1 and mark that we saw it . If the value is already in the dictionary just return the lookup position .