From f7746d88c9817a1c5127d7856b289d8fe2b18b24 Mon Sep 17 00:00:00 2001 From: maypok86 Date: Tue, 12 Mar 2024 20:59:00 +0300 Subject: [PATCH] [#56] Rename Advanced to Extension --- cache.go | 6 +++--- cache_test.go | 12 ++++++------ advanced.go => extension.go | 28 ++++++++++++++-------------- 3 files changed, 23 insertions(+), 23 deletions(-) rename advanced.go => extension.go (72%) diff --git a/cache.go b/cache.go index c696cce..bedbb0e 100644 --- a/cache.go +++ b/cache.go @@ -100,11 +100,11 @@ func (bs baseCache[K, V]) Stats() Stats { return newStats(bs.cache.Stats()) } -// Advanced returns access to inspect and perform low-level operations on this cache based on its runtime +// Extension returns access to inspect and perform low-level operations on this cache based on its runtime // characteristics. These operations are optional and dependent on how the cache was constructed // and what abilities the implementation exposes. -func (bs baseCache[K, V]) Advanced() Advanced[K, V] { - return newAdvanced(bs.cache) +func (bs baseCache[K, V]) Extension() Extension[K, V] { + return newExtension(bs.cache) } // Cache is a structure performs a best-effort bounding of a hash table using eviction algorithm diff --git a/cache_test.go b/cache_test.go index 9c00ffd..d573f45 100644 --- a/cache_test.go +++ b/cache_test.go @@ -332,17 +332,17 @@ func TestCache_Advanced(t *testing.T) { } k1 := 4 - v1, ok := c.Advanced().GetQuietly(k1) + v1, ok := c.Extension().GetQuietly(k1) if !ok { t.Fatalf("not found key %d", k1) } - e1, ok := c.Advanced().GetEntryQuietly(k1) + e1, ok := c.Extension().GetEntryQuietly(k1) if !ok { t.Fatalf("not found key %d", k1) } - e2, ok := c.Advanced().GetEntry(k1) + e2, ok := c.Extension().GetEntry(k1) if !ok { t.Fatalf("not found key %d", k1) } @@ -360,13 +360,13 @@ func TestCache_Advanced(t *testing.T) { t.Fatalf("found not valid entries. e1: %+v, e2: %+v, v1:%d", e1, e2, v1) } - if _, ok := c.Advanced().GetQuietly(size); ok { + if _, ok := c.Extension().GetQuietly(size); ok { t.Fatalf("found not valid key: %d", size) } - if _, ok := c.Advanced().GetEntryQuietly(size); ok { + if _, ok := c.Extension().GetEntryQuietly(size); ok { t.Fatalf("found not valid key: %d", size) } - if _, ok := c.Advanced().GetEntry(size); ok { + if _, ok := c.Extension().GetEntry(size); ok { t.Fatalf("found not valid key: %d", size) } } diff --git a/advanced.go b/extension.go similarity index 72% rename from advanced.go rename to extension.go index 60f6bbc..83a511b 100644 --- a/advanced.go +++ b/extension.go @@ -25,22 +25,22 @@ func zeroValue[V any]() V { return zero } -// Advanced is an access point for inspecting and performing low-level operations based on the cache's runtime +// Extension is an access point for inspecting and performing low-level operations based on the cache's runtime // characteristics. These operations are optional and dependent on how the cache was constructed // and what abilities the implementation exposes. -type Advanced[K comparable, V any] struct { +type Extension[K comparable, V any] struct { cache *core.Cache[K, V] } -func newAdvanced[K comparable, V any](cache *core.Cache[K, V]) Advanced[K, V] { - return Advanced[K, V]{ +func newExtension[K comparable, V any](cache *core.Cache[K, V]) Extension[K, V] { + return Extension[K, V]{ cache: cache, } } -func (a Advanced[K, V]) createEntry(n node.Node[K, V]) Entry[K, V] { +func (e Extension[K, V]) createEntry(n node.Node[K, V]) Entry[K, V] { var expiration int64 - if a.cache.WithExpiration() { + if e.cache.WithExpiration() { expiration = unixtime.StartTime() + int64(n.Expiration()) } @@ -56,8 +56,8 @@ func (a Advanced[K, V]) createEntry(n node.Node[K, V]) Entry[K, V] { // // Unlike Get in the cache, this function does not produce any side effects // such as updating statistics or the eviction policy. -func (a Advanced[K, V]) GetQuietly(key K) (V, bool) { - n, ok := a.cache.GetNodeQuietly(key) +func (e Extension[K, V]) GetQuietly(key K) (V, bool) { + n, ok := e.cache.GetNodeQuietly(key) if !ok { return zeroValue[V](), false } @@ -66,24 +66,24 @@ func (a Advanced[K, V]) GetQuietly(key K) (V, bool) { } // GetEntry returns the cache entry associated with the key in this cache. -func (a Advanced[K, V]) GetEntry(key K) (Entry[K, V], bool) { - n, ok := a.cache.GetNode(key) +func (e Extension[K, V]) GetEntry(key K) (Entry[K, V], bool) { + n, ok := e.cache.GetNode(key) if !ok { return Entry[K, V]{}, false } - return a.createEntry(n), true + return e.createEntry(n), true } // GetEntryQuietly returns the cache entry associated with the key in this cache. // // Unlike GetEntry, this function does not produce any side effects // such as updating statistics or the eviction policy. -func (a Advanced[K, V]) GetEntryQuietly(key K) (Entry[K, V], bool) { - n, ok := a.cache.GetNodeQuietly(key) +func (e Extension[K, V]) GetEntryQuietly(key K) (Entry[K, V], bool) { + n, ok := e.cache.GetNodeQuietly(key) if !ok { return Entry[K, V]{}, false } - return a.createEntry(n), true + return e.createEntry(n), true }