Documentation
¶
Index ¶
- func BuildExcludeFilter[T any](start, end int, filterPredicate func(T) bool) func(sl *[]T)
- func MakeHeap[T any](less func(i, j T) bool) (*HeapWrapper[T], *SliceInterface[T])
- func MakeMaxHeap[T constraints.Ordered]() (*HeapWrapper[T], *SliceInterface[T])
- func MakeMinHeap[T constraints.Ordered]() (*HeapWrapper[T], *SliceInterface[T])
- type FilterableHeap
- type HeapWrapper
- type Lessable
- type SliceInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildExcludeFilter ¶ added in v0.0.9
func MakeHeap ¶
func MakeHeap[T any](less func(i, j T) bool) (*HeapWrapper[T], *SliceInterface[T])
MakeHeap makes a heap for the type T using a less[T] function.
1st returned value is struct with basic set of heap methods. 2nd is one that implements heap.Interface[T] which is used in *HeapWrapper[T]. To add your own heap methods, embed *HeapWrapper[T] to your own struct type and manipulate SliceInterface[T].Inner slice in methods of that struct with succeeding *HeapWrapper.Init call.
func MakeMaxHeap ¶
func MakeMaxHeap[T constraints.Ordered]() (*HeapWrapper[T], *SliceInterface[T])
MakeMaxHeap makes a maxheap for the type T. This is same as MakeMinHeap but uses more[T] instead.
func MakeMinHeap ¶
func MakeMinHeap[T constraints.Ordered]() (*HeapWrapper[T], *SliceInterface[T])
MakeMinHeap makes a minheap for the type T.
MakeMinHeap does what MakeHeap does but with predeclared less function. T is constrained to predeclared primitive types which are compatible with less and greater comparison operations.
Types ¶
type FilterableHeap ¶ added in v0.0.9
type FilterableHeap[U any, T Lessable[U]] struct { *HeapWrapper[T] // contains filtered or unexported fields }
func NewFilterableHeap ¶ added in v0.0.9
func NewFilterableHeap[U any, T Lessable[U]]() *FilterableHeap[U, T]
func (*FilterableHeap[U, T]) Clone ¶ added in v0.0.13
func (h *FilterableHeap[U, T]) Clone() *FilterableHeap[U, T]
Clone clones internal slice and creates new FilterableHeap with it. This is done by simple slice copy, without succeeding Init call, which means it also clones broken invariants if any.
If type T or one of its internal value is pointer type, mutation of T porpagates cloned to original, and vice versa.
func (*FilterableHeap[U, T]) Filter ¶ added in v0.0.9
func (h *FilterableHeap[U, T]) Filter(filterFuncs ...func(innerSlice *[]T))
Filter calls filterFuncs one by one, in given order, with following heap.Init(). Each filterFunc receives innerSlice so that it can be mutated in that func.
Filter calls heap.Init() at the end of the method. So the complexity is at least O(n) where n is h.Len().
func (*FilterableHeap[U, T]) Len ¶ added in v0.0.9
func (h *FilterableHeap[U, T]) Len() int
func (*FilterableHeap[U, T]) Peek ¶ added in v0.0.9
func (h *FilterableHeap[U, T]) Peek() (p T)
Peek returns most prioritized value in heap without removing it. If this heap contains 0 element, returned p is zero value for type T.
The complexity is O(1).
type HeapWrapper ¶
type HeapWrapper[T any] struct { // contains filtered or unexported fields }
func NewHeapWrapper ¶
func NewHeapWrapper[T any](inter heapparam.Interface[T]) *HeapWrapper[T]
func (*HeapWrapper[T]) Fix ¶
func (hw *HeapWrapper[T]) Fix(i int)
func (*HeapWrapper[T]) Init ¶
func (hw *HeapWrapper[T]) Init()
func (*HeapWrapper[T]) Pop ¶
func (hw *HeapWrapper[T]) Pop() T
func (*HeapWrapper[T]) Push ¶
func (hw *HeapWrapper[T]) Push(x T)
func (*HeapWrapper[T]) Remove ¶
func (hw *HeapWrapper[T]) Remove(i int) T
type SliceInterface ¶
type SliceInterface[T any] struct { Inner []T // contains filtered or unexported fields }
func NewSliceInterface ¶
func NewSliceInterface[T any](init []T, less func(i, j T) bool) *SliceInterface[T]
func (*SliceInterface[T]) Len ¶
func (sl *SliceInterface[T]) Len() int
func (*SliceInterface[T]) Less ¶
func (sl *SliceInterface[T]) Less(i, j int) bool
func (*SliceInterface[T]) Pop ¶
func (sl *SliceInterface[T]) Pop() (p T)
func (*SliceInterface[T]) Push ¶
func (sl *SliceInterface[T]) Push(x T)
func (*SliceInterface[T]) Swap ¶
func (sl *SliceInterface[T]) Swap(i, j int)
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
example
command
|
|
reverser
command
|
|
sizehinter
command
|
|
package listparam wraps doubly-linked list implemented in go programming langauge standard library, to accept type parameter.
|
package listparam wraps doubly-linked list implemented in go programming langauge standard library, to accept type parameter. |
util implements trivial util functions.
|
util implements trivial util functions. |