Skip to content

Commit

Permalink
tweak comments
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Mar 18, 2024
1 parent 180faf8 commit 54b87e5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"unsafe"
)

// LRUCache implements LRU LRUCache with least recent used eviction policy.
// LRUCache implements LRU Cache with least recent used eviction policy.
type LRUCache[K comparable, V any] struct {
shards [512]lrushard[K, V]
mask uint32
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *LRUCache[K, V]) GetOrLoad(key K) (value V, err error, ok bool) {
return
}

// Peek returns value and expires nanoseconds for key, but does not modify its recency.
// Peek returns value, but does not modify its recency.
func (c *LRUCache[K, V]) Peek(key K) (value V, ok bool) {
hash := uint32(c.hasher(noescape(unsafe.Pointer(&key)), c.seed))
return c.shards[hash&c.mask].Peek(hash, key)
Expand Down
2 changes: 1 addition & 1 deletion lru_shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"unsafe"
)

// lrunode is a list lrunode of LRU, storing key-value pairs and related information
// lrunode is a list of lru node, storing key-value pairs and related information
type lrunode[K comparable, V any] struct {
key K
next uint32
Expand Down
8 changes: 4 additions & 4 deletions lru_shard_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func (s *lrushard[K, V]) table_Set(hash uint32, key K, index uint32) (prev uint3
}
}

// Get returns an index for a key.
// table_Get returns an index for a key.
// Returns false when no index has been assign for key.
func (s *lrushard[K, V]) table_Get(hash uint32, key K) (prev uint32, ok bool) {
func (s *lrushard[K, V]) table_Get(hash uint32, key K) (index uint32, ok bool) {
subhash := hash >> dibBitSize
mask := s.table.mask
i := subhash & mask
Expand All @@ -92,9 +92,9 @@ func (s *lrushard[K, V]) table_Get(hash uint32, key K) (prev uint32, ok bool) {
}
}

// Delete deletes an index for a key.
// table_Delete deletes an index for a key.
// Returns the deleted index, or false when no index was assigned.
func (s *lrushard[K, V]) table_Delete(hash uint32, key K) (v uint32, ok bool) {
func (s *lrushard[K, V]) table_Delete(hash uint32, key K) (index uint32, ok bool) {
subhash := hash >> dibBitSize
mask := s.table.mask
i := subhash & mask
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"unsafe"
)

// Options implements LRU Cache Option.
// Option is an interface for LRUCache and TTLCache configuration.
type Option[K comparable, V any] interface {
ApplyToLRUCache(*LRUCache[K, V])
ApplyToTTLCache(*TTLCache[K, V])
Expand Down
2 changes: 1 addition & 1 deletion ttl_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"unsafe"
)

// TTLCache implements LRU TTLCache with least recent used eviction policy.
// TTLCache implements LRU Cache with TTL functionality.
type TTLCache[K comparable, V any] struct {
shards [512]ttlshard[K, V]
mask uint32
Expand Down
2 changes: 1 addition & 1 deletion ttl_shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"unsafe"
)

// ttlnode is a list ttlnode of LRU, storing key-value pairs and related information
// ttlnode is a list of ttl node, storing key-value pairs and related information
type ttlnode[K comparable, V any] struct {
key K
expires uint32
Expand Down
8 changes: 4 additions & 4 deletions ttl_shard_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ttlNewTableSize(size uint32) (newsize uint32) {
return
}

// Set assigns an index to a key.
// table_Set assigns an index to a key.
// Returns the previous index, or false when no index was assigned.
func (s *ttlshard[K, V]) table_Set(hash uint32, key K, index uint32) (prev uint32, ok bool) {
subhash := hash >> dibBitSize
Expand Down Expand Up @@ -64,9 +64,9 @@ func (s *ttlshard[K, V]) table_Set(hash uint32, key K, index uint32) (prev uint3
}
}

// Get returns an index for a key.
// table_Get returns an index for a key.
// Returns false when no index has been assign for key.
func (s *ttlshard[K, V]) table_Get(hash uint32, key K) (prev uint32, ok bool) {
func (s *ttlshard[K, V]) table_Get(hash uint32, key K) (index uint32, ok bool) {
subhash := hash >> dibBitSize
mask := s.table.mask
i := subhash & mask
Expand All @@ -84,7 +84,7 @@ func (s *ttlshard[K, V]) table_Get(hash uint32, key K) (prev uint32, ok bool) {
}
}

// Delete deletes an index for a key.
// table_Delete deletes an index for a key.
// Returns the deleted index, or false when no index was assigned.
func (s *ttlshard[K, V]) table_Delete(hash uint32, key K) (v uint32, ok bool) {
subhash := hash >> dibBitSize
Expand Down

0 comments on commit 54b87e5

Please sign in to comment.