btree

package module
v0.0.0-...-f427b3e Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: Apache-2.0 Imports: 1 Imported by: 6

README

btree

go 1.18 generics experiment in building generic augmented btree data structures.

Don't use this in production, go 1.18 isn't even out yet!

Read more about this in the introductory blog post.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K, V any] struct {
	abstract.Map[K, V, struct{}]
}

Map is a ordered map from K to V.

Example
package main

import (
	"fmt"
	"strings"

	"github.com/ajwerner/btree"
)

func main() {
	m := btree.MakeMap[string, int](strings.Compare)
	m.Upsert("foo", 1)
	m.Upsert("bar", 2)
	fmt.Println(m.Get("foo"))
	fmt.Println(m.Get("baz"))
	it := m.Iterator()
	for it.First(); it.Valid(); it.Next() {
		fmt.Println(it.Cur(), it.Value())
	}

}
Output:

1 true
0 false
bar 2
foo 1

func MakeMap

func MakeMap[K, V any](cmp func(K, K) int) Map[K, V]

MakeMap constructs a new Map with the provided comparison function.

func (*Map[K, V]) Clone

func (m *Map[K, V]) Clone() Map[K, V]

Clone clones the Map, lazily. It does so in constant time.

type Set

type Set[T any] Map[T, struct{}]

Set is an ordered set of items of type T.

func MakeSet

func MakeSet[T any](cmp func(T, T) int) Set[T]

MakeSet constructs a new Set with the provided comparison function.

func (*Set[T]) Clone

func (t *Set[T]) Clone() Set[T]

Clone clones the Set, lazily. It does so in constant time.

func (*Set[K]) Delete

func (t *Set[K]) Delete(item K) (removed bool)

Delete removes the value with the provided key. It returns true if the item existed in the set.

func (*Set[T]) Upsert

func (t *Set[T]) Upsert(item T) (replaced T, overwrote bool)

Upsert inserts or updates the provided item. It returns the overwritten item if a previous value existed for the key.

Directories

Path Synopsis
internal
ordered
Package ordered contains utilities for dealing with types which implement constraints.Ordered.
Package ordered contains utilities for dealing with types which implement constraints.Ordered.

Jump to

Keyboard shortcuts

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