generationstore

package
v0.0.0-...-bc30bd0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanFunc

type CleanFunc func()

CleanFunc defines the cleanup function used in UpdateRawStore.

func DefaultCleanFunc

func DefaultCleanFunc(cache ListStore, snapshot RawStore) CleanFunc

DefaultCleanFunc is to remove all the elements that no longer exist in the ListStore but are still in the RawStore.

type CloneFunc

type CloneFunc func(string, StoredObj)

CloneFunc defines the clone function used in UpdateRawStore.

type HashStore

type HashStore map[string]StoredObj

HashStore defines the data model used for traversal.

type ListItem

type ListItem struct {

	// StoreObj holds the real object.
	StoredObj
	// contains filtered or unexported fields
}

------------------- ListItem -------------------

func (*ListItem) Next

func (item *ListItem) Next() *ListItem

func (*ListItem) Obj

func (item *ListItem) Obj() StoredObj

type ListStore

type ListStore interface {
	Store
	Front() *ListItem
	UpdateRawStore(RawStore, CloneFunc, CleanFunc)
}

ListStore defines the methods of ListStore. ATTENTION: We need to control the lock of this data structure at the upper level.

func NewListStore

func NewListStore() ListStore

type ListStoreImpl

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

ListStoreImpl implement the ListStore interface. We will store all the objects in hashmap and linked-list, and maintain the StoredObj's generation according to ListStoreImpl.generation. And the linked-list will be organized in descending order of generation.

func (*ListStoreImpl) ConditionRange

func (s *ListStoreImpl) ConditionRange(f StoreConditionRangeFunc) bool

func (*ListStoreImpl) Delete

func (s *ListStoreImpl) Delete(key string)

func (*ListStoreImpl) Front

func (s *ListStoreImpl) Front() *ListItem

func (*ListStoreImpl) Get

func (s *ListStoreImpl) Get(key string) StoredObj

func (*ListStoreImpl) Keys

func (s *ListStoreImpl) Keys() []string

func (*ListStoreImpl) Len

func (s *ListStoreImpl) Len() int

func (*ListStoreImpl) Range

func (s *ListStoreImpl) Range(f StoreRangeFunc)

func (*ListStoreImpl) Set

func (s *ListStoreImpl) Set(key string, obj StoredObj)

Set will update the ListItem if it has been existed, or create a new ListItem to hold it. The ListStoreImpl.generation will be updated and the ListItem will be moved to head.

func (*ListStoreImpl) String

func (s *ListStoreImpl) String() string

func (*ListStoreImpl) UpdateRawStore

func (s *ListStoreImpl) UpdateRawStore(store RawStore, cloneFunc CloneFunc, cleanFunc CleanFunc)

UpdateRawStore update RawStore according the generation. We will update the RawStore by linked-list firstly, and by RawStore.UpdatedSet. Finally refresh the RawStore.generation and do cleanup.

type RawStore

type RawStore interface {
	Store
	SetGeneration(int64)
	GetGeneration() int64
	UpdatedSet() sets.String
	ResetUpdatedSet()
}

RawStore defines the methods of RawStore. ATTENTION: We need to control the lock of this data structure at the upper level.

func NewRawStore

func NewRawStore() RawStore

type RawStoreImpl

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

RawStoreImpl implement the RawStore interface. StoredObj will be stored in a raw hashmap, and RawStoreImpl.generation hold the max-generation of these items. ATTENTION: We need to control the lock of this data structure at the upper level.

func (*RawStoreImpl) ConditionRange

func (s *RawStoreImpl) ConditionRange(f StoreConditionRangeFunc) bool

func (*RawStoreImpl) Delete

func (s *RawStoreImpl) Delete(key string)

func (*RawStoreImpl) Get

func (s *RawStoreImpl) Get(key string) StoredObj

func (*RawStoreImpl) GetGeneration

func (s *RawStoreImpl) GetGeneration() int64

func (*RawStoreImpl) Keys

func (s *RawStoreImpl) Keys() []string

func (*RawStoreImpl) Len

func (s *RawStoreImpl) Len() int

func (*RawStoreImpl) Range

func (s *RawStoreImpl) Range(f StoreRangeFunc)

func (*RawStoreImpl) ResetUpdatedSet

func (s *RawStoreImpl) ResetUpdatedSet()

func (*RawStoreImpl) Set

func (s *RawStoreImpl) Set(key string, obj StoredObj)

func (*RawStoreImpl) SetGeneration

func (s *RawStoreImpl) SetGeneration(generation int64)

func (*RawStoreImpl) String

func (s *RawStoreImpl) String() string

func (*RawStoreImpl) UpdatedSet

func (s *RawStoreImpl) UpdatedSet() sets.String

type Store

type Store interface {
	Get(string) StoredObj
	Set(string, StoredObj)
	Delete(string)
	Len() int
	Keys() []string
	String() string
	Range(StoreRangeFunc)
	ConditionRange(StoreConditionRangeFunc) bool
}

Store defines the field that the some-datastructure will hold if it needs generationstore. The Store field's real object is either ListStore or RawStore. ATTENTION: We need to control the lock of this data structure at the upper level.

type StoreConditionRangeFunc

type StoreConditionRangeFunc func(string, StoredObj) bool

The return value of StoreConditionRangeFunc means whether to continue the traversal process.

type StoreRangeFunc

type StoreRangeFunc func(string, StoredObj)

type StoredObj

type StoredObj interface {
	GetGeneration() int64
	SetGeneration(int64)
}

StoredObj defines the methods that all the objects stored in the generationstore must have.

Jump to

Keyboard shortcuts

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