redblack

package
v0.0.0-...-a64ee79 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback[T constraints.Ordered, O Ordered[T]] func(*O)

Callback is a function type that takes an Ordered type as an argument.

type Color

type Color bool

Color defines color

const (
	Red   Color = false
	Black Color = true
)

type Complex128

type Complex128 complex128

func (Complex128) Get

func (c Complex128) Get() complex128

type Float64

type Float64 float64

Float64 implements Getter

func (Float64) Get

func (m Float64) Get() float64

Get returns float64 value

type Integer

type Integer int

Integer implements Getter

func (Integer) Get

func (m Integer) Get() int

Get returns int value

type Node

type Node[T constraints.Ordered, O Ordered[T]] struct {
	Color               Color
	Value               O
	Left, Right, Parent *Node[T, O]
}

func NewNode

func NewNode[T constraints.Ordered, O Ordered[T]](value O) *Node[T, O]

type Ordered

type Ordered[T constraints.Ordered] interface {
	Get() T
}

Ordered is a custom interface for types that are either integer, float, or string. These types must implement the Get() method.

type String

type String string

String implements Getter

func (String) Get

func (m String) Get() string

Get returns string value

type Tree

type Tree[T constraints.Ordered, O Ordered[T]] struct {
	Root *Node[T, O]
	// contains filtered or unexported fields
}

func NewTree

func NewTree[T constraints.Ordered, O Ordered[T]]() *Tree[T, O]

NewTree creates a new instance of a Tree

Example
package main

import (
	"fmt"
	"github.com/viant/gds/tree/redblack"
)

func main() {
	tree := redblack.NewTree[int, redblack.Integer]()
	tree.Insert(1)
	tree.Insert(101)
	tree.Insert(54)
	sorted := tree.InOrderTraversal()
	fmt.Printf("%v\n", sorted)
}
Output:

func (*Tree[T, O]) Delete

func (t *Tree[T, O]) Delete(value T)

func (*Tree[T, O]) InOrderTraversal

func (t *Tree[T, O]) InOrderTraversal() []O

func (*Tree[T, O]) Insert

func (t *Tree[T, O]) Insert(value O)

func (*Tree[T, O]) Iterate

func (t *Tree[T, O]) Iterate(callback Callback[T, O])

func (*Tree[T, O]) Search

func (t *Tree[T, O]) Search(value T) *Node[T, O]

func (*Tree[T, O]) Size

func (t *Tree[T, O]) Size() int

Jump to

Keyboard shortcuts

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