inmemory

package
v0.0.59 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InverseIndexType       = "inverse"
	InverseUniqueIndexType = "inverse_unique"
	SortdIndexType         = "sorted"
	SuffixIndexType        = "suffix"
)

Variables

This section is empty.

Functions

func NewSuffixIndex

func NewSuffixIndex[T d](cache Cache[T], btreeDegree int, from []string, to *string) (SuffixIndex[T], SuffixIndex[T])

Types

type AddCallbackListener added in v0.0.56

type AddCallbackListener[T d] struct {
	// contains filtered or unexported fields
}

func NewAddCallbackListener added in v0.0.56

func NewAddCallbackListener[T d](callback func(ctx context.Context, v T)) *AddCallbackListener[T]

func (*AddCallbackListener[T]) Add added in v0.0.56

func (s *AddCallbackListener[T]) Add(ctx context.Context, v T)

func (*AddCallbackListener[T]) Delete added in v0.0.56

func (s *AddCallbackListener[T]) Delete(ctx context.Context, _id primitive.ObjectID)

func (*AddCallbackListener[T]) Update added in v0.0.56

func (s *AddCallbackListener[T]) Update(ctx context.Context, _id primitive.ObjectID, updatedFields T, removedFields []string)

type Cache

type Cache[T d] interface {
	All(ctx context.Context) (ids []string)
	Get(ctx context.Context, id string) (b T, found bool)
	GetByIndex(ctx context.Context, idx int) (r T, f bool)
	GetIndexByID(id string) (idx int, found bool)
	GetIDByIndex(idx int) (id string, found bool)
	Add(ctx context.Context, v T)
	Update(ctx context.Context, _id primitive.ObjectID, updatedFields T, removedFields []string)
	Delete(ctx context.Context, _id primitive.ObjectID)
}

func NewCache

func NewCache[T d](
	data map[string]T,
) Cache[T]

NewCache ...

type CacheWithEventListener

type CacheWithEventListener[T d] struct {
	Cache                Cache[T]
	EventListener        EventListener[T]
	Notify               Notify[T]
	InverseIndexes       map[string]InverseIndex[T]
	InverseUniqueIndexes map[string]InverseUniqueIndex[T]
	SortedIndexes        map[string]SortedIndex[T]
	SuffixIndexes        map[string]SuffixIndex[T]
	AwaitNotify          Notify[T]
}

CacheWithEventListener ...

func NewCacheWithEventListener

func NewCacheWithEventListener[T d](
	beforeListeners []StreamEventListener[T],
	afterListeners []StreamEventListener[T],
	notify Notify[T],
) *CacheWithEventListener[T]

NewCacheWithEventListener ...

type DeleteCallbackListener added in v0.0.56

type DeleteCallbackListener[T d] struct {
	// contains filtered or unexported fields
}

func NewDeleteCallbackListener added in v0.0.56

func NewDeleteCallbackListener[T d](callback func(ctx context.Context, id string)) *DeleteCallbackListener[T]

func (*DeleteCallbackListener[T]) Add added in v0.0.56

func (s *DeleteCallbackListener[T]) Add(ctx context.Context, v T)

func (*DeleteCallbackListener[T]) Delete added in v0.0.56

func (s *DeleteCallbackListener[T]) Delete(ctx context.Context, _id primitive.ObjectID)

func (*DeleteCallbackListener[T]) Update added in v0.0.56

func (s *DeleteCallbackListener[T]) Update(ctx context.Context, _id primitive.ObjectID, updatedFields T, removedFields []string)

type Entity

type Entity[T d] struct {
	Collection      string
	BeforeListeners []StreamEventListener[T]
	AfterListeners  []StreamEventListener[T]
	Notify          Notify[T]
	Option          func(InMemory[T])
}

Entity ...

type EventListener

type EventListener[T d] interface {
	StreamEventListener[T]
	AddListener(listener StreamEventListener[T], before bool) (idx int)
}

type F

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

F ...

func (*F) Less

func (a *F) Less(than btree.Item) bool

Less ...

func (*F) Reset

func (a *F) Reset()

Reset ...

type Idx

type Idx struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Idx ...

func NewIdx

func NewIdx(
	maxIdx *atomic.Int64,
	itemsByIndex map[int64]string,
	indexByID map[string]int64,
) *Idx

NewIdx ...

func (*Idx) GetIDByIndex

func (c *Idx) GetIDByIndex(idx int) (id string, found bool)

GetIDByIndex ...

func (*Idx) GetIndexByID

func (c *Idx) GetIndexByID(id string) (idx int, found bool)

GetIndexByID ...

type InMemory

type InMemory[T d] interface {
	GetCacheWithEventListener() *CacheWithEventListener[T]
	GetMongo() *mongo.Mongo[T]
	Spawn(ctx context.Context) T
	AwaitCreate(ctx context.Context, ps T) (id string, err error)
	AwaitUpdate(ctx context.Context, ps T) (res T, err error)
	AwaitUpdateDoc(ctx context.Context, id string, set, unset bson.D) (found bool, err error)
	AwaitDelete(ctx context.Context, ps T) (err error)
}

func NewInMemory

func NewInMemory[T d](ctx context.Context, stream stream, deps MongoDeps, entityDeps Entity[T]) (InMemory[T], error)

NewInMemory ...

type Intersect

type Intersect struct {
}

Intersect ...

func NewIntersect

func NewIntersect() *Intersect

NewIntersect ...

func (*Intersect) Intersect

func (s *Intersect) Intersect(in1 []string, in ...[]string) (res []string)

Intersect ...

func (*Intersect) IntersectInt

func (s *Intersect) IntersectInt(in1, in2 []int) (res []int)

IntersectInt ...

func (*Intersect) LeftOutter added in v0.0.53

func (s *Intersect) LeftOutter(in1, in2 []string) (res []string)

func (*Intersect) Union

func (s *Intersect) Union(in1, in2 []string) (res []string)

Union ...

func (*Intersect) UnionInt

func (s *Intersect) UnionInt(in1, in2 []int) (res []int)

UnionInt ...

type InverseIndex

type InverseIndex[T d] interface {
	StreamEventListener[T]
	Get(ctx context.Context, val ...*string) (ids []string)
}

func NewInverseIndex

func NewInverseIndex[T d](
	data map[string][]string,
	nilData []string,
	cache Cache[T],
	from []string,
	to *string,
) InverseIndex[T]

type InverseUniqueIndex added in v0.0.10

type InverseUniqueIndex[T d] interface {
	StreamEventListener[T]
	Get(ctx context.Context, val ...string) (id string, found bool)
}

func NewInverseUniqIndex

func NewInverseUniqIndex[T d](
	data map[string]string,
	cache Cache[T],
	field []string,
	to *string,
) InverseUniqueIndex[T]

type Listener

type Listener[T d] struct {
	// contains filtered or unexported fields
}

Listener ...

func NewListener

func NewListener[T d](cache Cache[T]) *Listener[T]

NewListener ...

func (*Listener[T]) Add

func (c *Listener[T]) Add(ctx context.Context, v T)

Add ...

func (*Listener[T]) AddListener

func (c *Listener[T]) AddListener(listener StreamEventListener[T], before bool) (idx int)

AddListener ...

func (*Listener[T]) Delete

func (c *Listener[T]) Delete(ctx context.Context, _id primitive.ObjectID)

Delete ...

func (*Listener[T]) Update

func (c *Listener[T]) Update(ctx context.Context, _id primitive.ObjectID, updatedFields T, removedFields []string)

Update ...

type M

type M interface {
	Add(id string, title string)
	Update(id string, title string)
	Delete(id string, text string)
	Search(ctx context.Context, text string) (items []string)
	Find(ctx context.Context, text string) (items []string)
}

func BuildM added in v0.0.22

func BuildM[T d](cache Cache[T]) M

func NewM

func NewM[T d](
	cache Cache[T],
	tree suffixTree,
) M

type MongoDeps

type MongoDeps struct {
	Client            *mng.Client
	Db                string
	ConnectionTimeout time.Duration
}

type Notifier

type Notifier[T d] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Notifier используется для ожидания обновления в кеше например, надо произвести запись в хранилище и дождаться обновления в inmemory 1) подписались на notify 2) сделали запись в хранилище 3) дождались обновления в inmemory подписка на ожидание самостоятельно удаляется

func NewNotifier

func NewNotifier[T d](
	listenersCreate map[string]map[string]func(),
	listenersUpdate map[string]map[string]func(),
	listenersDelete map[string]map[string]func(),
) *Notifier[T]

NewNotifier ...

func (*Notifier[T]) Add

func (s *Notifier[T]) Add(ctx context.Context, v T)

Add ...

func (*Notifier[T]) AddListenerCreate

func (s *Notifier[T]) AddListenerCreate(id string, c func()) string

AddListenerCreate ...

func (*Notifier[T]) AddListenerDelete

func (s *Notifier[T]) AddListenerDelete(id string, c func()) string

AddListenerDelete ...

func (*Notifier[T]) AddListenerUpdate

func (s *Notifier[T]) AddListenerUpdate(id string, c func()) string

AddListenerUpdate ...

func (*Notifier[T]) Delete

func (s *Notifier[T]) Delete(ctx context.Context, _id primitive.ObjectID)

Delete ...

func (*Notifier[T]) DeleteListenerCreate

func (s *Notifier[T]) DeleteListenerCreate(id, ui string)

func (*Notifier[T]) DeleteListenerDelete

func (s *Notifier[T]) DeleteListenerDelete(id, ui string)

func (*Notifier[T]) DeleteListenerUpdate

func (s *Notifier[T]) DeleteListenerUpdate(id, ui string)

func (*Notifier[T]) Update

func (s *Notifier[T]) Update(ctx context.Context, _id primitive.ObjectID, updatedFields T, removedFields []string)

Update ...

type Notify

type Notify[T d] interface {
	StreamEventListener[T]
	AddListenerCreate(id string, c func()) string
	AddListenerUpdate(id string, c func()) string
	AddListenerDelete(id string, c func()) string
	DeleteListenerCreate(id, ui string)
	DeleteListenerUpdate(id, ui string)
	DeleteListenerDelete(id, ui string)
}

Notify ...

type Pool

type Pool struct {
	sync.Pool
}

Pool ...

func NewPool

func NewPool() *Pool

NewPool ...

func (*Pool) Acquire

func (p *Pool) Acquire() *F

Acquire ...

func (*Pool) Release

func (p *Pool) Release(req *F)

Release ...

type S

type S struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

S ...

func NewS

func NewS(
	intersect intersect,
	data *btree.BTree,
	pool *Pool,
) *S

NewS ...

func (*S) Delete added in v0.0.38

func (a *S) Delete(in string, idx int)

func (*S) Find added in v0.0.48

func (a *S) Find(in string) (out []int)

func (*S) Put

func (a *S) Put(in string, idx int)

Put ...

func (*S) Reset

func (a *S) Reset()

Reset ...

func (*S) Search

func (a *S) Search(in string) (out []int)

Search ...

type Sorted added in v0.0.24

type Sorted interface {
	Intersect(in []string) (res []string)
	Add(ctx context.Context, id string, title string)
	Update(ctx context.Context, id string, old string, title string)
	Delete(ctx context.Context, id string, title string)
}

func BuildSorted added in v0.0.23

func BuildSorted() Sorted

func NewSorted added in v0.0.23

func NewSorted(degree int, ids []string) Sorted

type SortedIndex

type SortedIndex[T d] interface {
	StreamEventListener[T]
	Intersect(in []string) (res []string)
}

func NewSortedIndex

func NewSortedIndex[T d](
	sorted Sorted,
	cache Cache[T],
	from []string,
	to *string,
) SortedIndex[T]

NewSortedIndex ...

type StreamEventListener added in v0.0.10

type StreamEventListener[T d] interface {
	Add(ctx context.Context, v T)
	Update(ctx context.Context, _id primitive.ObjectID, updatedFields T, removedFields []string)
	Delete(ctx context.Context, _id primitive.ObjectID)
}

StreamEventListener ...

type Suffix

type Suffix[T d] struct {
	M
	// contains filtered or unexported fields
}

func (*Suffix[T]) Add

func (s *Suffix[T]) Add(ctx context.Context, it T)

Add ...

func (*Suffix[T]) Delete

func (s *Suffix[T]) Delete(ctx context.Context, _id primitive.ObjectID)

Delete ...

func (*Suffix[T]) Find added in v0.0.49

func (s *Suffix[T]) Find(ctx context.Context, text string) (items []string)

func (*Suffix[T]) Search

func (s *Suffix[T]) Search(ctx context.Context, text string) (items []string)

Search ...

func (*Suffix[T]) Update

func (s *Suffix[T]) Update(ctx context.Context, id primitive.ObjectID, updatedFields T, removedFields []string)

Update ...

type SuffixIndex added in v0.0.10

type SuffixIndex[T d] interface {
	StreamEventListener[T]
	Search(ctx context.Context, text string) (items []string)
	Find(ctx context.Context, text string) (items []string)
}

func NewSuffix

func NewSuffix[T d](index M, cache Cache[T], from []string, to *string) SuffixIndex[T]

func NewUpdateSuffix added in v0.0.38

func NewUpdateSuffix[T d](index M, cache Cache[T], from []string, to *string) SuffixIndex[T]

type UpdateCallbackListener added in v0.0.56

type UpdateCallbackListener[T d] struct {
	// contains filtered or unexported fields
}

func NewUpdateCallbackListener added in v0.0.56

func NewUpdateCallbackListener[T d](callback func(ctx context.Context, id string, v T, removedFields []string)) *UpdateCallbackListener[T]

func (*UpdateCallbackListener[T]) Add added in v0.0.56

func (s *UpdateCallbackListener[T]) Add(ctx context.Context, v T)

func (*UpdateCallbackListener[T]) Delete added in v0.0.56

func (s *UpdateCallbackListener[T]) Delete(ctx context.Context, _id primitive.ObjectID)

func (*UpdateCallbackListener[T]) Update added in v0.0.56

func (s *UpdateCallbackListener[T]) Update(ctx context.Context, _id primitive.ObjectID, updatedFields T, removedFields []string)

type UpdateSuffix added in v0.0.38

type UpdateSuffix[T d] struct {
	M
	// contains filtered or unexported fields
}

func (*UpdateSuffix[T]) Add added in v0.0.38

func (s *UpdateSuffix[T]) Add(ctx context.Context, it T)

func (*UpdateSuffix[T]) Delete added in v0.0.38

func (s *UpdateSuffix[T]) Delete(ctx context.Context, _id primitive.ObjectID)

func (*UpdateSuffix[T]) Search added in v0.0.38

func (s *UpdateSuffix[T]) Search(ctx context.Context, text string) (items []string)

func (*UpdateSuffix[T]) Update added in v0.0.38

func (s *UpdateSuffix[T]) Update(ctx context.Context, id primitive.ObjectID, updatedFields T, removedFields []string)

Update удаляет старое значение из индекса сделано так, потому что основной суффиксный индекс включается в цепочку после обновления кеша а удалить данные мы можем только до обновления кеша, чтобы иметь в кеше старые данные с помощью такого решения мы ухоидим от необходимости ребилда кеша, он у нас актуальный всегда

Jump to

Keyboard shortcuts

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