memory

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package memory contains structs for genny to generate templates of your need

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NumberBiComp added in v0.2.12

func NumberBiComp(a, b Number) uint8

Types

type Elem added in v0.4.2

type Elem generic.Number

type ElemSet added in v0.4.2

type ElemSet []Elem

ElemSet uses binary search to store comparable elements it acts as normal Set though, with performance advantage over map

func (*ElemSet) Has added in v0.4.2

func (s *ElemSet) Has(val Elem) bool

Has returns whether set has the value

func (*ElemSet) Insert added in v0.4.2

func (s *ElemSet) Insert(val Elem) bool

Insert inserts the element or returns false if element already is present

func (*ElemSet) Remove added in v0.4.2

func (s *ElemSet) Remove(val Elem) bool

Remove removes the value or returns false if value is not present

type Element added in v0.2.12

type Element generic.Type

type ElementCapsule added in v0.2.12

type ElementCapsule struct {
	// contains filtered or unexported fields
}

ElementCapsule is something like an optional type, it holds boolean about whether it contains value though it does not hold pointer

type ElementStorage added in v0.2.12

type ElementStorage struct {
	// contains filtered or unexported fields
}

ElementStorage generates IDs witch makes no need to use hashing, only drawback is that you cannot choose the id, it will be assigned like a pointer, but without putting presure no gc, brilliant ElementStorage for components. Its highly unlikely you will run out of ids as they are reused

func (*ElementStorage) Allocate added in v0.2.12

func (s *ElementStorage) Allocate() (*Element, int)

Allocate allocates an value and returns id and pointer to it. Note that allocate does not always allocate at all and just reuses freed space, returned pointer also does not point to zero value and you have to overwrite all properties to get expected behavior

func (*ElementStorage) AllocateID added in v0.2.12

func (s *ElementStorage) AllocateID(id int) *Element

Allocate id allocates if it is free, else it returns nil

func (*ElementStorage) Blanc added in v0.2.12

func (s *ElementStorage) Blanc()

Blanc allocates blanc space adds

func (*ElementStorage) Clear added in v0.2.12

func (s *ElementStorage) Clear()

Clear clears ElementStorage, but keeps allocated space

func (*ElementStorage) Count added in v0.2.12

func (s *ElementStorage) Count() int

Count returns amount of values stored

func (*ElementStorage) Item added in v0.2.12

func (s *ElementStorage) Item(id int) *Element

Item returns pointer to value under the "id", accessing random id can result in random value that can be considered unoccupied

method panics if id is not occupied

func (*ElementStorage) Len added in v0.2.12

func (s *ElementStorage) Len() int

Len returns size of ElementStorage

func (*ElementStorage) Occupied added in v0.2.12

func (s *ElementStorage) Occupied() []int

Occupied return all occupied ids in ElementStorage, this method panics if ElementStorage is outdated See Update method.

func (*ElementStorage) Remove added in v0.2.12

func (s *ElementStorage) Remove(id int)

Remove removes a value and frees memory for something else

panic if there is nothing to free

func (*ElementStorage) SlowClear added in v0.2.12

func (s *ElementStorage) SlowClear()

SlowClear clears the the ElementStorage slowly with is tradeoff for having faster allocating speed

func (*ElementStorage) Used added in v0.2.12

func (s *ElementStorage) Used(id int) bool

Used returns whether id is used

type Item added in v0.2.11

type Item generic.Type

type ItemVec added in v0.2.11

type ItemVec []Item

ItemVec is a standard Vector type with utility methods

func (*ItemVec) BiInsert added in v0.2.11

func (v *ItemVec) BiInsert(value Item, cmp func(a, b Item) uint8)

BiInsert inserts inserts value in a way that keebuff vec sorted, binary search is used to determinate where to insert

func (ItemVec) BiSearch added in v0.2.11

func (v ItemVec) BiSearch(value Item, cmp func(a, b Item) uint8) (int, bool)

BiSearch performs a binary search on Ves assuming it is sorted. cmp consumer should return 0 if a == b equal, 1 if a > b and 2 if b > a, even if value wos not found it returns it returns closest index and false. If ItemVec is empty -1 and false is returned

func (*ItemVec) Clear added in v0.2.11

func (v *ItemVec) Clear()

Clear is equivalent to Truncate(0)

func (ItemVec) Clone added in v0.2.11

func (v ItemVec) Clone() ItemVec

Clone creates new ItemVec copies content of v to it and returns it

func (*ItemVec) Extend added in v0.2.11

func (v *ItemVec) Extend(amount int)

Extend extends vec size by amount so then len(ItemVec) = len(ItemVec) + amount

func (*ItemVec) Filter added in v0.2.11

func (v *ItemVec) Filter(filter func(e Item) bool)

Filter leaves only elements for with filter returns true

func (ItemVec) Find added in v0.2.11

func (v ItemVec) Find(find func(e Item) bool) (idx int, res Item)

Find returns first element for which find returns true along with index, if there is none, index equals -1

func (ItemVec) ForEach added in v0.2.11

func (v ItemVec) ForEach(con func(i int, e Item) Item)

ForEach is a standard foreach method. Its shortcut for modifying all elements

func (*ItemVec) Insert added in v0.2.11

func (v *ItemVec) Insert(idx int, val ...Item)

Insert inserts value to given index

func (ItemVec) Last added in v0.2.11

func (v ItemVec) Last() Item

Last returns last element of slice

func (ItemVec) Len added in v0.2.11

func (v ItemVec) Len() int

Len implements VertexData interface

func (ItemVec) Move added in v0.2.11

func (v ItemVec) Move(old, new int)

Move moves value from old to new shifting elements in between

func (*ItemVec) Pop added in v0.2.11

func (v *ItemVec) Pop() Item

Pop removes last element

func (*ItemVec) PopFront added in v0.2.11

func (v *ItemVec) PopFront() Item

PopFront removes first element and returns it

func (*ItemVec) Remove added in v0.2.11

func (v *ItemVec) Remove(idx int) (val Item)

Remove removes element and returns it

func (*ItemVec) RemoveSlice added in v0.2.11

func (v *ItemVec) RemoveSlice(start, end int)

RemoveSlice removes sequence of slice

func (*ItemVec) Resize added in v0.2.11

func (v *ItemVec) Resize(size int)

Resize resizes the ItemVec

func (ItemVec) Reverse added in v0.2.11

func (v ItemVec) Reverse()

Reverse reverses content of slice

func (ItemVec) Rewrite added in v0.2.11

func (v ItemVec) Rewrite(o ItemVec, idx int)

Rewrite revrites elements from index to o values

func (ItemVec) Sort added in v0.2.11

func (v ItemVec) Sort(buff []int, comp func(a, pivot Item) bool) []int

Sort is quicksort for ItemVec, if returns true, item will be swapped to left side from pivot so a > pivot will sort in descending order

func (ItemVec) Swap added in v0.2.11

func (v ItemVec) Swap(a, b int)

Swap swabuff two elements

func (*ItemVec) Truncate added in v0.2.11

func (v *ItemVec) Truncate(l int)

Truncate in comparison to truncating by bracket operator also sets all forgoten elements to default value, witch is useful if this is slice of pointers ItemVec will have length you specify

type Key added in v0.2.11

type Key generic.Type

type KeyValueCapsule added in v0.2.11

type KeyValueCapsule struct {
	K Key
	V Value
}

KeyValueCapsule is component of ordered map that stores key and a value

type KeyValueOrdered added in v0.2.11

type KeyValueOrdered struct {
	// contains filtered or unexported fields
}

KeyValueOrdered stores its items in underlying slice and map just keeps indexes

func NKeyValueOrdered added in v0.2.11

func NKeyValueOrdered() KeyValueOrdered

NOrderedMap initializes inner map

func (*KeyValueOrdered) Clear added in v0.2.11

func (o *KeyValueOrdered) Clear()

Clear removes all elements

func (*KeyValueOrdered) Index added in v0.2.11

func (o *KeyValueOrdered) Index(name Key) (int, bool)

Index returns index of a key's value

func (*KeyValueOrdered) Insert added in v0.2.11

func (o *KeyValueOrdered) Insert(key Key, idx int, value Value)

Insert insets element under index and key

func (*KeyValueOrdered) IsNil added in v0.2.11

func (o *KeyValueOrdered) IsNil() bool

IsNil reports whether KeyValueOrdered instance is uninitialized

func (*KeyValueOrdered) Put added in v0.2.11

func (o *KeyValueOrdered) Put(key Key, value Value)

Put puts a value under key

func (*KeyValueOrdered) ReIndex added in v0.2.11

func (o *KeyValueOrdered) ReIndex(old, new int)

ReIndex changes index of an element

func (*KeyValueOrdered) Remove added in v0.2.11

func (o *KeyValueOrdered) Remove(key Key) (v Value, i int, b bool)

Remove removes the key value pair

func (*KeyValueOrdered) RemoveIndex added in v0.2.11

func (o *KeyValueOrdered) RemoveIndex(idx int) (cell KeyValueCapsule)

RemoveIndex removes by index

func (*KeyValueOrdered) Rename added in v0.2.11

func (o *KeyValueOrdered) Rename(old, new Key) bool

Rename renames element and keeps index

func (*KeyValueOrdered) Slice added in v0.2.11

func (o *KeyValueOrdered) Slice() []KeyValueCapsule

Slice returns underlying slice

func (*KeyValueOrdered) Value added in v0.2.11

func (o *KeyValueOrdered) Value(key Key) (val *Value, idx int, ok bool)

Value returns value under key

type Number added in v0.2.12

type Number generic.Number

type Quick added in v0.2.11

type Quick generic.Type

type QuickPool

type QuickPool struct {
	// contains filtered or unexported fields
}

QuickPool is template that can store interface referenced objects on one place reducing allocation, if you are creating lot of date stored behind interface that has very short livetime QuickPool can be nice optimization

func (*QuickPool) Item

func (q *QuickPool) Item(new Quick) *Quick

Item returns pointer to pooling struct that is free, if no free struct is present new one is allocated

func (*QuickPool) Over

func (q *QuickPool) Over(val Quick) *Quick

Over overwrites by raw value and returns pointer to its new position

func (*QuickPool) Restart

func (q *QuickPool) Restart()

Restart makes QuickPool reuse old objects, if you cannot call this as pooling structs you taken are constantly referenced, its useles to use QuickPool in first place

type Value added in v0.2.11

type Value generic.Type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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