Documentation
¶
Overview ¶
Package moveslice provides helper functionality for slices of type Move (chess moves).
Index ¶
- type MoveSlice
- func (ms *MoveSlice) At(i int) Move
- func (ms *MoveSlice) Back() Move
- func (ms *MoveSlice) Cap() int
- func (ms *MoveSlice) Clear()
- func (ms *MoveSlice) Clone() *MoveSlice
- func (ms *MoveSlice) Equals(other *MoveSlice) bool
- func (ms *MoveSlice) Filter(f func(index int) bool)
- func (ms *MoveSlice) FilterCopy(dest *MoveSlice, f func(index int) bool)
- func (ms *MoveSlice) ForEach(f func(index int))
- func (ms *MoveSlice) ForEachParallel(f func(index int))
- func (ms *MoveSlice) Front() Move
- func (ms *MoveSlice) Len() int
- func (ms *MoveSlice) PopBack() Move
- func (ms *MoveSlice) PopFront() Move
- func (ms *MoveSlice) PushBack(m Move)
- func (ms *MoveSlice) PushFront(m Move)
- func (ms *MoveSlice) Set(i int, move Move)
- func (ms *MoveSlice) Sort()
- func (ms *MoveSlice) String() string
- func (ms *MoveSlice) StringUci() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MoveSlice ¶
type MoveSlice []Move
MoveSlice represents a data structure (go slice) for Move.
func NewMoveSlice ¶
NewMoveSlice creates a new move slice with the given capacity and 0 elements. Is identical to MoveSlice(make([]Move, 0, cap))
func (*MoveSlice) At ¶
At returns the move at index i in the slice without removing the move from the slice. At(0) refers to the first move and is the same as Front(). At(Len()-1) refers to the last move and is the same as Back(). Index will be checked against bounds and panics if out of bounds
func (*MoveSlice) Back ¶
func (ms *MoveSlice) Back() Move
Back returns the move at the back of the slice. This is the element that would be returned by ms[len[ms)-1]. This call panics if the slice is empty.
func (*MoveSlice) Clear ¶
func (ms *MoveSlice) Clear()
Clear removes all moves from the slice, but retains the current capacity. This is useful when repeatedly reusing the slice at high frequency to avoid GC during reuse.
func (*MoveSlice) Clone ¶
Clone copies the MoveSlice into a newly create MoveSlice doing a deep copy.
func (*MoveSlice) Equals ¶
Equals returns true if all elements of the MoveSlice equals the elements of the other MoveSlice
func (*MoveSlice) Filter ¶
Filter removes all elements from the MoveSlice for which the given call to func will return false. Rebuilds the data slice by looping over all elements and only re-adding elements for which the call to the given func is true. Reuses the underlying array
func (*MoveSlice) FilterCopy ¶
FilterCopy copies the MoveSlice into the given destination slice without the filtered elements. An element is filtered when the given call to func will return false for the element.
func (*MoveSlice) ForEach ¶
ForEach simple range loop calling the given function on each element in stored order
func (*MoveSlice) ForEachParallel ¶
ForEachParallel simple loop over all elements calling a goroutine which calls the given func with the index of the current element as a parameter. Waits until all elements have been processed. There is no synchronization for the parallel execution. This needs to done in the provided function if necessary
func (*MoveSlice) Front ¶
func (ms *MoveSlice) Front() Move
Front returns the move at the front of the slice. This is the element that would be returned by ms[0]. This call panics if the slice is empty.
func (*MoveSlice) Len ¶
Len returns the number of moves currently stored in the slice. Equivalent to len(ms)
func (*MoveSlice) PopBack ¶
func (ms *MoveSlice) PopBack() Move
PopBack removes and returns the move from the back of the slice. If the slice is empty, the call panics.
func (*MoveSlice) PopFront ¶
func (ms *MoveSlice) PopFront() Move
PopFront removes and returns the move from the front of the slice. If the slice is empty, the call panics. Shrinks the capacity of the slice as it only shifts the start of the slice within the underlying array. Might lead to earlier re-allocations
func (*MoveSlice) PushBack ¶
func (ms *MoveSlice) PushBack(m Move)
PushBack appends an element at the end of the slice Equivalent to append(ms, m)
func (*MoveSlice) PushFront ¶
func (ms *MoveSlice) PushFront(m Move)
PushFront prepends an element at the beginning of the slice using the underlying array (does not create a new array) Moves (copies) all elements by one index slot and adds the new move at the front.
func (*MoveSlice) Set ¶
Set puts a move at index i in the slice. Set shares the same purpose than At() but performs the opposite operation. The index i is the same index defined by At(). Index will be checked against bounds and panics if out of bounds
func (*MoveSlice) Sort ¶
func (ms *MoveSlice) Sort()
Sort will sort moves from highest Value to lowest Value . It uses a stable InsertionSort as MoveSlices are mostly pre-sorted and small. Sorts move only on the base of their Value (Move value == move&0xFFFF0000). Otherwise the order will not be changed.