Back to

Package gtreap

Latest Go to latest

The latest major version is .

Published: Dec 28, 2016 | License: MIT | Module:


type Compare

type Compare func(a, b interface{}) int

Compare returns an integer comparing the two items lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

type Item

type Item interface{}

Item can be anything.

type ItemVisitor

type ItemVisitor func(i Item) bool

type Iterator

type Iterator struct {
	// contains filtered or unexported fields

Iterator supports iterative ascending traversal of the Treap. An Iterator is instantiated by calling a Treap's Iterator method.

func (*Iterator) Next

func (it *Iterator) Next() (Item, bool)

Next returns the next Item in the iteration sequence.

If another item exists in the iteration sequence, true will be returned as the second return value; if not, false will be returned, indicating end of iteration. Additional calls to Next after end of iteration will continue to return false.

type Treap

type Treap struct {
	// contains filtered or unexported fields

func NewTreap

func NewTreap(c Compare) *Treap

func (*Treap) Delete

func (t *Treap) Delete(target Item) *Treap

func (*Treap) Get

func (t *Treap) Get(target Item) Item

func (*Treap) Iterator

func (t *Treap) Iterator(pivot Item) *Iterator

Iterator returns an ascending Iterator instance that is bound to this Treap. The iterator begins at "pivot" and iterates through the end of the Treap.

func (*Treap) Max

func (t *Treap) Max() Item

func (*Treap) Min

func (t *Treap) Min() Item

func (*Treap) Upsert

func (t *Treap) Upsert(item Item, itemPriority int) *Treap

Note: only the priority of the first insert of an item is used. Priorities from future updates on already existing items are ignored. To change the priority for an item, you need to do a Delete then an Upsert.

func (*Treap) VisitAscend

func (t *Treap) VisitAscend(pivot Item, visitor ItemVisitor)

Visit items greater-than-or-equal to the pivot.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier