diffstore

package
v0.0.0-...-c7476d4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyLeaf

type AnyLeaf[T any] struct {
	// contains filtered or unexported fields
}

func NewAnyLeaf

func NewAnyLeaf[T any](equal func(a, b T) bool) *AnyLeaf[T]

func (*AnyLeaf[T]) Get

func (l *AnyLeaf[T]) Get() T

func (*AnyLeaf[T]) Hash

func (l *AnyLeaf[T]) Hash() uint64

func (*AnyLeaf[T]) Reset

func (l *AnyLeaf[T]) Reset()

func (*AnyLeaf[T]) Set

func (l *AnyLeaf[T]) Set(v T)

func (*AnyLeaf[T]) String

func (l *AnyLeaf[T]) String() string

type BufferLeaf

type BufferLeaf struct {
	bytes.Buffer
}
Example
bl := NewBufferLeaf()

fmt.Fprintf(bl, "hello %d %.2f", 1, math.Pi)

fmt.Println("[", bl, "]")
Output:

[ hello 1 3.14 ]

func NewBufferLeaf

func NewBufferLeaf() *BufferLeaf

func (*BufferLeaf) Hash

func (l *BufferLeaf) Hash() uint64

func (*BufferLeaf) Reset

func (l *BufferLeaf) Reset()

func (*BufferLeaf) Writeln

func (l *BufferLeaf) Writeln()

type Item

type Item[K constraints.Ordered, V Leaf] struct {
	// contains filtered or unexported fields
}

func (*Item[K, V]) Changed

func (i *Item[K, V]) Changed() bool

func (*Item[K, V]) Created

func (i *Item[K, V]) Created() bool

func (*Item[K, V]) Defer

func (i *Item[K, V]) Defer(f func(V))

func (*Item[K, V]) Deleted

func (i *Item[K, V]) Deleted() bool

func (*Item[K, V]) Key

func (i *Item[K, V]) Key() K

func (*Item[K, V]) Less

func (i1 *Item[K, V]) Less(i btree.Item) bool

func (*Item[K, V]) RunDeferred

func (i *Item[K, V]) RunDeferred()

func (*Item[K, V]) Updated

func (i *Item[K, V]) Updated() bool

func (*Item[K, V]) Value

func (i *Item[K, V]) Value() V

type JSONLeaf

type JSONLeaf[T any] struct {
	// contains filtered or unexported fields
}

func NewJSONLeaf

func NewJSONLeaf[T any]() *JSONLeaf[T]

func (*JSONLeaf[T]) Get

func (l *JSONLeaf[T]) Get() T

func (*JSONLeaf[T]) Hash

func (l *JSONLeaf[T]) Hash() uint64

func (*JSONLeaf[T]) Reset

func (l *JSONLeaf[T]) Reset()

func (*JSONLeaf[T]) Set

func (l *JSONLeaf[T]) Set(v T)

func (*JSONLeaf[T]) String

func (l *JSONLeaf[T]) String() string

type Leaf

type Leaf interface {
	Reset()
	Hash() uint64
}

type Store

type Store[K constraints.Ordered, V Leaf] struct {
	// contains filtered or unexported fields
}
Example
store := NewBufferStore[string]()

{
	fmt.Fprint(store.Get("a"), "hello a")

	store.Done()
	store.printDiff()
}

{
	store.Reset()

	fmt.Fprint(store.Get("a"), "hello a")

	store.Done()
	store.printDiff()
}

{
	store.Reset()

	fmt.Fprint(store.Get("a"), "hello a")
	fmt.Fprint(store.Get("b"), "hello b")

	store.Done()
	store.printDiff()
}

{
	store.Reset()

	fmt.Fprint(store.Get("a"), "hi a")

	store.Done()
	store.printDiff()
}

{
	store.Reset()

	fmt.Fprint(store.Get("b"), "hi b")

	store.Done()
	store.printDiff()
}

{
	store.Reset()

	store.Done()
	store.printDiff()
}
Output:

-----
C a => "hello a"
-----
<same>
-----
C b => "hello b"
-----
U a => "hi a"
D b
-----
C b => "hi b"
D a
-----
D b

func New

func New[K constraints.Ordered, V Leaf](newValue func() V) *Store[K, V]

func NewAnyStore

func NewAnyStore[K constraints.Ordered, T any](equal func(a, b T) bool) *Store[K, *AnyLeaf[T]]

func NewBufferStore

func NewBufferStore[K constraints.Ordered]() *Store[K, *BufferLeaf]

func NewJSONStore

func NewJSONStore[K constraints.Ordered, T any]() *Store[K, *JSONLeaf[T]]

func (*Store[K, V]) Changed

func (s *Store[K, V]) Changed() (ret []*Item[K, V])

Changed returns every entry that was created or updated

func (*Store[K, V]) Deleted

func (s *Store[K, V]) Deleted() (ret []*Item[K, V])

func (*Store[K, V]) Done

func (s *Store[K, V]) Done()

Done must be called at the end of the filling process. It will compute hashes of every node to allow diff functions to work.

func (*Store[K, V]) Get

func (s *Store[K, V]) Get(key K) V

func (*Store[K, V]) GetItem

func (s *Store[K, V]) GetItem(key K) *Item[K, V]

func (*Store[K, V]) Has

func (s *Store[K, V]) Has(key K) bool

func (*Store[K, V]) HasChanges

func (s *Store[K, V]) HasChanges() (changed bool)

func (*Store[K, V]) List

func (s *Store[K, V]) List() (ret []*Item[K, V])

func (*Store[K, V]) Reset

func (s *Store[K, V]) Reset()

func (*Store[K, V]) RunDeferred

func (s *Store[K, V]) RunDeferred()

Jump to

Keyboard shortcuts

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