lightdiffstore

package
v0.0.0-...-edb81cd Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: Apache-2.0 Imports: 3 Imported by: 7

Documentation

Index

Examples

Constants

View Source
const (
	ItemDeleted   ItemState = iota
	ItemChanged             = 1
	ItemUnchanged           = 2
)
View Source
const DefaultSeparator = '|'

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffStore

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

DiffStore tracks changes by prefix and sub keys

Example
s := New()

set := func(k, v string) {
	fmt.Printf("set %v to %s\n", k, v)
	s.Set([]byte(k), xxhash.Sum64([]byte(v)), v)
}

set("a", "alice")
set("b", "bob")

fmt.Println("-> updated:", s.Updated(), "deleted:", s.Deleted())

// --------------------------------------------------------------------------
fmt.Println()
s.Reset(ItemUnchanged)

set("a", "alice2")

fmt.Println("-> updated:", s.Updated(), "deleted:", s.Deleted())

// --------------------------------------------------------------------------
fmt.Println()
s.Reset(ItemDeleted)

set("a", "alice3")

fmt.Println("-> updated:", s.Updated(), "deleted:", s.Deleted())

// --------------------------------------------------------------------------
fmt.Println()
s.Reset(ItemDeleted)

set("a", "alice3")
set("b", "bob")

fmt.Println("-> updated:", s.Updated(), "deleted:", s.Deleted())

// double reset will remove all entries (and should not crash)
s.Reset(ItemDeleted)
s.Reset(ItemDeleted)

fmt.Println("tree size after double reset:", s.tree.Len())
Output:

set a to alice
set b to bob
-> updated: [{a => alice} {b => bob}] deleted: []

set a to alice2
-> updated: [{a => alice2}] deleted: []

set a to alice3
-> updated: [{a => alice3}] deleted: [{b => bob}]

set a to alice3
set b to bob
-> updated: [{b => bob}] deleted: []
tree size after double reset: 0

func New

func New() *DiffStore

func (*DiffStore) Delete

func (s *DiffStore) Delete(key []byte)

Delete an entry from the store

func (*DiffStore) DeleteByPrefix

func (s *DiffStore) DeleteByPrefix(prefix []byte)

DeleteByPrefix removes all entries with the given prefix from the store

func (*DiffStore) Deleted

func (s *DiffStore) Deleted() (deleted []KV)

Updated returns all the entries that where deleted since the last Reset.

func (*DiffStore) GetByPrefix

func (s *DiffStore) GetByPrefix(prefix []byte) (items []KV)

GetByPrefix returns all the entries with the given prefix.

func (*DiffStore) Reset

func (s *DiffStore) Reset(state ItemState)

Reset the store to clear, marking all entries with the given state (and removing previously deleted ones)

func (*DiffStore) Set

func (s *DiffStore) Set(key []byte, hash uint64, value interface{})

Set insert or update a key/value in the store

func (*DiffStore) Updated

func (s *DiffStore) Updated() (updated []KV)

Updated returns all the entries that where updated since the last Reset.

type ItemState

type ItemState int

type KV

type KV struct {
	Key   []byte
	Value interface{}
}

func (*KV) Less

func (a *KV) Less(bItem btree.Item) bool

func (KV) String

func (a KV) String() string

Jump to

Keyboard shortcuts

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