gitee.com/lh-her-team/common@v1.5.1/birdsnest/strategy.go (about)

     1  // Package birdsnest strategy
     2  package birdsnest
     3  
     4  // Strategy function
     5  type Strategy func(bn *BirdsNestImpl) error
     6  
     7  // LruStrategy Nest filter cycle elimination strategy
     8  func LruStrategy(bn *BirdsNestImpl) error {
     9  	i := seeNextIndex(bn.currentIndex, int(bn.config.Length+1))
    10  	bn.filters[i] = NewCuckooFilter(bn.config.Cuckoo)
    11  	bn.log.Debugf("filter %v is full, filter %v eliminate success", bn.currentIndex, i)
    12  	bn.currentIndex = i
    13  	return nil
    14  }
    15  
    16  // see next index and currentIndex reset
    17  func seeNextIndex(index, both int) int {
    18  	index++
    19  	return index % both
    20  }