structx

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package structx provides ordered and pooled data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete[Type comparable, Type1 any](m *OrderedMap[Type, Type1], key Type)

Delete built-in function deletes the element with the specified key (m[key]) from the OrderedMap. If m is nil or there is no such element, delete is a no-op.

Example:

var om = NewOrderedMap[string, int]()
om.Put("x", 1)
structx.Delete(om, "x")

Types

type ObjectPool

type ObjectPool[T any] struct {
	// contains filtered or unexported fields
}

ObjectPool is a free-list pool that hands out reusable *T values.

func NewObjectPool

func NewObjectPool[T any](size ...uint32) *ObjectPool[T]

NewObjectPool returns an ObjectPool, optionally preallocated with size objects.

func (*ObjectPool[T]) Get

func (p *ObjectPool[T]) Get() *T

Get returns an object from the pool, growing it if the pool is empty.

type OrderedMap

type OrderedMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

OrderedMap is a map[Type]Type1-like collection that preserves the order in which keys were inserted. It behaves like a regular map but allows deterministic iteration over its elements.

OrderedMap is useful when both quick key-based access and predictable iteration order are desired.

func NewOrderedMap

func NewOrderedMap[K comparable, V any](size ...uint32) *OrderedMap[K, V]

NewOrderedMap returns a new empty OrderedMap.

func (*OrderedMap[K, V]) Delete

func (m *OrderedMap[K, V]) Delete(key K)

Delete removes the element with the specified key. If the key does not exist, Delete does nothing.

Complexity: - time: O(1) - mem: O(1)

func (*OrderedMap[K, V]) Get

func (m *OrderedMap[K, V]) Get(key K) (V, bool)

Get retrieves the value stored under the given key. The second return value reports whether the key was present.

Complexity: - time: O(1) - mem: O(1)

func (*OrderedMap[K, V]) GetValues

func (m *OrderedMap[K, V]) GetValues() []V

GetValues returns all values in insertion order. The returned slice has the same length as the number of elements.

Complexity: - time: O(N) - mem: O(N)

func (*OrderedMap[K, V]) Iter

func (m *OrderedMap[K, V]) Iter() func(func(K, V) bool)

Iter iteration on map in insertion order

Example:

m := NewOrderedMap[int, string]()

for k, v := range m.Iter() {
	fmt.Println(k,v)
}

func (*OrderedMap[K, V]) Put

func (m *OrderedMap[K, V]) Put(key K, value V)

Put sets the value for the given key. If the key already exists, its value is updated. Otherwise, a new entry is added to the end of the order.

Complexity: - time: O(1) - mem: O(1)

Jump to

Keyboard shortcuts

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