mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-04 07:48:44 +00:00
Enable construction of TruncIndex from id array.
Fixes #5166 Current graph.restore is essentially O(n^2 log n) due to how suffixarray creation works. Rather than create/append/create new this supports creation from a seed array of ids. Functional testing shows this eliminates the hang on Creating image graph reported on list. Docker-DCO-1.1-Signed-off-by: Paul Nasrat <pnasrat@gmail.com> (github: pnasrat)
This commit is contained in:
+8
-3
@@ -426,12 +426,17 @@ type TruncIndex struct {
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
func NewTruncIndex() *TruncIndex {
|
||||
return &TruncIndex{
|
||||
index: suffixarray.New([]byte{' '}),
|
||||
func NewTruncIndex(ids []string) (idx *TruncIndex) {
|
||||
idx = &TruncIndex{
|
||||
ids: make(map[string]bool),
|
||||
bytes: []byte{' '},
|
||||
}
|
||||
for _, id := range ids {
|
||||
idx.ids[id] = true
|
||||
idx.bytes = append(idx.bytes, []byte(id+" ")...)
|
||||
}
|
||||
idx.index = suffixarray.New(idx.bytes)
|
||||
return
|
||||
}
|
||||
|
||||
func (idx *TruncIndex) Add(id string) error {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@ func TestRaceWriteBroadcaster(t *testing.T) {
|
||||
|
||||
// Test the behavior of TruncIndex, an index for querying IDs from a non-conflicting prefix.
|
||||
func TestTruncIndex(t *testing.T) {
|
||||
index := NewTruncIndex()
|
||||
ids := []string{}
|
||||
index := NewTruncIndex(ids)
|
||||
// Get on an empty index
|
||||
if _, err := index.Get("foobar"); err == nil {
|
||||
t.Fatal("Get on an empty index should return an error")
|
||||
|
||||
Reference in New Issue
Block a user