sll

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 17, 2018 License: MIT Imports: 3 Imported by: 0

README

GoDoc

Sll

A scored linked list. Sll implements a pointer-based doubly linked list with the addition of methods to fetch nodes by score (high or low) and arbitrarily move nodes between lists. A node score is incremented with each Read() method called while retrieving the node's value.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxHeap

type MaxHeap []*Node

MaxHeap implements a max-heap heap.Interface.

func (MaxHeap) Len

func (mh MaxHeap) Len() int

func (MaxHeap) Less

func (mh MaxHeap) Less(i, j int) bool

func (*MaxHeap) Peek

func (mh *MaxHeap) Peek() interface{}

Peek returns the root node from the heap.

func (*MaxHeap) Pop

func (mh *MaxHeap) Pop() interface{}

Pop removes and returns the root node from the heap.

func (*MaxHeap) Push

func (mh *MaxHeap) Push(x interface{})

Push adds an item to the heap.

func (MaxHeap) Swap

func (mh MaxHeap) Swap(i, j int)

type MinHeap

type MinHeap []*Node

MinHeap implements a min-heap heap.Interface.

func (MinHeap) Len

func (mh MinHeap) Len() int

func (MinHeap) Less

func (mh MinHeap) Less(i, j int) bool

func (*MinHeap) Peek

func (mh *MinHeap) Peek() interface{}

Peek returns the root node from the heap.

func (*MinHeap) Pop

func (mh *MinHeap) Pop() interface{}

Pop removes and returns the root node from the heap.

func (*MinHeap) Push

func (mh *MinHeap) Push(x interface{})

Push adds an item to the heap.

func (MinHeap) Swap

func (mh MinHeap) Swap(i, j int)

type Node

type Node struct {
	Score uint64
	Value interface{}
	// contains filtered or unexported fields
}

Node is a scored linked list node.

func (*Node) Copy

func (n *Node) Copy() *Node

Copy returns a copy of a *Node.

func (*Node) Next

func (n *Node) Next() *Node

Next returns the next node in the *Sll.

func (*Node) Prev

func (n *Node) Prev() *Node

Prev returns the previous node in the *Sll.

func (*Node) Read

func (n *Node) Read() interface{}

Read returns a *Node Value and increments the score.

type NodeScoreList

type NodeScoreList []*Node

NodeScoreList is a slice of *Node sorted by ascending scores.

func (NodeScoreList) Len

func (nsl NodeScoreList) Len() int

func (NodeScoreList) Less

func (nsl NodeScoreList) Less(i, j int) bool

func (NodeScoreList) Swap

func (nsl NodeScoreList) Swap(i, j int)

type Sll

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

Sll is a scored linked list.

func New

func New() *Sll

New creates a new *Sll.

func (*Sll) Copy

func (ll *Sll) Copy() *Sll

Copy returns a copy of a *Sll.

func (*Sll) Head

func (ll *Sll) Head() *Node

Head returns the head *Node.

func (*Sll) HighScores

func (ll *Sll) HighScores(k int) NodeScoreList

HighScores takes an integer and returns the respective number of *Nodes with the higest scores sorted in ascending order.

func (*Sll) Len

func (ll *Sll) Len() uint

Len returns the count of nodes in the *Sll.

func (*Sll) LowScores

func (ll *Sll) LowScores(k int) NodeScoreList

LowScores takes an integer and returns the respective number of *Nodes with the lowest scores sorted in ascending order.

func (*Sll) MoveToHead

func (ll *Sll) MoveToHead(n *Node)

MoveToHead takes a *Node and moves it to the front of the *Sll.

func (*Sll) MoveToTail

func (ll *Sll) MoveToTail(n *Node)

MoveToTail takes a *Node and moves it to the back of the *Sll.

func (*Sll) PushHead

func (ll *Sll) PushHead(v interface{}) *Node

PushHead creates a *Node with value v at the head of the *Sll and returns a *Node.

func (*Sll) PushHeadNode

func (ll *Sll) PushHeadNode(n *Node)

PushHeadNode pushes an existing node to the head of the *Sll.

func (*Sll) PushTail

func (ll *Sll) PushTail(v interface{}) *Node

PushTail creates a *Node with value v at the tail of the *Sll and returns a *Node.

func (*Sll) PushTailNode

func (ll *Sll) PushTailNode(n *Node)

PushTailNode pushes an existing node to the tail of the *Sll.

func (*Sll) Remove

func (ll *Sll) Remove(n *Node)

Remove removes a *Node from the *Sll.

func (*Sll) RemoveHead

func (ll *Sll) RemoveHead()

RemoveHead removes the current *Sll.head.

func (*Sll) RemoveTail

func (ll *Sll) RemoveTail()

RemoveTail removes the current *Sll.tail.s

func (*Sll) Tail

func (ll *Sll) Tail() *Node

Tail returns the head *Node.

Directories

Path Synopsis
examples
sll-example
The MIT License (MIT) Copyright (c) 2016 Jamie Alquiza Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The MIT License (MIT) Copyright (c) 2016 Jamie Alquiza Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Jump to

Keyboard shortcuts

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