backdata

package
v0.37.0-crescendo-RC5-... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2024 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapBackData

type MapBackData struct {
	// contains filtered or unexported fields
}

MapBackData implements a map-based generic memory BackData backed by a Go map. Note that this implementation is NOT thread-safe, and the higher-level Backend is responsible for concurrency management.

func NewMapBackData

func NewMapBackData() *MapBackData

func (*MapBackData) Add

func (b *MapBackData) Add(entityID flow.Identifier, entity flow.Entity) bool

Add adds the given entity to the backdata.

func (*MapBackData) Adjust

func (b *MapBackData) Adjust(entityID flow.Identifier, f func(flow.Entity) flow.Entity) (flow.Entity, bool)

Adjust adjusts the entity using the given function if the given identifier can be found. Returns a bool which indicates whether the entity was updated as well as the updated entity.

func (*MapBackData) AdjustWithInit added in v0.33.1

func (b *MapBackData) AdjustWithInit(entityID flow.Identifier, adjust func(flow.Entity) flow.Entity, init func() flow.Entity) (flow.Entity, bool)

AdjustWithInit adjusts the entity using the given function if the given identifier can be found. When the entity is not found, it initializes the entity using the given init function and then applies the adjust function. Args: - entityID: the identifier of the entity to adjust. - adjust: the function that adjusts the entity. - init: the function that initializes the entity when it is not found. Returns:

  • the adjusted entity.

- a bool which indicates whether the entity was adjusted.

func (*MapBackData) All

func (b *MapBackData) All() map[flow.Identifier]flow.Entity

All returns all entities stored in the backdata.

func (*MapBackData) ByID

func (b *MapBackData) ByID(entityID flow.Identifier) (flow.Entity, bool)

ByID returns the given entity from the backdata.

func (*MapBackData) Clear

func (b *MapBackData) Clear()

Clear removes all entities from the backdata.

func (*MapBackData) Entities

func (b *MapBackData) Entities() []flow.Entity

Entities returns the list of entities stored in the backdata.

func (*MapBackData) GetWithInit added in v0.33.1

func (b *MapBackData) GetWithInit(entityID flow.Identifier, init func() flow.Entity) (flow.Entity, bool)

GetWithInit returns the given entity from the backdata. If the entity does not exist, it creates a new entity using the factory function and stores it in the backdata. Args: - entityID: the identifier of the entity to get. - init: the function that initializes the entity when it is not found. Returns:

  • the entity.
  • a bool which indicates whether the entity was found (or created).

func (*MapBackData) Has

func (b *MapBackData) Has(entityID flow.Identifier) bool

Has checks if backdata already contains the entity with the given identifier.

func (*MapBackData) Identifiers

func (b *MapBackData) Identifiers() flow.IdentifierList

Identifiers returns the list of identifiers of entities stored in the backdata.

func (*MapBackData) Remove added in v0.27.0

func (b *MapBackData) Remove(entityID flow.Identifier) (flow.Entity, bool)

Remove removes the entity with the given identifier.

func (*MapBackData) Size

func (b *MapBackData) Size() uint

Size returns the size of the backdata, i.e., total number of stored (entityId, entity)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL