Files
kopia/internal/bigmap/bigmap_set.go
Jarek Kowalski 28ce29eab4 feat(repository): added Set and Map backed by custom on-disk hashtable (#2364)
* feat(repository): added bigmap Set and Map backed by custom on-disk hashtable

* additional test coverage for corner cases

* profile flags

* exclude bigmapbench from code coverage

* refactored based on conversation with Julio

The concern was that values stored on disk are not encrypted.

* bigmap.Map - implements encryption of values
* bigmap.Set - stores keys only, so no encryption necessary
* bigmap.internalMap - used as backing structure for Map and Set

* implemented benchmark with values
2022-09-10 15:47:53 +00:00

40 lines
982 B
Go

package bigmap
import "context"
// Set is a wrapper around Map that only supports Put() and Contains().
type Set struct {
inner *internalMap
}
// Put adds the element to a set, returns true if the element was added (as opposed to having
// existed before).
func (s *Set) Put(ctx context.Context, key []byte) bool {
return s.inner.PutIfAbsent(ctx, key, nil)
}
// Contains returns true if a given key exists in the set.
func (s *Set) Contains(key []byte) bool {
return s.inner.Contains(key)
}
// Close releases resources associated with the set.
func (s *Set) Close(ctx context.Context) {
s.inner.Close(ctx)
}
// NewSet creates new Set.
func NewSet(ctx context.Context) (*Set, error) {
return NewSetWithOptions(ctx, nil)
}
// NewSetWithOptions creates new Set with options.
func NewSetWithOptions(ctx context.Context, opt *Options) (*Set, error) {
inner, err := newInternalMapWithOptions(ctx, false, opt)
if err != nil {
return nil, err
}
return &Set{inner}, nil
}