Documentation ¶
Overview ¶
Package mcp defines the Modification Candidate Pool (MCP).
Index ¶
- Variables
- type ModificationCandidatePool
- type UniqueKey
- func (uk *UniqueKey) Clone() *UniqueKey
- func (uk *UniqueKey) GetRowID() int
- func (uk *UniqueKey) GetValue() map[string]interface{}
- func (uk *UniqueKey) GetValueHash() string
- func (uk *UniqueKey) IsValueEqual(otherUK *UniqueKey) bool
- func (uk *UniqueKey) SetRowID(rowID int)
- func (uk *UniqueKey) SetValue(value map[string]interface{})
- func (uk *UniqueKey) String() string
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
Clone is to clone a UK into a new one. So that two UK objects are not interfered with each other.
func (*UniqueKey) GetRowID ¶
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 ¶
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 ¶
GetValueHash return hash for values.
func (*UniqueKey) IsValueEqual ¶
IsValueEqual tests whether two UK's value parts are equal.