storj/storage/util.go
Egon Elbre 83df0ee1b0
Implement ListV2 with storage rework (#303)
1. Added KeyValueStore.Iterate for implementing the different List, ListV2 etc. implementations. This allows for more efficient use of memory depending on the situation.
2. Implemented an inmemory teststore for running tests. This should allow to replace MockKeyValueStore in most places.
3. Rewrote tests
4. Pulled out logger from bolt implementation so it can be used for all other storage implementations.
5. Fixed multiple things in bolt and redis implementations.
2018-09-05 19:10:35 +03:00

41 lines
944 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package storage
// NextKey returns the successive key
func NextKey(key Key) Key {
return append(CloneKey(key), 0)
}
// AfterPrefix returns the key after prefix
func AfterPrefix(key Key) Key {
after := CloneKey(key)
after[len(after)-1]++
return after
}
// CloneKey creates a copy of key
func CloneKey(key Key) Key { return append(Key{}, key...) }
// CloneValue creates a copy of value
func CloneValue(value Value) Value { return append(Value{}, value...) }
// CloneItem creates a deep copy of item
func CloneItem(item ListItem) ListItem {
return ListItem{
Key: CloneKey(item.Key),
Value: CloneValue(item.Value),
IsPrefix: item.IsPrefix,
}
}
// CloneItems creates a deep copy of items
func CloneItems(items Items) Items {
var result = make(Items, len(items))
for i, item := range items {
result[i] = CloneItem(item)
}
return result
}