File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,20 +32,6 @@ type arc struct {
3232 b2 * internal.Cache
3333}
3434
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-
4935func (a * arc ) Load (key interface {}) (value interface {}, ok bool ) {
5036 if val , ok := a .t1 .Peek (key ); ok {
5137 exp , _ := a .t1 .Expiry (key )
Original file line number Diff line number Diff line change @@ -53,11 +53,8 @@ func TestARCc(t *testing.T) {
5353
5454 a .Store (1 , 1 )
5555 a .Load (1 )
56-
5756 assert .Equal (t , 0 , a .t1 .Len ())
5857 assert .Equal (t , 1 , a .t2 .Len ())
59- assert .Equal (t , 1 , a .Front ())
60- assert .Equal (t , 1 , a .Back ())
6158
6259 a .Delete (1 )
6360}
Original file line number Diff line number Diff line change @@ -24,20 +24,6 @@ type Event = internal.Event
2424
2525// Cache stores data so that future requests for that data can be served faster.
2626type 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 {}
4127 // Load returns key value.
4228 Load (key interface {}) (interface {}, bool )
4329 // Peek returns key value without updating the underlying "recent-ness".
@@ -105,7 +91,7 @@ type Cache interface {
10591// GC is a long running function, it returns when ctx done, therefore the
10692// caller must start it in its own goroutine.
10793//
108- // # Experimental
94+ // Experimental
10995//
11096// Notice: This func is EXPERIMENTAL and may be changed or removed in a
11197// later release.
@@ -156,20 +142,6 @@ type cache struct {
156142 unsafe Cache
157143}
158144
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-
173145func (c * cache ) Load (key interface {}) (interface {}, bool ) {
174146 c .mu .Lock ()
175147 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) {
4242 return
4343}
4444
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-
5945func (c * collection ) Len () int {
6046 return c .ll .Len ()
6147}
Original file line number Diff line number Diff line change @@ -28,14 +28,11 @@ func TestCollection(t *testing.T) {
2828 }
2929 }
3030
31- front := c .Front ()
32- back := c .Back ()
3331 oldest := c .Discard ()
3432 c .Remove (entries [2 ])
33+ back := c .ll .Back ().Value .(* internal.Entry )
3534
36- assert .Equal (t , 1 , front .Key )
37- assert .Equal (t , 3 , back .Key )
3835 assert .Equal (t , 1 , oldest .Key )
3936 assert .Equal (t , 1 , c .Len ())
40- assert .Equal (t , 2 , c . Back () .Key )
37+ assert .Equal (t , 2 , back .Key )
4138}
Original file line number Diff line number Diff line change @@ -18,8 +18,6 @@ func New(cap int) libcache.Cache {
1818
1919type idle struct {}
2020
21- func (idle ) Front () (v interface {}) { return }
22- func (idle ) Back () (v interface {}) { return }
2321func (idle ) Load (interface {}) (v interface {}, ok bool ) { return }
2422func (idle ) Peek (interface {}) (v interface {}, ok bool ) { return }
2523func (idle ) Keys () (keys []interface {}) { return }
Original file line number Diff line number Diff line change @@ -53,8 +53,6 @@ type Collection interface {
5353 Add (* Entry )
5454 Remove (* Entry )
5555 Discard () * Entry
56- Front () * Entry
57- Back () * Entry
5856 Len () int
5957 Init ()
6058}
@@ -99,30 +97,6 @@ type Cache struct {
9997 capacity int
10098}
10199
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-
126100// Load returns key value.
127101func (c * Cache ) Load (key interface {}) (interface {}, bool ) {
128102 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) {
5757 return heap .Pop (f ).(* element ).value
5858}
5959
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-
7460func (f * collection ) Move (e * internal.Entry ) {
7561 ele := e .Element .(* element )
7662 ele .count ++
Original file line number Diff line number Diff line change @@ -27,13 +27,9 @@ func TestCollection(t *testing.T) {
2727 }
2828 }
2929
30- front := f .Front ()
31- back := f .Back ()
3230 oldest := f .Discard ()
3331 f .Remove (entries [2 ])
3432
35- assert .Equal (t , front .Key , 2 )
36- assert .Equal (t , back .Key , 1 )
3733 assert .Equal (t , oldest .Key , 1 )
3834 assert .Equal (t , f .Len (), 1 )
3935 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) {
4242 return
4343}
4444
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-
5945func (c * collection ) Len () int {
6046 return c .ll .Len ()
6147}
You can’t perform that action at this time.
0 commit comments