datastruct

package
v0.302.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapAdd

func MapAdd[K comparable, V any, Map KVS[K, V]](m Map, k K, v V) func()

Types

type KVS added in v0.302.0

type KVS[K comparable, V any] interface {
	Lookup(key K) (V, bool)
	Get(key K) V
	Set(key K, val V)
	Delete(key K)
	Keys() []K
	ToMap() map[K]V
	Sizer
}

KVS stands for Key Value Store, and a common interface for map[K]V types.

type LinkedList added in v0.302.0

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

func (*LinkedList[T]) Append added in v0.302.0

func (ll *LinkedList[T]) Append(vs ...T)

func (*LinkedList[T]) Iter added in v0.302.0

func (ll *LinkedList[T]) Iter() iter.Seq[T]

func (*LinkedList[T]) Len added in v0.302.0

func (ll *LinkedList[T]) Len() int

Len returns the length of elements in the list

func (*LinkedList[T]) Lookup added in v0.302.0

func (ll *LinkedList[T]) Lookup(index int) (T, bool)

func (*LinkedList[T]) Pop added in v0.302.0

func (ll *LinkedList[T]) Pop() (T, bool)

func (*LinkedList[T]) Prepend added in v0.302.0

func (ll *LinkedList[T]) Prepend(vs ...T)

Prepend adds an element to the beginning of the list.

func (*LinkedList[T]) Shift added in v0.302.0

func (ll *LinkedList[T]) Shift() (T, bool)

func (*LinkedList[T]) ToSlice added in v0.302.0

func (ll *LinkedList[T]) ToSlice() []T

type List added in v0.302.0

type List[T any] interface {
	Append(vs ...T)
	ToSlice() []T
	Iter() iter.Seq[T]
	Sizer
}

type Map

type Map[K comparable, V any] map[K]V

func (Map[K, V]) Delete

func (m Map[K, V]) Delete(key K)

func (Map[K, V]) Get

func (m Map[K, V]) Get(key K) V

func (Map[K, V]) Keys

func (m Map[K, V]) Keys() []K

func (Map[K, V]) Len

func (m Map[K, V]) Len() int

func (Map[K, V]) Lookup

func (m Map[K, V]) Lookup(key K) (V, bool)

func (Map[K, V]) Set

func (m Map[K, V]) Set(key K, val V)

func (Map[K, V]) ToMap added in v0.302.0

func (m Map[K, V]) ToMap() map[K]V

type OrderedSet added in v0.302.0

type OrderedSet[T comparable] struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"go.llib.dev/frameless/pkg/datastruct"
)

func main() {
	var set datastruct.OrderedSet[string]
	set.Append("foo", "bar", "baz", "foo")
	set.ToSlice() // []string{"foo", "bar", "baz"}
	set.Len()     // 3
}
Example (FromSlice)
package main

import (
	"go.llib.dev/frameless/pkg/datastruct"
)

func main() {
	var vs = []string{"foo", "bar", "baz", "foo"}
	var set = datastruct.OrderedSet[string]{}.FromSlice(vs)
	set.ToSlice() // []string{"foo", "bar", "baz"}
	set.Len()     // 3
}
Example (Has)
package main

import (
	"go.llib.dev/frameless/pkg/datastruct"
)

func main() {
	var set datastruct.OrderedSet[string]
	set.Append("foo", "bar", "baz", "foo")
	set.Has("foo") // true
	set.Has("bar") // true
	set.Has("oof") // false
}
Example (Iterate)
package main

import (
	"go.llib.dev/frameless/pkg/datastruct"
)

func main() {
	var set datastruct.OrderedSet[string]
	set.Append("foo", "bar", "baz", "foo")

	for v := range set.Iter() {
		_ = v // "foo" -> "bar" -> "baz"
	}
}

func (*OrderedSet[T]) Append added in v0.302.0

func (s *OrderedSet[T]) Append(vs ...T)

func (OrderedSet[T]) FromSlice added in v0.302.0

func (set OrderedSet[T]) FromSlice(vs []T) OrderedSet[T]

func (OrderedSet[T]) Has added in v0.302.0

func (s OrderedSet[T]) Has(v T) bool

func (OrderedSet[T]) Iter added in v0.302.0

func (s OrderedSet[T]) Iter() iter.Seq[T]

func (OrderedSet[T]) Len added in v0.302.0

func (s OrderedSet[T]) Len() int

func (OrderedSet[T]) ToSlice added in v0.302.0

func (s OrderedSet[T]) ToSlice() []T

type Sizer added in v0.302.0

type Sizer interface {
	Len() int
}

Jump to

Keyboard shortcuts

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