style: errors, collections (#15640)
This commit is contained in:
parent
528ce31eeb
commit
622ebf4df0
@ -14,10 +14,9 @@ func (b boolKey[T]) Encode(buffer []byte, key T) (int, error) {
|
||||
if key {
|
||||
buffer[0] = 0x1
|
||||
return 1, nil
|
||||
} else {
|
||||
buffer[0] = 0x0
|
||||
return 1, nil
|
||||
}
|
||||
buffer[0] = 0x0
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
func (b boolKey[T]) Decode(buffer []byte) (int, T, error) {
|
||||
|
||||
@ -38,10 +38,10 @@ type IndexedMap[PrimaryKey, Value any, Idx Indexes[PrimaryKey, Value]] struct {
|
||||
}
|
||||
|
||||
// NewIndexedMap instantiates a new IndexedMap. Accepts a SchemaBuilder, a Prefix,
|
||||
// a humanised name that defines the name of the collection, the primary key codec
|
||||
// a humanized name that defines the name of the collection, the primary key codec
|
||||
// which is basically what IndexedMap uses to encode the primary key to bytes,
|
||||
// the value codec which is what the IndexedMap uses to encode the value.
|
||||
// Then it expects the initialised indexes.
|
||||
// Then it expects the initialized indexes.
|
||||
func NewIndexedMap[PrimaryKey, Value any, Idx Indexes[PrimaryKey, Value]](
|
||||
schema *SchemaBuilder,
|
||||
prefix Prefix,
|
||||
@ -112,7 +112,7 @@ func (m *IndexedMap[PrimaryKey, Value, Idx]) ValueCodec() codec.ValueCodec[Value
|
||||
|
||||
func (m *IndexedMap[PrimaryKey, Value, Idx]) ref(ctx context.Context, pk PrimaryKey, value Value) error {
|
||||
for _, index := range m.Indexes.IndexesList() {
|
||||
err := index.Reference(ctx, pk, value, cachedGet[PrimaryKey, Value](m, ctx, pk))
|
||||
err := index.Reference(ctx, pk, value, cachedGet[PrimaryKey, Value](ctx, m, pk))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -122,7 +122,7 @@ func (m *IndexedMap[PrimaryKey, Value, Idx]) ref(ctx context.Context, pk Primary
|
||||
|
||||
func (m *IndexedMap[PrimaryKey, Value, Idx]) unref(ctx context.Context, pk PrimaryKey) error {
|
||||
for _, index := range m.Indexes.IndexesList() {
|
||||
err := index.Unreference(ctx, pk, cachedGet[PrimaryKey, Value](m, ctx, pk))
|
||||
err := index.Unreference(ctx, pk, cachedGet[PrimaryKey, Value](ctx, m, pk))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -134,7 +134,7 @@ func (m *IndexedMap[PrimaryKey, Value, Idx]) unref(ctx context.Context, pk Prima
|
||||
// returns always the same result on multiple calls.
|
||||
func cachedGet[K, V any, M interface {
|
||||
Get(ctx context.Context, key K) (V, error)
|
||||
}](m M, ctx context.Context, key K,
|
||||
}](ctx context.Context, m M, key K,
|
||||
) func() (V, error) {
|
||||
var (
|
||||
value V
|
||||
|
||||
@ -26,7 +26,7 @@ type pairKeyCodec[K1, K2 any] interface {
|
||||
// NewReversePair instantiates a new ReversePair index.
|
||||
// NOTE: when using this function you will need to type hint: doing NewReversePair[Value]()
|
||||
// Example: if the value of the indexed map is string, you need to do NewReversePair[string](...)
|
||||
func NewReversePair[Value any, K1, K2 any](
|
||||
func NewReversePair[Value, K1, K2 any](
|
||||
sb *collections.SchemaBuilder,
|
||||
prefix collections.Prefix,
|
||||
name string,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user