Deduplicate state block contents

This commit is contained in:
Neil Alexander 2021-04-15 15:51:15 +01:00
parent dbd53fa9ff
commit 6900e0f495
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
10 changed files with 277 additions and 344 deletions

View file

@ -40,6 +40,13 @@ type StateSnapshotNID int64
// These blocks of state data are combined to form the actual state.
type StateBlockNID int64
// StateBlockNIDs is used to sort and dedupe state block NIDs.
type StateBlockNIDs []StateBlockNID
func (a StateBlockNIDs) Len() int { return len(a) }
func (a StateBlockNIDs) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a StateBlockNIDs) Less(i, j int) bool { return a[i] < a[j] }
// A StateKeyTuple is a pair of a numeric event type and a numeric state key.
// It is used to lookup state entries.
type StateKeyTuple struct {
@ -65,6 +72,12 @@ type StateEntry struct {
EventNID EventNID
}
type StateEntries []StateEntry
func (a StateEntries) Len() int { return len(a) }
func (a StateEntries) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a StateEntries) Less(i, j int) bool { return a[i].EventNID < a[j].EventNID }
// LessThan returns true if this state entry is less than the other state entry.
// The ordering is arbitrary and is used to implement binary search and to efficiently deduplicate entries.
func (a StateEntry) LessThan(b StateEntry) bool {