1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

bump tchap/go-patricia v2.3.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-04-06 01:46:41 +02:00
parent b00897d51a
commit 6251d81510
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 51 additions and 7 deletions

View file

@ -12,7 +12,7 @@ github.com/konsorten/go-windows-terminal-sequences f55edac94c9bbba5d6182a4be46d8
github.com/kr/pty 521317be5ebc228a0f0ede099fa2a0b5ece22e49 # v1.1.4
github.com/mattn/go-shellwords a72fbe27a1b0ed0df2f02754945044ce1456608b # v1.0.5
github.com/sirupsen/logrus 8bdbc7bcc01dcbb8ec23dc8a28e332258d25251f # v1.4.1
github.com/tchap/go-patricia v2.2.6
github.com/tchap/go-patricia a7f0089c6f496e8e70402f61733606daa326cac5 # v2.3.0
github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3 # v0.1.0
golang.org/x/net a680a1efc54dd51c040b3b5ce4939ea3cf2ea0d1
golang.org/x/sys d455e41777fca6e8a5a79e34a14b8368bc11d9ba

View file

@ -1,8 +1,6 @@
# go-patricia #
**Documentation**: [GoDoc](http://godoc.org/github.com/tchap/go-patricia/patricia)<br />
**Build Status**: [![Build
Status](https://drone.io/github.com/tchap/go-patricia/status.png)](https://drone.io/github.com/tchap/go-patricia/latest)<br />
**Test Coverage**: [![Coverage
Status](https://coveralls.io/repos/tchap/go-patricia/badge.png)](https://coveralls.io/r/tchap/go-patricia)
@ -117,7 +115,3 @@ MIT, check the `LICENSE` file.
[![Gittip
Badge](http://img.shields.io/gittip/alanhamlett.png)](https://www.gittip.com/tchap/
"Gittip Badge")
[![Bitdeli
Badge](https://d2weczhvl823v0.cloudfront.net/tchap/go-patricia/trend.png)](https://bitdeli.com/free
"Bitdeli Badge")

View file

@ -20,6 +20,7 @@ type childList interface {
next(b byte) *Trie
walk(prefix *Prefix, visitor VisitorFunc) error
print(w io.Writer, indent int)
clone() childList
total() int
}
@ -143,6 +144,17 @@ func (list *sparseChildList) total() int {
return tot
}
func (list *sparseChildList) clone() childList {
clones := make(tries, len(list.children), cap(list.children))
for i, child := range list.children {
clones[i] = child.Clone()
}
return &sparseChildList{
children: clones,
}
}
func (list *sparseChildList) print(w io.Writer, indent int) {
for _, child := range list.children {
if child != nil {
@ -314,6 +326,32 @@ func (list *denseChildList) print(w io.Writer, indent int) {
}
}
func (list *denseChildList) clone() childList {
clones := make(tries, cap(list.children))
if list.numChildren != 0 {
clonedCount := 0
for i := list.headIndex; i < len(list.children); i++ {
child := list.children[i]
if child != nil {
clones[i] = child.Clone()
clonedCount++
if clonedCount == list.numChildren {
break
}
}
}
}
return &denseChildList{
min: list.min,
max: list.max,
numChildren: list.numChildren,
headIndex: list.headIndex,
children: clones,
}
}
func (list *denseChildList) total() int {
tot := 0
for _, child := range list.children {

View file

@ -77,6 +77,18 @@ func MaxChildrenPerSparseNode(value int) Option {
}
}
// Clone makes a copy of an existing trie.
// Items stored in both tries become shared, obviously.
func (trie *Trie) Clone() *Trie {
return &Trie{
prefix: append(Prefix(nil), trie.prefix...),
item: trie.item,
maxPrefixPerNode: trie.maxPrefixPerNode,
maxChildrenPerSparseNode: trie.maxChildrenPerSparseNode,
children: trie.children.clone(),
}
}
// Item returns the item stored in the root of this trie.
func (trie *Trie) Item() Item {
return trie.item