rankedset

package
v4.0.0-alpha.0+incompa... Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface {
	// Key returns the unique identifier for this item.
	Key() string
	// Rank is used to sort items.
	// Items with the same rank are sorted lexicographically based on Key.
	Rank() int64
}

Item represents a single object in a RankedSet.

type RankedSet

type RankedSet struct {
	// contains filtered or unexported fields
}

RankedSet stores Items based on Key (uniqueness) and Rank (sorting).

func New

func New() *RankedSet

func (*RankedSet) Delete

func (s *RankedSet) Delete(item Item) Item

Delete removes the item from the set based on Key (Rank is ignored). The removed item is returned if it existed in the set.

func (*RankedSet) Get

func (s *RankedSet) Get(item Item) Item

func (*RankedSet) Has

func (s *RankedSet) Has(item Item) bool

func (*RankedSet) Insert

func (s *RankedSet) Insert(item Item) Item

Insert adds the item into the set. If an item with the same Key existed in the set, it is deleted and returned.

func (*RankedSet) Len

func (s *RankedSet) Len() int

func (*RankedSet) LessThan

func (s *RankedSet) LessThan(rank int64, delete bool) []Item

LessThan returns all items less than the given rank in ranked order. If delete is set to true, the returned items are removed from the set.

func (*RankedSet) List

func (s *RankedSet) List(delete bool) []Item

List returns all items in the set in ranked order. If delete is set to true, the returned items are removed from the set.

func (*RankedSet) Max

func (s *RankedSet) Max() Item

func (*RankedSet) Min

func (s *RankedSet) Min() Item

type StringItem

type StringItem string

StringItem implements Item using a string. It has two main uses: 1. If all items in a RankedSet are StringItems, the set becomes a store of unique strings sorted lexicographically. 2. It serves as a Key item that can be passed into methods that ignore Rank such as RankedSet.Delete.

func (StringItem) Key

func (s StringItem) Key() string

func (StringItem) Rank

func (s StringItem) Rank() int64

Jump to

Keyboard shortcuts

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