Documentation ¶
Index ¶
- Constants
- type DiffStore
- func (s *DiffStore) Delete(key []byte)
- func (s *DiffStore) DeleteByPrefix(prefix []byte)
- func (s *DiffStore) Deleted() (deleted []KV)
- func (s *DiffStore) GetByPrefix(prefix []byte) (items []KV)
- func (s *DiffStore) Reset(state ItemState)
- func (s *DiffStore) Set(key []byte, hash uint64, value interface{})
- func (s *DiffStore) Updated() (updated []KV)
- type ItemState
- type KV
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 (*DiffStore) DeleteByPrefix ¶
DeleteByPrefix removes all entries with the given prefix from the store
func (*DiffStore) Deleted ¶
Updated returns all the entries that where deleted since the last Reset.
func (*DiffStore) GetByPrefix ¶
GetByPrefix returns all the entries with the given prefix.
func (*DiffStore) Reset ¶
Reset the store to clear, marking all entries with the given state (and removing previously deleted ones)
Click to show internal directories.
Click to hide internal directories.