sortutil

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: CC0-1.0 Imports: 4 Imported by: 7

Documentation

Overview

Package sortutil contains common sorting definitions and utilities for sorting data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int64s

func Int64s(a []int64)

Int64s sorts a slice of int64s in increasing order.

func InterfaceStrings

func InterfaceStrings(a []interface{})

InterfaceStrings sorts a slice of interface{} in increasing order by their string values.

func UInt64s

func UInt64s(a []uint64)

UInt64s sorts a slice of uint64s in increasing order.

Types

type AbstractSlice

type AbstractSlice []interface{}

AbstractSlice is a special type implementing the sort interface for interface{} (Sorting is by string value)

func (AbstractSlice) Len

func (p AbstractSlice) Len() int

func (AbstractSlice) Less

func (p AbstractSlice) Less(i, j int) bool

func (AbstractSlice) Swap

func (p AbstractSlice) Swap(i, j int)

type Int64Slice

type Int64Slice []int64

Int64Slice is a special type implementing the sort interface for int64

func (Int64Slice) Len

func (p Int64Slice) Len() int

func (Int64Slice) Less

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap

func (p Int64Slice) Swap(i, j int)

type IntHeap

type IntHeap []int

IntHeap is a classic heap with int values.

func (IntHeap) Len

func (h IntHeap) Len() int

func (IntHeap) Less

func (h IntHeap) Less(i, j int) bool

func (*IntHeap) Peek

func (h *IntHeap) Peek() int

Peek returns the next item but does not remove it like Pop.

func (*IntHeap) Pop

func (h *IntHeap) Pop() interface{}

Pop removes an item to the heap.

func (*IntHeap) Push

func (h *IntHeap) Push(x interface{})

Push adds an item to the heap.

func (*IntHeap) RemoveAll

func (h *IntHeap) RemoveAll(r int)

RemoveAll removes all occurrences of item r from the IntHeap.

func (*IntHeap) RemoveFirst

func (h *IntHeap) RemoveFirst(r int)

RemoveFirst removes the first occurrences of item r from the IntHeap.

func (IntHeap) Swap

func (h IntHeap) Swap(i, j int)

type PriorityQueue

type PriorityQueue struct {
	MinPriority func() int // Function returning the minimum priority
	// contains filtered or unexported fields
}

PriorityQueue is like a regular queue where each element has a priority. Items with higher priority are served first. Items with the same priority are returned in the order they were added. Priority 0 is the highest priority with the priority decreasing as the priority number increases.

It is possible to set a minimum priority function on the PriorityQueue object. The function returns the current minimum priority level which should be returned by the queue. If the current available priority is lower than this then len() will return 0 and pop will return nil. If the function returns a negative value then the value is ignored.

func NewPriorityQueue

func NewPriorityQueue() *PriorityQueue

NewPriorityQueue creates a new priority queue.

func (*PriorityQueue) Clear

func (pq *PriorityQueue) Clear()

Clear clears the current queue contents.

func (*PriorityQueue) CurrentPriority

func (pq *PriorityQueue) CurrentPriority() int

CurrentPriority returns the priority of the next item.

func (*PriorityQueue) Peek

func (pq *PriorityQueue) Peek() interface{}

Peek returns the next item of the queue but does not remove it.

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

Pop remove the next element from the queue and returns it.

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(value interface{}, priority int)

Push adds a new element to the queue.

func (*PriorityQueue) Size

func (pq *PriorityQueue) Size() int

Size returns the current queue size.

func (*PriorityQueue) SizeCurrentPriority

func (pq *PriorityQueue) SizeCurrentPriority() int

SizeCurrentPriority returns the queue size of all elements of the highest priority.

func (*PriorityQueue) String

func (pq *PriorityQueue) String() string

String returns a string representation of the queue.

type UInt64Slice

type UInt64Slice []uint64

UInt64Slice is a special type implementing the sort interface for uint64

func (UInt64Slice) Len

func (p UInt64Slice) Len() int

func (UInt64Slice) Less

func (p UInt64Slice) Less(i, j int) bool

func (UInt64Slice) Swap

func (p UInt64Slice) Swap(i, j int)

type VectorClock

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

VectorClock implements a vector clock object. The clock can record actions of actors. Each action produces a new version which can be queried.

func CloneVectorClock

func CloneVectorClock(vc *VectorClock) *VectorClock

CloneVectorClock clones an existing vector clock.

func NewDescendant

func NewDescendant(otherVCs ...*VectorClock) *VectorClock

NewDescendant creates a vector clock which is a descendant of all given vector clocks.

func NewVectorClock

func NewVectorClock() *VectorClock

NewVectorClock creates a new vector clock datastructure.

func (*VectorClock) Act

func (vc *VectorClock) Act(actor string)

Act records an action of an actor.

func (*VectorClock) IsConflicting

func (vc *VectorClock) IsConflicting(otherVC *VectorClock) bool

IsConflicting determines if another vector clock is conflicting with this vector clock.

func (*VectorClock) IsDescendent

func (vc *VectorClock) IsDescendent(otherVC *VectorClock) bool

IsDescendent determines if another vector clock is a descendent of this vector clock.

func (*VectorClock) String

func (vc *VectorClock) String() string

String returns a string representation of this vector clock.

func (*VectorClock) Version

func (vc *VectorClock) Version(actor string) uint64

Version returns the current version for a given actor.

Jump to

Keyboard shortcuts

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