typeparamcommon

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

type-param-common

Type parameter primitives and commons.

Basically wrapper around go std library. If wrapping is inadequate, copy-and-paste and modify go codes.

Non overlapping package name

Wrappers of Go std lib are suffixed with -param

Package descriptions

heap-param, list-param, ring-param

Wrappers around container/heap, container/list and container/ring. Getter/Setter and Unwrap methods are added to mutate/observe Value from outside wrapper.

Correct usage of these types involves direct mutation by assigning to Value. Since Go expose no way to trap property accesses, without additional getters/setters we have no way to access to those properties. Thus these methods should be justified.

sync-param

Type-param aware wrappers around sync.Map and sync.Pool.

slice

Deque, queue, stack and whatever that needs type-param. It eases pain of write-deque-type-everywhere.

  • Deque
  • Queue
  • Stack
iterator

Iterator impl for go.

  • creating iterator
    • from slice
    • from list.List[T]
    • from channel
  • Reverse, ForEach
  • Filter(Select and Exclude)
  • Map
  • Reduce
  • Skip and Take

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildExcludeFilter added in v0.0.9

func BuildExcludeFilter[T any](start, end int, filterPredicate func(T) bool) func(sl *[]T)

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]) 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 Lessable

type Lessable[T any] interface {
	Inner() T
	// LessThan determines self is less than input Lessable[T].
	LessThan(Lessable[T]) bool
}

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
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.

Jump to

Keyboard shortcuts

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