Release v0.3.0

This commit is contained in:
Manu Herrera
2020-11-09 10:05:29 -03:00
parent 4e9aa7a3c5
commit 8107c4478b
1265 changed files with 440488 additions and 107809 deletions

17
vendor/github.com/decred/dcrd/lru/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,17 @@
ISC License
Copyright (c) 2013-2017 The btcsuite developers
Copyright (c) 2015-2018 The Decred developers
Copyright (c) 2017 The Lightning Network Developers
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

40
vendor/github.com/decred/dcrd/lru/README.md generated vendored Normal file
View File

@@ -0,0 +1,40 @@
lru
===
[![Build Status](http://img.shields.io/travis/decred/dcrd.svg)](https://travis-ci.org/decred/dcrd)
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/decred/dcrd/lru)
Package lru implements a generic least-recently-used cache with near O(1) perf.
## LRU Cache
A least-recently-used (LRU) cache is a cache that holds a limited number of
items with an eviction policy such that when the capacity of the cache is
exceeded, the least-recently-used item is automatically removed when inserting a
new item. The meaining of used in this implementation is either accessing the
item via a lookup or adding the item into the cache, including when the item
already exists.
## External Use
This package has intentionally been designed so it can be used as a standalone
package for any projects needing to make use of a well-test and conccurrent safe
least-recently-used cache with near O(1) performance characteristics for
lookups, inserts, and deletions.
## Installation and Updating
```bash
$ go get -u github.com/decred/dcrd/lru
```
## Examples
* [Basic Usage](http://godoc.org/github.com/decred/dcrd/lru#example-package--BasicUsage)
Demonstrates creating a new cache instance, inserting items into the cache,
causing an eviction of the least-recently-used item, and removing an item.
## License
Package lru is licensed under the [copyfree](http://copyfree.org) ISC License.

104
vendor/github.com/decred/dcrd/lru/cache.go generated vendored Normal file
View File

@@ -0,0 +1,104 @@
// Copyright (c) 2019 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package lru
import (
"container/list"
"sync"
)
// Cache provides a concurrency safe least-recently-used cache with nearly O(1)
// lookups, inserts, and deletions. The cache is limited to a maximum number of
// items with eviction for the oldest entry when the limit is exceeded.
//
// The NewCache function must be used to create a usable cache since the zero
// value of this struct is not valid.
type Cache struct {
mtx sync.Mutex
cache map[interface{}]*list.Element // nearly O(1) lookups
list *list.List // O(1) insert, update, delete
limit uint
}
// Contains returns whether or not the passed item is a member of the cache.
//
// This function is safe for concurrent access.
func (m *Cache) Contains(item interface{}) bool {
m.mtx.Lock()
node, exists := m.cache[item]
if exists {
m.list.MoveToFront(node)
}
m.mtx.Unlock()
return exists
}
// Add adds the passed item to the cache and handles eviction of the oldest item
// if adding the new item would exceed the max limit. Adding an existing item
// makes it the most recently used item.
//
// This function is safe for concurrent access.
func (m *Cache) Add(item interface{}) {
m.mtx.Lock()
defer m.mtx.Unlock()
// When the limit is zero, nothing can be added to the cache, so just
// return.
if m.limit == 0 {
return
}
// When the entry already exists move it to the front of the list thereby
// marking it most recently used.
if node, exists := m.cache[item]; exists {
m.list.MoveToFront(node)
return
}
// Evict the least recently used entry (back of the list) if the the new
// entry would exceed the size limit for the cache. Also reuse the list
// node so a new one doesn't have to be allocated.
if uint(len(m.cache))+1 > m.limit {
node := m.list.Back()
lru := node.Value
// Evict least recently used item.
delete(m.cache, lru)
// Reuse the list node of the item that was just evicted for the new
// item.
node.Value = item
m.list.MoveToFront(node)
m.cache[item] = node
return
}
// The limit hasn't been reached yet, so just add the new item.
node := m.list.PushFront(item)
m.cache[item] = node
}
// Delete deletes the passed item from the cache (if it exists).
//
// This function is safe for concurrent access.
func (m *Cache) Delete(item interface{}) {
m.mtx.Lock()
if node, exists := m.cache[item]; exists {
m.list.Remove(node)
delete(m.cache, item)
}
m.mtx.Unlock()
}
// Cache returns an initialized and empty LRU cache. See the documentation for
// Cache for more details.
func NewCache(limit uint) Cache {
return Cache{
cache: make(map[interface{}]*list.Element),
list: list.New(),
limit: limit,
}
}

24
vendor/github.com/decred/dcrd/lru/doc.go generated vendored Normal file
View File

@@ -0,0 +1,24 @@
// Copyright (c) 2019 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
/*
Package lru implements a generic least-recently-used cache with near O(1) perf.
LRU Cache
A least-recently-used (LRU) cache is a cache that holds a limited number of
items with an eviction policy such that when the capacity of the cache is
exceeded, the least-recently-used item is automatically removed when inserting a
new item. The meaining of used in this implementation is either accessing the
item via a lookup or adding the item into the cache, including when the item
already exists.
External Use
This package has intentionally been designed so it can be used as a standalone
package for any projects needing to make use of a well-test least-recently-used
cache with near O(1) performance characteristics for lookups, inserts, and
deletions.
*/
package lru

3
vendor/github.com/decred/dcrd/lru/go.mod generated vendored Normal file
View File

@@ -0,0 +1,3 @@
module github.com/decred/dcrd/lru
go 1.11