Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33_sdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
harrylee2015
chain33_sdk
Commits
7696a740
Commit
7696a740
authored
May 31, 2018
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add missing vendor files
parent
812c9ec8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
204 additions
and
0 deletions
+204
-0
lru.go
src/vendor/github.com/hashicorp/golang-lru/simplelru/lru.go
+161
-0
lru_interface.go
...ithub.com/hashicorp/golang-lru/simplelru/lru_interface.go
+37
-0
vendor.json
src/vendor/vendor.json
+6
-0
No files found.
src/vendor/github.com/hashicorp/golang-lru/simplelru/lru.go
0 → 100644
View file @
7696a740
package
simplelru
import
(
"container/list"
"errors"
)
// EvictCallback is used to get a callback when a cache entry is evicted
type
EvictCallback
func
(
key
interface
{},
value
interface
{})
// LRU implements a non-thread safe fixed size LRU cache
type
LRU
struct
{
size
int
evictList
*
list
.
List
items
map
[
interface
{}]
*
list
.
Element
onEvict
EvictCallback
}
// entry is used to hold a value in the evictList
type
entry
struct
{
key
interface
{}
value
interface
{}
}
// NewLRU constructs an LRU of the given size
func
NewLRU
(
size
int
,
onEvict
EvictCallback
)
(
*
LRU
,
error
)
{
if
size
<=
0
{
return
nil
,
errors
.
New
(
"Must provide a positive size"
)
}
c
:=
&
LRU
{
size
:
size
,
evictList
:
list
.
New
(),
items
:
make
(
map
[
interface
{}]
*
list
.
Element
),
onEvict
:
onEvict
,
}
return
c
,
nil
}
// Purge is used to completely clear the cache.
func
(
c
*
LRU
)
Purge
()
{
for
k
,
v
:=
range
c
.
items
{
if
c
.
onEvict
!=
nil
{
c
.
onEvict
(
k
,
v
.
Value
.
(
*
entry
)
.
value
)
}
delete
(
c
.
items
,
k
)
}
c
.
evictList
.
Init
()
}
// Add adds a value to the cache. Returns true if an eviction occurred.
func
(
c
*
LRU
)
Add
(
key
,
value
interface
{})
(
evicted
bool
)
{
// Check for existing item
if
ent
,
ok
:=
c
.
items
[
key
];
ok
{
c
.
evictList
.
MoveToFront
(
ent
)
ent
.
Value
.
(
*
entry
)
.
value
=
value
return
false
}
// Add new item
ent
:=
&
entry
{
key
,
value
}
entry
:=
c
.
evictList
.
PushFront
(
ent
)
c
.
items
[
key
]
=
entry
evict
:=
c
.
evictList
.
Len
()
>
c
.
size
// Verify size not exceeded
if
evict
{
c
.
removeOldest
()
}
return
evict
}
// Get looks up a key's value from the cache.
func
(
c
*
LRU
)
Get
(
key
interface
{})
(
value
interface
{},
ok
bool
)
{
if
ent
,
ok
:=
c
.
items
[
key
];
ok
{
c
.
evictList
.
MoveToFront
(
ent
)
return
ent
.
Value
.
(
*
entry
)
.
value
,
true
}
return
}
// Contains checks if a key is in the cache, without updating the recent-ness
// or deleting it for being stale.
func
(
c
*
LRU
)
Contains
(
key
interface
{})
(
ok
bool
)
{
_
,
ok
=
c
.
items
[
key
]
return
ok
}
// Peek returns the key value (or undefined if not found) without updating
// the "recently used"-ness of the key.
func
(
c
*
LRU
)
Peek
(
key
interface
{})
(
value
interface
{},
ok
bool
)
{
var
ent
*
list
.
Element
if
ent
,
ok
=
c
.
items
[
key
];
ok
{
return
ent
.
Value
.
(
*
entry
)
.
value
,
true
}
return
nil
,
ok
}
// Remove removes the provided key from the cache, returning if the
// key was contained.
func
(
c
*
LRU
)
Remove
(
key
interface
{})
(
present
bool
)
{
if
ent
,
ok
:=
c
.
items
[
key
];
ok
{
c
.
removeElement
(
ent
)
return
true
}
return
false
}
// RemoveOldest removes the oldest item from the cache.
func
(
c
*
LRU
)
RemoveOldest
()
(
key
interface
{},
value
interface
{},
ok
bool
)
{
ent
:=
c
.
evictList
.
Back
()
if
ent
!=
nil
{
c
.
removeElement
(
ent
)
kv
:=
ent
.
Value
.
(
*
entry
)
return
kv
.
key
,
kv
.
value
,
true
}
return
nil
,
nil
,
false
}
// GetOldest returns the oldest entry
func
(
c
*
LRU
)
GetOldest
()
(
key
interface
{},
value
interface
{},
ok
bool
)
{
ent
:=
c
.
evictList
.
Back
()
if
ent
!=
nil
{
kv
:=
ent
.
Value
.
(
*
entry
)
return
kv
.
key
,
kv
.
value
,
true
}
return
nil
,
nil
,
false
}
// Keys returns a slice of the keys in the cache, from oldest to newest.
func
(
c
*
LRU
)
Keys
()
[]
interface
{}
{
keys
:=
make
([]
interface
{},
len
(
c
.
items
))
i
:=
0
for
ent
:=
c
.
evictList
.
Back
();
ent
!=
nil
;
ent
=
ent
.
Prev
()
{
keys
[
i
]
=
ent
.
Value
.
(
*
entry
)
.
key
i
++
}
return
keys
}
// Len returns the number of items in the cache.
func
(
c
*
LRU
)
Len
()
int
{
return
c
.
evictList
.
Len
()
}
// removeOldest removes the oldest item from the cache.
func
(
c
*
LRU
)
removeOldest
()
{
ent
:=
c
.
evictList
.
Back
()
if
ent
!=
nil
{
c
.
removeElement
(
ent
)
}
}
// removeElement is used to remove a given list element from the cache
func
(
c
*
LRU
)
removeElement
(
e
*
list
.
Element
)
{
c
.
evictList
.
Remove
(
e
)
kv
:=
e
.
Value
.
(
*
entry
)
delete
(
c
.
items
,
kv
.
key
)
if
c
.
onEvict
!=
nil
{
c
.
onEvict
(
kv
.
key
,
kv
.
value
)
}
}
src/vendor/github.com/hashicorp/golang-lru/simplelru/lru_interface.go
0 → 100644
View file @
7696a740
package
simplelru
// LRUCache is the interface for simple LRU cache.
type
LRUCache
interface
{
// Adds a value to the cache, returns true if an eviction occurred and
// updates the "recently used"-ness of the key.
Add
(
key
,
value
interface
{})
bool
// Returns key's value from the cache and
// updates the "recently used"-ness of the key. #value, isFound
Get
(
key
interface
{})
(
value
interface
{},
ok
bool
)
// Check if a key exsists in cache without updating the recent-ness.
Contains
(
key
interface
{})
(
ok
bool
)
// Returns key's value without updating the "recently used"-ness of the key.
Peek
(
key
interface
{})
(
value
interface
{},
ok
bool
)
// Removes a key from the cache.
Remove
(
key
interface
{})
bool
// Removes the oldest entry from cache.
RemoveOldest
()
(
interface
{},
interface
{},
bool
)
// Returns the oldest entry from the cache. #key, value, isFound
GetOldest
()
(
interface
{},
interface
{},
bool
)
// Returns a slice of the keys in the cache, from oldest to newest.
Keys
()
[]
interface
{}
// Returns the number of items in the cache.
Len
()
int
// Clear all cache entries
Purge
()
}
src/vendor/vendor.json
View file @
7696a740
...
...
@@ -262,6 +262,12 @@
"revisionTime"
:
"2018-02-01T23:52:37Z"
},
{
"checksumSHA1"
:
"BBPs41SjdH2T+Kos+L4KbjmDsJk="
,
"path"
:
"github.com/hashicorp/golang-lru/simplelru"
,
"revision"
:
"0fb14efe8c47ae851c0034ed7a448854d3d34cf3"
,
"revisionTime"
:
"2018-02-01T23:52:37Z"
},
{
"checksumSHA1"
:
"o8plpAmb60vrmo/6FMDQZjyoO9U="
,
"path"
:
"github.com/inconshreveable/log15"
,
"revision"
:
""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment