File tree 15 files changed +9
-170
lines changed
15 files changed +9
-170
lines changed Original file line number Diff line number Diff line change @@ -32,20 +32,6 @@ type arc struct {
32
32
b2 * internal.Cache
33
33
}
34
34
35
- func (a * arc ) Front () interface {} {
36
- if k := a .t1 .Front (); k != nil {
37
- return k
38
- }
39
- return a .t2 .Front ()
40
- }
41
-
42
- func (a * arc ) Back () interface {} {
43
- if k := a .t1 .Back (); k != nil {
44
- return k
45
- }
46
- return a .t2 .Back ()
47
- }
48
-
49
35
func (a * arc ) Load (key interface {}) (value interface {}, ok bool ) {
50
36
if val , ok := a .t1 .Peek (key ); ok {
51
37
exp , _ := a .t1 .Expiry (key )
Original file line number Diff line number Diff line change @@ -53,11 +53,8 @@ func TestARCc(t *testing.T) {
53
53
54
54
a .Store (1 , 1 )
55
55
a .Load (1 )
56
-
57
56
assert .Equal (t , 0 , a .t1 .Len ())
58
57
assert .Equal (t , 1 , a .t2 .Len ())
59
- assert .Equal (t , 1 , a .Front ())
60
- assert .Equal (t , 1 , a .Back ())
61
58
62
59
a .Delete (1 )
63
60
}
Original file line number Diff line number Diff line change @@ -24,20 +24,6 @@ type Event = internal.Event
24
24
25
25
// Cache stores data so that future requests for that data can be served faster.
26
26
type Cache interface {
27
- // Front returns the first key of cache or nil if the cache is empty.
28
- //
29
- // # Experimental
30
- //
31
- // Notice: This func is EXPERIMENTAL and may be changed or removed in a
32
- // later release.
33
- Front () interface {}
34
- // Back returns the last key of cache or nil if the cache is empty.
35
- //
36
- // # Experimental
37
- //
38
- // Notice: This func is EXPERIMENTAL and may be changed or removed in a
39
- // later release.
40
- Back () interface {}
41
27
// Load returns key value.
42
28
Load (key interface {}) (interface {}, bool )
43
29
// Peek returns key value without updating the underlying "recent-ness".
@@ -105,7 +91,7 @@ type Cache interface {
105
91
// GC is a long running function, it returns when ctx done, therefore the
106
92
// caller must start it in its own goroutine.
107
93
//
108
- // # Experimental
94
+ // Experimental
109
95
//
110
96
// Notice: This func is EXPERIMENTAL and may be changed or removed in a
111
97
// later release.
@@ -156,20 +142,6 @@ type cache struct {
156
142
unsafe Cache
157
143
}
158
144
159
- func (c * cache ) Front () interface {} {
160
- c .mu .Lock ()
161
- k := c .unsafe .Front ()
162
- c .mu .Unlock ()
163
- return k
164
- }
165
-
166
- func (c * cache ) Back () interface {} {
167
- c .mu .Lock ()
168
- k := c .unsafe .Back ()
169
- c .mu .Unlock ()
170
- return k
171
- }
172
-
173
145
func (c * cache ) Load (key interface {}) (interface {}, bool ) {
174
146
c .mu .Lock ()
175
147
v , ok := c .unsafe .Load (key )
Original file line number Diff line number Diff line change @@ -42,20 +42,6 @@ func (c *collection) Discard() (e *internal.Entry) {
42
42
return
43
43
}
44
44
45
- func (c * collection ) Front () (e * internal.Entry ) {
46
- if le := c .ll .Front (); le != nil {
47
- e = le .Value .(* internal.Entry )
48
- }
49
- return
50
- }
51
-
52
- func (c * collection ) Back () (e * internal.Entry ) {
53
- if le := c .ll .Back (); le != nil {
54
- e = le .Value .(* internal.Entry )
55
- }
56
- return
57
- }
58
-
59
45
func (c * collection ) Len () int {
60
46
return c .ll .Len ()
61
47
}
Original file line number Diff line number Diff line change @@ -28,14 +28,11 @@ func TestCollection(t *testing.T) {
28
28
}
29
29
}
30
30
31
- front := c .Front ()
32
- back := c .Back ()
33
31
oldest := c .Discard ()
34
32
c .Remove (entries [2 ])
33
+ back := c .ll .Back ().Value .(* internal.Entry )
35
34
36
- assert .Equal (t , 1 , front .Key )
37
- assert .Equal (t , 3 , back .Key )
38
35
assert .Equal (t , 1 , oldest .Key )
39
36
assert .Equal (t , 1 , c .Len ())
40
- assert .Equal (t , 2 , c . Back () .Key )
37
+ assert .Equal (t , 2 , back .Key )
41
38
}
Original file line number Diff line number Diff line change @@ -18,8 +18,6 @@ func New(cap int) libcache.Cache {
18
18
19
19
type idle struct {}
20
20
21
- func (idle ) Front () (v interface {}) { return }
22
- func (idle ) Back () (v interface {}) { return }
23
21
func (idle ) Load (interface {}) (v interface {}, ok bool ) { return }
24
22
func (idle ) Peek (interface {}) (v interface {}, ok bool ) { return }
25
23
func (idle ) Keys () (keys []interface {}) { return }
Original file line number Diff line number Diff line change @@ -53,8 +53,6 @@ type Collection interface {
53
53
Add (* Entry )
54
54
Remove (* Entry )
55
55
Discard () * Entry
56
- Front () * Entry
57
- Back () * Entry
58
56
Len () int
59
57
Init ()
60
58
}
@@ -99,30 +97,6 @@ type Cache struct {
99
97
capacity int
100
98
}
101
99
102
- // Front returns the first key of cache or nil if the cache is empty.
103
- func (c * Cache ) Front () interface {} {
104
- // Run GC inline before get the front entry.
105
- c .GC ()
106
-
107
- if e := c .coll .Front (); e != nil {
108
- return e .Key
109
- }
110
-
111
- return nil
112
- }
113
-
114
- // Back returns the last key of cache or nil if the cache is empty.
115
- func (c * Cache ) Back () interface {} {
116
- // Run GC inline before get the back entry.
117
- c .GC ()
118
-
119
- if e := c .coll .Back (); e != nil {
120
- return e .Key
121
- }
122
-
123
- return nil
124
- }
125
-
126
100
// Load returns key value.
127
101
func (c * Cache ) Load (key interface {}) (interface {}, bool ) {
128
102
return c .get (key , false )
Original file line number Diff line number Diff line change @@ -57,20 +57,6 @@ func (f *collection) Discard() (e *internal.Entry) {
57
57
return heap .Pop (f ).(* element ).value
58
58
}
59
59
60
- func (f * collection ) Front () (e * internal.Entry ) {
61
- if f .Len () > 0 {
62
- e = (* f )[f .Len ()- 1 ].value
63
- }
64
- return
65
- }
66
-
67
- func (f * collection ) Back () (e * internal.Entry ) {
68
- if f .Len () > 0 {
69
- e = (* f )[0 ].value
70
- }
71
- return
72
- }
73
-
74
60
func (f * collection ) Move (e * internal.Entry ) {
75
61
ele := e .Element .(* element )
76
62
ele .count ++
Original file line number Diff line number Diff line change @@ -27,13 +27,9 @@ func TestCollection(t *testing.T) {
27
27
}
28
28
}
29
29
30
- front := f .Front ()
31
- back := f .Back ()
32
30
oldest := f .Discard ()
33
31
f .Remove (entries [2 ])
34
32
35
- assert .Equal (t , front .Key , 2 )
36
- assert .Equal (t , back .Key , 1 )
37
33
assert .Equal (t , oldest .Key , 1 )
38
34
assert .Equal (t , f .Len (), 1 )
39
35
assert .Equal (t , (* f )[0 ].value .Key , 2 )
Original file line number Diff line number Diff line change @@ -42,20 +42,6 @@ func (c *collection) Discard() (e *internal.Entry) {
42
42
return
43
43
}
44
44
45
- func (c * collection ) Front () (e * internal.Entry ) {
46
- if le := c .ll .Front (); le != nil {
47
- e = le .Value .(* internal.Entry )
48
- }
49
- return
50
- }
51
-
52
- func (c * collection ) Back () (e * internal.Entry ) {
53
- if le := c .ll .Back (); le != nil {
54
- e = le .Value .(* internal.Entry )
55
- }
56
- return
57
- }
58
-
59
45
func (c * collection ) Len () int {
60
46
return c .ll .Len ()
61
47
}
Original file line number Diff line number Diff line change @@ -28,15 +28,11 @@ func TestCollection(t *testing.T) {
28
28
}
29
29
}
30
30
31
- front := c .Front ()
32
- back := c .Back ()
33
-
34
31
oldest := c .Discard ()
35
32
c .Remove (entries [0 ])
33
+ back := c .ll .Back ().Value .(* internal.Entry )
36
34
37
- assert .Equal (t , 1 , front .Key )
38
- assert .Equal (t , 3 , back .Key )
39
35
assert .Equal (t , 3 , oldest .Key )
40
36
assert .Equal (t , 1 , c .Len ())
41
- assert .Equal (t , 2 , c . Back () .Key )
37
+ assert .Equal (t , 2 , back .Key )
42
38
}
Original file line number Diff line number Diff line change @@ -45,20 +45,6 @@ func (c *collection) Discard() (e *internal.Entry) {
45
45
return
46
46
}
47
47
48
- func (c * collection ) Front () (e * internal.Entry ) {
49
- if le := c .ll .Front (); le != nil {
50
- e = le .Value .(* internal.Entry )
51
- }
52
- return
53
- }
54
-
55
- func (c * collection ) Back () (e * internal.Entry ) {
56
- if le := c .ll .Back (); le != nil {
57
- e = le .Value .(* internal.Entry )
58
- }
59
- return
60
- }
61
-
62
48
func (c * collection ) Len () int {
63
49
return c .ll .Len ()
64
50
}
Original file line number Diff line number Diff line change @@ -28,15 +28,11 @@ func TestCollection(t *testing.T) {
28
28
}
29
29
}
30
30
31
- front := c .Front ()
32
- back := c .Back ()
33
-
34
31
oldest := c .Discard ()
35
32
c .Remove (entries [2 ])
33
+ back := c .ll .Back ().Value .(* internal.Entry )
36
34
37
- assert .Equal (t , 3 , front .Key )
38
- assert .Equal (t , 1 , back .Key )
39
35
assert .Equal (t , 1 , oldest .Key )
40
36
assert .Equal (t , 1 , c .Len ())
41
- assert .Equal (t , 2 , c . Back () .Key )
37
+ assert .Equal (t , 2 , back .Key )
42
38
}
Original file line number Diff line number Diff line change @@ -45,20 +45,6 @@ func (c *collection) Discard() (e *internal.Entry) {
45
45
return
46
46
}
47
47
48
- func (c * collection ) Front () (e * internal.Entry ) {
49
- if le := c .ll .Front (); le != nil {
50
- e = le .Value .(* internal.Entry )
51
- }
52
- return
53
- }
54
-
55
- func (c * collection ) Back () (e * internal.Entry ) {
56
- if le := c .ll .Back (); le != nil {
57
- e = le .Value .(* internal.Entry )
58
- }
59
- return
60
- }
61
-
62
48
func (c * collection ) Len () int {
63
49
return c .ll .Len ()
64
50
}
Original file line number Diff line number Diff line change @@ -28,14 +28,11 @@ func TestCollection(t *testing.T) {
28
28
}
29
29
}
30
30
31
- front := c .Front ()
32
- back := c .Back ()
33
31
oldest := c .Discard ()
34
32
c .Remove (entries [1 ])
33
+ back := c .ll .Back ().Value .(* internal.Entry )
35
34
36
- assert .Equal (t , 3 , front .Key )
37
- assert .Equal (t , 1 , back .Key )
38
35
assert .Equal (t , 3 , oldest .Key )
39
36
assert .Equal (t , 1 , c .Len ())
40
- assert .Equal (t , 1 , c . Back () .Key )
37
+ assert .Equal (t , 1 , back .Key )
41
38
}
You can’t perform that action at this time.
0 commit comments