state

package
v0.0.0-...-ad861b7 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT, Unlicense Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map of arbitrary data to hold unordered state for `layout.List` items. This allows Gio programs to re-use a buffer of states for lists items in between frames. It is a grow-only buffer that expects entries to stabilise.

This is designed along 2 constraints: 1. Performance 2. Type ambiguity

Since Go doesn't have generics, I decided to give the caller type control by using `unsafe.Pointer`.

The caller only has to ensure that the type they initialise it with is the type they attempt to cast out of it. Since the scope of use is small, this invariant is straightforward to uphold.

Nonetheless, this style of API is primarily motivated by re-use concerns when using common patterns in Gio (specifically `layout.List` state management). The static approach would be to copy-paste the same structures with different types every time you have list state to manage.

In light of Go generics incoming, this may become a moot issue. In the meantime this remains an experimental API that functions as expected.

func (*Map) Begin

func (m *Map) Begin()

Begin prepares the map to be accessed. Require to reset iteration state each frame.

func (*Map) More

func (m *Map) More() bool

More reports whether there is more data to iterate.

func (*Map) New

func (m *Map) New(k string, init unsafe.Pointer) unsafe.Pointer

New returns a value for the provided key. In the case no value exists, the initializer is used as the default value. The initializer is the value that will be returned from the map. Take care when casting it.

v := (*T)(m.New("foo", &T{}))

func (*Map) Next

func (m *Map) Next() (key string, value unsafe.Pointer)

Next iterates over the collection, returning the key-value pair.

for key, value := m.Next(); m.More(); key, value = m.Next() {
	t := (*T)(v)
}

Jump to

Keyboard shortcuts

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