Skip to content

Commit 7f78ca1

Browse files
committed
removed internal test files
1 parent 77d5ecc commit 7f78ca1

File tree

6 files changed

+0
-42
lines changed

6 files changed

+0
-42
lines changed

lfu/lfu.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package lfu
22

33
import (
44
"container/heap"
5-
"sync"
65
)
76

87
// Cache is a thread safe LRU cache
98
type Cache[K comparable, V any] struct {
109
cap int
1110
queue *priorityQueue[K, V]
1211
items map[K]*entry[K, V]
13-
mu sync.RWMutex
1412
}
1513

1614
// NewCache creates a new LFU cache whose capacity is the default size (128).
@@ -29,9 +27,6 @@ func NewCacheWithCap[K comparable, V any](cap int) *Cache[K, V] {
2927

3028
// Get looks up a key's value from the cache.
3129
func (c *Cache[K, V]) Get(key K) (zero V, _ bool) {
32-
c.mu.RLock()
33-
defer c.mu.RUnlock()
34-
3530
e, ok := c.items[key]
3631
if !ok {
3732
return
@@ -43,9 +38,6 @@ func (c *Cache[K, V]) Get(key K) (zero V, _ bool) {
4338

4439
// Set sets a value to the cache with key. replacing any existing value.
4540
func (c *Cache[K, V]) Set(key K, val V) {
46-
c.mu.Lock()
47-
defer c.mu.Unlock()
48-
4941
if e, ok := c.items[key]; ok {
5042
c.queue.update(e, val)
5143
return
@@ -63,8 +55,6 @@ func (c *Cache[K, V]) Set(key K, val V) {
6355

6456
// Keys returns the keys of the cache. the order is from oldest to newest.
6557
func (c *Cache[K, V]) Keys() []K {
66-
c.mu.RLock()
67-
defer c.mu.RUnlock()
6858
keys := make([]K, 0, len(c.items))
6959
for _, entry := range *c.queue {
7060
keys = append(keys, entry.key)
@@ -74,8 +64,6 @@ func (c *Cache[K, V]) Keys() []K {
7464

7565
// Delete deletes the item with provided key from the cache.
7666
func (c *Cache[K, V]) Delete(key K) {
77-
c.mu.Lock()
78-
defer c.mu.Unlock()
7967
if e, ok := c.items[key]; ok {
8068
heap.Remove(c.queue, e.index)
8169
delete(c.items, key)
@@ -84,7 +72,5 @@ func (c *Cache[K, V]) Delete(key K) {
8472

8573
// Len returns the number of items in the cache.
8674
func (c *Cache[K, V]) Len() int {
87-
c.mu.RLock()
88-
defer c.mu.RUnlock()
8975
return c.queue.Len()
9076
}

lfu/lfu_internal_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

lru/lru.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package lru
22

33
import (
44
"container/list"
5-
"sync"
65
)
76

87
// Cache is a thread safe LRU cache
98
type Cache[K comparable, V any] struct {
109
cap int
1110
list *list.List
1211
items map[K]*list.Element
13-
mu sync.RWMutex
1412
}
1513

1614
type entry[K comparable, V any] struct {
@@ -34,8 +32,6 @@ func NewCacheWithCap[K comparable, V any](cap int) *Cache[K, V] {
3432

3533
// Get looks up a key's value from the cache.
3634
func (c *Cache[K, V]) Get(key K) (zero V, _ bool) {
37-
c.mu.RLock()
38-
defer c.mu.RUnlock()
3935
e, ok := c.items[key]
4036
if !ok {
4137
return
@@ -47,9 +43,6 @@ func (c *Cache[K, V]) Get(key K) (zero V, _ bool) {
4743

4844
// Set sets a value to the cache with key. replacing any existing value.
4945
func (c *Cache[K, V]) Set(key K, val V) {
50-
c.mu.Lock()
51-
defer c.mu.Unlock()
52-
5346
if e, ok := c.items[key]; ok {
5447
// updates cache order
5548
c.list.MoveToFront(e)
@@ -72,8 +65,6 @@ func (c *Cache[K, V]) Set(key K, val V) {
7265

7366
// Keys returns the keys of the cache. the order is from oldest to newest.
7467
func (c *Cache[K, V]) Keys() []K {
75-
c.mu.RLock()
76-
defer c.mu.RUnlock()
7768
keys := make([]K, 0, len(c.items))
7869
for ent := c.list.Back(); ent != nil; ent = ent.Prev() {
7970
entry := ent.Value.(*entry[K, V])
@@ -84,15 +75,11 @@ func (c *Cache[K, V]) Keys() []K {
8475

8576
// Len returns the number of items in the cache.
8677
func (c *Cache[K, V]) Len() int {
87-
c.mu.RLock()
88-
defer c.mu.RUnlock()
8978
return c.list.Len()
9079
}
9180

9281
// Delete deletes the item with provided key from the cache.
9382
func (c *Cache[K, V]) Delete(key K) {
94-
c.mu.Lock()
95-
defer c.mu.Unlock()
9683
if e, ok := c.items[key]; ok {
9784
c.delete(e)
9885
}

lru/lru_internal_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

simple/simple.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ package simple
22

33
import (
44
"sort"
5-
"sync"
65
"time"
76
)
87

98
// Cache is a simple cache has no clear priority for evict cache.
109
type Cache[K comparable, V any] struct {
1110
items map[K]*entry[V]
12-
mu sync.RWMutex
1311
}
1412

1513
type entry[V any] struct {
@@ -27,8 +25,6 @@ func NewCache[K comparable, V any]() *Cache[K, V] {
2725
// Set sets any item to the cache. replacing any existing item.
2826
// The default item never expires.
2927
func (c *Cache[K, V]) Set(k K, v V) {
30-
c.mu.Lock()
31-
defer c.mu.Unlock()
3228
c.items[k] = &entry[V]{
3329
val: v,
3430
createdAt: time.Now(),
@@ -38,9 +34,6 @@ func (c *Cache[K, V]) Set(k K, v V) {
3834
// Get gets an item from the cache.
3935
// Returns the item or zero value, and a bool indicating whether the key was found.
4036
func (c *Cache[K, V]) Get(k K) (val V, ok bool) {
41-
c.mu.RLock()
42-
defer c.mu.RUnlock()
43-
4437
got, found := c.items[k]
4538
if !found {
4639
return
@@ -50,9 +43,6 @@ func (c *Cache[K, V]) Get(k K) (val V, ok bool) {
5043

5144
// Keys returns cache keys. the order is sorted by created.
5245
func (c *Cache[K, _]) Keys() []K {
53-
c.mu.RLock()
54-
defer c.mu.RUnlock()
55-
5646
ret := make([]K, 0, len(c.items))
5747
for key := range c.items {
5848
ret = append(ret, key)
@@ -67,7 +57,5 @@ func (c *Cache[K, _]) Keys() []K {
6757

6858
// Delete deletes the item with provided key from the cache.
6959
func (c *Cache[K, V]) Delete(key K) {
70-
c.mu.Lock()
71-
defer c.mu.Unlock()
7260
delete(c.items, key)
7361
}

simple/simple_internal_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)