splaytree

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package splaytree implements a splay tree. See https://en.wikipedia.org/wiki/Splay_tree for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SplayTree

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

SplayTree represents a splay tree. Zero value of SplayTree is empty splay tree.

func New

func New[T constraints.Ordered]() *SplayTree[T]

New returns an initialized splay tree.

func NewWithComparator

func NewWithComparator[T any](comp func(T, T) int) *SplayTree[T]

NewWithComparator returns an initialized splay tree using given comparator.

func (*SplayTree[T]) All

func (s *SplayTree[T]) All() []T

All returns all elements from tree. Returned slice is sorted.

func (*SplayTree[T]) Contains

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

Contains returns true if tree contains given value, false otherwise.

func (*SplayTree[T]) Insert

func (s *SplayTree[T]) Insert(value T)

Insert inserts value in a tree.

func (*SplayTree[T]) Kth

func (s *SplayTree[T]) Kth(i int) T

Kth returns kth greatest element.

func (*SplayTree[T]) Remove

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

Remove removes value from tree. returns true if tree contained given value, false otherwise.

func (*SplayTree[T]) Size

func (s *SplayTree[T]) Size() int

Size returns size of the tree.

func (*SplayTree[T]) Sub

func (s *SplayTree[T]) Sub(l, r int) []T

Sub returns elements [l, r) in ascending order.

Jump to

Keyboard shortcuts

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