mcp

package
v0.0.0-...-be15534 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package mcp defines the Modification Candidate Pool (MCP).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMCPCapacityFull means the capacity of the modification candidate pool (MCP) is full.
	ErrMCPCapacityFull = errors.New("the capacity of the modification candidate pool is full")
	// ErrInvalidRowID means the row ID of the unique key is invalid.
	// For example, when the row ID is greater than the current MCP size, this error will be triggered.
	ErrInvalidRowID = errors.New("invalid row ID")
	// ErrDeleteUKNotFound means the unique key to be deleted is not found in the MCP.
	ErrDeleteUKNotFound = errors.New("delete UK not found")
)

Functions

This section is empty.

Types

type ModificationCandidatePool

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

ModificationCandidatePool is the core container storing all the current unique keys for a table.

func NewModificationCandidatePool

func NewModificationCandidatePool(capcity int) *ModificationCandidatePool

NewModificationCandidatePool create a new MCP.

func (*ModificationCandidatePool) AddUK

func (mcp *ModificationCandidatePool) AddUK(uk *UniqueKey) error

AddUK adds the unique key into the MCP. It has side effect: the input UK's row ID will be changed.

func (*ModificationCandidatePool) DeleteUK

func (mcp *ModificationCandidatePool) DeleteUK(uk *UniqueKey) error

DeleteUK deletes the unique key from the MCP. It will get the row ID of the UK and delete the UK on that position. If the actual value is different from the input UK, the element will still be deleted. It has side effect: after the deletion, the input UK's row ID will be set to -1, to prevent deleting a dangling UK multiple times.

func (*ModificationCandidatePool) Len

func (mcp *ModificationCandidatePool) Len() int

Len gets the current length of the MCP.

func (*ModificationCandidatePool) NextUK

func (mcp *ModificationCandidatePool) NextUK() *UniqueKey

NextUK randomly picks a unique key in the MCP.

func (*ModificationCandidatePool) Reset

func (mcp *ModificationCandidatePool) Reset()

Reset cleans up all the items in the MCP.

type UniqueKey

type UniqueKey struct {
	// It inherits a RWMutex, which is used to modify the metadata inside the UK struct.
	sync.RWMutex
	// contains filtered or unexported fields
}

UniqueKey is the data structure describing a unique key.

func NewUniqueKey

func NewUniqueKey(rowID int, value map[string]interface{}) *UniqueKey

NewUniqueKey creates a new unique key instance. the map values are cloned into the new UK instance, so that the further changes in the value map won't affect the values inside the UK.

func (*UniqueKey) Clone

func (uk *UniqueKey) Clone() *UniqueKey

Clone is to clone a UK into a new one. So that two UK objects are not interfered with each other.

func (*UniqueKey) GetRowID

func (uk *UniqueKey) GetRowID() int

GetRowID gets the row ID of the unique key. The row ID is a virtual concept, not the real row ID for a DB table. Usually it is used to locate the index in an MCP.

func (*UniqueKey) GetValue

func (uk *UniqueKey) GetValue() map[string]interface{}

GetValue gets the UK value map of a unique key. The returned value is cloned, so that further modifications won't affect the value inside the UK.

func (*UniqueKey) GetValueHash

func (uk *UniqueKey) GetValueHash() string

GetValueHash return hash for values.

func (*UniqueKey) IsValueEqual

func (uk *UniqueKey) IsValueEqual(otherUK *UniqueKey) bool

IsValueEqual tests whether two UK's value parts are equal.

func (*UniqueKey) SetRowID

func (uk *UniqueKey) SetRowID(rowID int)

SetRowID sets the row ID of the unique key.

func (*UniqueKey) SetValue

func (uk *UniqueKey) SetValue(value map[string]interface{})

SetValue sets the UK value map. The input values are cloned into the UK, and further modifications on the input map won't affect the values inside the UK.

func (*UniqueKey) String

func (uk *UniqueKey) String() string

String returns the string representation of a UK.

Jump to

Keyboard shortcuts

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