diff --git a/config.go b/config.go index c94d7be9..e8cce086 100644 --- a/config.go +++ b/config.go @@ -68,7 +68,7 @@ func DefaultConfig(eviction time.Duration) Config { // initialShardSize computes initial shard size func (c Config) initialShardSize() int { - return max(c.MaxEntriesInWindow/c.Shards, minimumEntriesInShard) + return max(min(c.MaxEntriesInWindow/c.Shards, c.maximumShardSize()), minimumEntriesInShard) } // maximumShardSize computes maximum shard size diff --git a/utils.go b/utils.go index ca1df79b..eb4420d3 100644 --- a/utils.go +++ b/utils.go @@ -7,6 +7,13 @@ func max(a, b int) int { return b } +func min(a, b int) int { + if a < b { + return a + } + return b +} + func convertMBToBytes(value int) int { return value * 1024 * 1024 }