skipset

package module
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 4 Imported by: 0

README

skipset is a high-performance, scalable, concurrent-safe set based on skip-list.

Documentation

Overview

Example
l := New(func(a, b int) bool {
	return a < b
})

for _, v := range []int{10, 12, 15} {
	if l.Store(v) {
		fmt.Println("skipset add", v)
	}
}

if l.Contains(10) {
	fmt.Println("skipset contains 10")
}

l.Range(func(value int) bool {
	fmt.Println("skipset range found ", value)
	return true
})

l.Remove(15)
fmt.Printf("skipset contains %d items\r\n", l.Len())

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SkipSet

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

SkipSet represents a generic set based on skip list

func New

func New[T any](lessFunc func(a, b T) bool) *SkipSet[T]

New return an empty Item the set in ascending order.

func (*SkipSet[T]) AscendGreaterEqual

func (s *SkipSet[T]) AscendGreaterEqual(value T, f func(value T) bool)

AscendGreaterEqual calls f sequentially for each value present in the set greater than or equal to value. If f returns false, range stops the iteration.

func (*SkipSet[T]) Contains

func (s *SkipSet[T]) Contains(value T) bool

Contains check if the value is in the the set.

func (*SkipSet[T]) Len

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

Len return the length of this the set.

func (*SkipSet[T]) Load added in v0.13.0

func (s *SkipSet[T]) Load(value T) (v T, found bool)

Load returns the value in the set

func (*SkipSet[T]) LoadOrStore added in v0.13.0

func (s *SkipSet[T]) LoadOrStore(value T, newValue ValueOrFuncValue[T]) (actual T, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*SkipSet[T]) Max added in v0.17.0

func (s *SkipSet[T]) Max() T

Max returns the maximum value in the set. If it is empty then the zero value is returned.

func (*SkipSet[T]) Min added in v0.17.0

func (s *SkipSet[T]) Min() T

Min returns the minimum value in the set. If it is empty then the zero value is returned.

func (*SkipSet[T]) Range

func (s *SkipSet[T]) Range(f func(value T) bool)

Range calls f sequentially for each value present in the set. If f returns false, range stops the iteration.

func (*SkipSet[T]) Remove

func (s *SkipSet[T]) Remove(value T) bool

Remove a node from the the set.

func (*SkipSet[T]) Set added in v0.16.0

func (s *SkipSet[T]) Set(value T)

Set is similar to store but ensures given value is stored into the set.

func (*SkipSet[T]) Store added in v0.13.0

func (s *SkipSet[T]) Store(value T) bool

Store adds the value into the set, return true if this process insert the value into the set, return false if this process can't insert this value, because another process has inserted the same value.

If the value is in the set but not fully linked, this process will wait until it is.

type ValueOrFuncValue added in v0.15.0

type ValueOrFuncValue[T any] interface {
	any | func() T
}

Jump to

Keyboard shortcuts

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