datastruct

package
v0.304.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package datastruct is an experimental package, that is a candidate to become a port if there is use-case to support it.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValueStore

type KeyValueStore[K comparable, V any] interface {
	Lookup(key K) (V, bool)
	Get(key K) V
	Set(key K, val V)
	Delete(key K)
	Keys() []K
	Iter() iter.Seq2[K, V]
	Sizer
}

type LinkedList

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

func (*LinkedList[T]) Append

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

func (*LinkedList[T]) Iter

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

func (*LinkedList[T]) Len

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

Len returns the length of elements in the list

func (*LinkedList[T]) Lookup

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

func (*LinkedList[T]) Pop

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

func (*LinkedList[T]) Prepend

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

Prepend adds an element to the beginning of the list.

func (*LinkedList[T]) Shift

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

func (*LinkedList[T]) Slice

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

type List

type List[T any] interface {
	Append(vs ...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]) Iter

func (m Map[K, V]) Iter() iter.Seq2[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]) Map

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

func (Map[K, V]) Set

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

type Mapper

type Mapper[K comparable, V any] interface {
	// Map returns the contents as a map[K]V.
	Map() map[K]V
}

type OrderedSet

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

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

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

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

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

import (
	"go.llib.dev/frameless/port/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/port/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

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

func (*OrderedSet[T]) Delete

func (s *OrderedSet[T]) Delete(index int) bool

func (OrderedSet[T]) FromSlice

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

func (OrderedSet[T]) Has

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

func (*OrderedSet[T]) Insert

func (s *OrderedSet[T]) Insert(index int, vs ...T) bool

func (OrderedSet[T]) Iter

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

func (OrderedSet[T]) Len

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

func (*OrderedSet[T]) Lookup

func (s *OrderedSet[T]) Lookup(index int) (T, bool)

func (*OrderedSet[T]) Set

func (s *OrderedSet[T]) Set(index int, v T) bool

func (OrderedSet[T]) Slice

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

type Sequence

type Sequence[T any] interface {
	List[T]
	Lookup(index int) (T, bool)
	Set(index int, val T) bool
	Insert(index int, vs ...T) bool
	Delete(index int) bool
}

type Set

type Set[T comparable] map[T]struct{}
Example
package main

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

func main() {
	var set datastruct.Set[string]
	set.Append("foo", "bar", "baz")
	for v := range set.Iter() {
		_ = v // "foo" / "bar" / "baz"
	}
}

func (*Set[T]) Append

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

func (*Set[T]) Iter

func (s *Set[T]) Iter() iter.Seq[T]

func (*Set[T]) Len

func (s *Set[T]) Len() int

func (*Set[T]) Slice

func (s *Set[T]) Slice() []T

type Sizer

type Sizer interface {
	Len() int
}

type Slicer

type Slicer[T any] interface {
	// Slice returns the contents as a slice of T.
	Slice() []T
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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