typeparamcommon

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 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 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 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
Code generated by github.com/ngicks/type-param-common/cmd/lenner.
Code generated by github.com/ngicks/type-param-common/cmd/lenner.

Jump to

Keyboard shortcuts

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