mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +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 {
|
func New(capacity int, preallocate bool) *LRUCache {
|
||||||
var cache map[externalapi.DomainHash]interface{}
|
var cache map[externalapi.DomainHash]interface{}
|
||||||
if preallocate {
|
if preallocate {
|
||||||
cache = make(map[externalapi.DomainHash]interface{}, capacity+1)
|
cache = make(map[externalapi.DomainHash]interface{}, capacity)
|
||||||
} else {
|
} else {
|
||||||
cache = make(map[externalapi.DomainHash]interface{})
|
cache = make(map[externalapi.DomainHash]interface{})
|
||||||
}
|
}
|
||||||
@ -27,11 +27,10 @@ func New(capacity int, preallocate bool) *LRUCache {
|
|||||||
|
|
||||||
// Add adds an entry to the LRUCache
|
// Add adds an entry to the LRUCache
|
||||||
func (c *LRUCache) Add(key *externalapi.DomainHash, value interface{}) {
|
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.evictRandom()
|
||||||
}
|
}
|
||||||
|
c.cache[*key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
// 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 {
|
func New(capacity int, preallocate bool) *LRUCache {
|
||||||
var cache map[lruKey]*externalapi.BlockGHOSTDAGData
|
var cache map[lruKey]*externalapi.BlockGHOSTDAGData
|
||||||
if preallocate {
|
if preallocate {
|
||||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGData, capacity+1)
|
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGData, capacity)
|
||||||
} else {
|
} else {
|
||||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGData)
|
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGData)
|
||||||
}
|
}
|
||||||
@ -37,12 +37,12 @@ func New(capacity int, preallocate bool) *LRUCache {
|
|||||||
|
|
||||||
// Add adds an entry to the LRUCache
|
// Add adds an entry to the LRUCache
|
||||||
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, isTrustedData bool, value *externalapi.BlockGHOSTDAGData) {
|
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, isTrustedData bool, value *externalapi.BlockGHOSTDAGData) {
|
||||||
key := newKey(blockHash, isTrustedData)
|
if len(c.cache) >= c.capacity {
|
||||||
c.cache[key] = value
|
|
||||||
|
|
||||||
if len(c.cache) > c.capacity {
|
|
||||||
c.evictRandom()
|
c.evictRandom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key := newKey(blockHash, isTrustedData)
|
||||||
|
c.cache[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
// 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 {
|
func New(capacity int, preallocate bool) *LRUCache {
|
||||||
var cache map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair
|
var cache map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair
|
||||||
if preallocate {
|
if preallocate {
|
||||||
cache = make(map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair, capacity+1)
|
cache = make(map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair, capacity)
|
||||||
} else {
|
} else {
|
||||||
cache = make(map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair)
|
cache = make(map[lruKey][]*externalapi.BlockGHOSTDAGDataHashPair)
|
||||||
}
|
}
|
||||||
@ -37,12 +37,12 @@ func New(capacity int, preallocate bool) *LRUCache {
|
|||||||
|
|
||||||
// Add adds an entry to the LRUCache
|
// Add adds an entry to the LRUCache
|
||||||
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, windowSize int, value []*externalapi.BlockGHOSTDAGDataHashPair) {
|
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, windowSize int, value []*externalapi.BlockGHOSTDAGDataHashPair) {
|
||||||
key := newKey(blockHash, windowSize)
|
if len(c.cache) >= c.capacity {
|
||||||
c.cache[key] = value
|
|
||||||
|
|
||||||
if len(c.cache) > c.capacity {
|
|
||||||
c.evictRandom()
|
c.evictRandom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key := newKey(blockHash, windowSize)
|
||||||
|
c.cache[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
// 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 {
|
func New(capacity int, preallocate bool) *LRUCache {
|
||||||
var cache map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair
|
var cache map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair
|
||||||
if preallocate {
|
if preallocate {
|
||||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair, capacity+1)
|
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair, capacity)
|
||||||
} else {
|
} else {
|
||||||
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair)
|
cache = make(map[lruKey]*externalapi.BlockGHOSTDAGDataHashPair)
|
||||||
}
|
}
|
||||||
@ -37,12 +37,12 @@ func New(capacity int, preallocate bool) *LRUCache {
|
|||||||
|
|
||||||
// Add adds an entry to the LRUCache
|
// Add adds an entry to the LRUCache
|
||||||
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, index uint64, value *externalapi.BlockGHOSTDAGDataHashPair) {
|
func (c *LRUCache) Add(blockHash *externalapi.DomainHash, index uint64, value *externalapi.BlockGHOSTDAGDataHashPair) {
|
||||||
key := newKey(blockHash, index)
|
if len(c.cache) >= c.capacity {
|
||||||
c.cache[key] = value
|
|
||||||
|
|
||||||
if len(c.cache) > c.capacity {
|
|
||||||
c.evictRandom()
|
c.evictRandom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key := newKey(blockHash, index)
|
||||||
|
c.cache[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
// 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 {
|
func New(capacity int, preallocate bool) *LRUCache {
|
||||||
var cache map[uint64]*externalapi.DomainHash
|
var cache map[uint64]*externalapi.DomainHash
|
||||||
if preallocate {
|
if preallocate {
|
||||||
cache = make(map[uint64]*externalapi.DomainHash, capacity+1)
|
cache = make(map[uint64]*externalapi.DomainHash, capacity)
|
||||||
} else {
|
} else {
|
||||||
cache = make(map[uint64]*externalapi.DomainHash)
|
cache = make(map[uint64]*externalapi.DomainHash)
|
||||||
}
|
}
|
||||||
@ -25,11 +25,11 @@ func New(capacity int, preallocate bool) *LRUCache {
|
|||||||
|
|
||||||
// Add adds an entry to the LRUCache
|
// Add adds an entry to the LRUCache
|
||||||
func (c *LRUCache) Add(key uint64, value *externalapi.DomainHash) {
|
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.evictRandom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.cache[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the entry for the given key, or (nil, false) otherwise
|
// Get returns the entry for the given key, or (nil, false) otherwise
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user