mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Merge 2faa3d0843dbbcc9610410333ed8ee609aa219ca into ed745a9acb0d1f2bf765e03d8ee4114d3032b73a
This commit is contained in:
commit
1f3dd8775d
@ -15,7 +15,7 @@ type LRUCache struct {
|
||||
func New(capacity int, preallocate bool) *LRUCache {
|
||||
var cache map[externalapi.DomainHash]interface{}
|
||||
if preallocate {
|
||||
cache = make(map[externalapi.DomainHash]interface{}, capacity+1)
|
||||
cache = make(map[externalapi.DomainHash]interface{}, capacity)
|
||||
} else {
|
||||
cache = make(map[externalapi.DomainHash]interface{})
|
||||
}
|
||||
@ -27,11 +27,10 @@ func New(capacity int, preallocate bool) *LRUCache {
|
||||
|
||||
// Add adds an entry to the LRUCache
|
||||
func (c *LRUCache) Add(key *externalapi.DomainHash, value interface{}) {
|
||||
c.cache[*key] = value
|
||||
|
||||
if len(c.cache) > c.capacity {
|
||||
if len(c.cache) >= c.capacity {
|
||||
c.evictRandom()
|
||||
}
|
||||
c.cache[*key] = value
|
||||
}
|
||||
|
||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
||||
|
@ -25,7 +25,7 @@ type LRUCache struct {
|
||||
func New(capacity int, preallocate bool) *LRUCache {
|
||||
var cache map[lruKey]*externalapi.BlockGHOSTDAGData
|
||||
if preallocate {
|
||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGData, capacity+1)
|
||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGData, capacity)
|
||||
} else {
|
||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGData)
|
||||
}
|
||||
@ -37,12 +37,12 @@ func New(capacity int, preallocate bool) *LRUCache {
|
||||
|
||||
// Add adds an entry to the LRUCache
|
||||
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, isTrustedData bool, value *externalapi.BlockGHOSTDAGData) {
|
||||
key := newKey(blockHash, isTrustedData)
|
||||
c.cache[key] = value
|
||||
|
||||
if len(c.cache) > c.capacity {
|
||||
if len(c.cache) >= c.capacity {
|
||||
c.evictRandom()
|
||||
}
|
||||
|
||||
key := newKey(blockHash, isTrustedData)
|
||||
c.cache[key] = value
|
||||
}
|
||||
|
||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
||||
|
@ -25,7 +25,7 @@ type LRUCache struct {
|
||||
func New(capacity int, preallocate bool) *LRUCache {
|
||||
var cache map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair
|
||||
if preallocate {
|
||||
cache = make(map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair, capacity+1)
|
||||
cache = make(map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair, capacity)
|
||||
} else {
|
||||
cache = make(map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair)
|
||||
}
|
||||
@ -37,12 +37,12 @@ func New(capacity int, preallocate bool) *LRUCache {
|
||||
|
||||
// Add adds an entry to the LRUCache
|
||||
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, windowSize int, value []*externalapi.BlockGHOSTDAGDataHashPair) {
|
||||
key := newKey(blockHash, windowSize)
|
||||
c.cache[key] = value
|
||||
|
||||
if len(c.cache) > c.capacity {
|
||||
if len(c.cache) >= c.capacity {
|
||||
c.evictRandom()
|
||||
}
|
||||
|
||||
key := newKey(blockHash, windowSize)
|
||||
c.cache[key] = value
|
||||
}
|
||||
|
||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
||||
|
@ -25,7 +25,7 @@ type LRUCache struct {
|
||||
func New(capacity int, preallocate bool) *LRUCache {
|
||||
var cache map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair
|
||||
if preallocate {
|
||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair, capacity+1)
|
||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair, capacity)
|
||||
} else {
|
||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair)
|
||||
}
|
||||
@ -37,12 +37,12 @@ func New(capacity int, preallocate bool) *LRUCache {
|
||||
|
||||
// Add adds an entry to the LRUCache
|
||||
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, index uint64, value *externalapi.BlockGHOSTDAGDataHashPair) {
|
||||
key := newKey(blockHash, index)
|
||||
c.cache[key] = value
|
||||
|
||||
if len(c.cache) > c.capacity {
|
||||
if len(c.cache) >= c.capacity {
|
||||
c.evictRandom()
|
||||
}
|
||||
|
||||
key := newKey(blockHash, index)
|
||||
c.cache[key] = value
|
||||
}
|
||||
|
||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
||||
|
@ -13,7 +13,7 @@ type LRUCache struct {
|
||||
func New(capacity int, preallocate bool) *LRUCache {
|
||||
var cache map[uint64]*externalapi.DomainHash
|
||||
if preallocate {
|
||||
cache = make(map[uint64]*externalapi.DomainHash, capacity+1)
|
||||
cache = make(map[uint64]*externalapi.DomainHash, capacity)
|
||||
} else {
|
||||
cache = make(map[uint64]*externalapi.DomainHash)
|
||||
}
|
||||
@ -25,11 +25,11 @@ func New(capacity int, preallocate bool) *LRUCache {
|
||||
|
||||
// Add adds an entry to the LRUCache
|
||||
func (c *LRUCache) Add(key uint64, value *externalapi.DomainHash) {
|
||||
c.cache[key] = value
|
||||
|
||||
if len(c.cache) > c.capacity {
|
||||
if len(c.cache) >= c.capacity {
|
||||
c.evictRandom()
|
||||
}
|
||||
|
||||
c.cache[key] = value
|
||||
}
|
||||
|
||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
||||
|
Loading…
x
Reference in New Issue
Block a user