algo

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package algo contains algorithms such as merging, intersecting sorted lists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyFilter

func ApplyFilter(u *task.List, f func(uint64, int) bool)

ApplyFilter applies a filter to our UIDList.

func BlockToList

func BlockToList(b *task.List) []uint64

func Difference

func Difference(u, v *task.List)

func Idx

func Idx(ul *task.List, i, j int) int

func IndexOf

func IndexOf(u *task.List, uid uint64) (int, int)

IndexOf performs a binary search on the uids slice and returns the index at which it finds the uid, else returns -1

func IntersectSorted

func IntersectSorted(lists []*task.List) *task.List

IntersectSorted intersect a list of UIDLists. An alternative is to do pairwise intersections n-1 times where n=number of lists. This is less efficient: Let p be length of shortest list. Let q be average length of lists. So nq = total number of elements. There are many possible cases. Consider the case where the shortest list is the answer (or close to the answer). The following method requires nq reads (each element is read only once) whereas pairwise intersections can require np + nq - p reads, which can be up to ~twice as many.

func IntersectWith

func IntersectWith(u, v *task.List)

func ItemAtIndex

func ItemAtIndex(ul *task.List, i int) uint64

func ListLen

func ListLen(l *task.List) int

func MergeSorted

func MergeSorted(lists []*task.List) *task.List

MergeSorted merges sorted lists.

func Slice

func Slice(ul *task.List, start, end int)

Slice returns a new task.List with the elements between start index and end index of the list passed to it.

func Sort

func Sort(ul *task.List)

func SortedListToBlock

func SortedListToBlock(l []uint64) *task.List

func Swap

func Swap(ul *task.List, i, j int)

func ToUintsListForTest

func ToUintsListForTest(ul []*task.List) [][]uint64

ToUintsListForTest converts to list of uints for testing purpose only.

Types

type AsList

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

AsList implements sort.Interface by for block lists

func (AsList) Len

func (s AsList) Len() int

func (AsList) Less

func (s AsList) Less(i, j int) bool

func (AsList) Swap

func (s AsList) Swap(i, j int)

type ListIterator

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

ListIterator is used to read through the task.List.

func NewListIterator

func NewListIterator(l *task.List) ListIterator

NewListIterator returns a read iterator for the list passed to it.

func (*ListIterator) Next

func (l *ListIterator) Next()

Next moves the iterator to the next element and also sets the end if the last element is consumed already.

func (*ListIterator) Seek

func (l *ListIterator) Seek(uid uint64, whence int)

Seek seeks to the index whose value is greater than or equal to the given UID. It uses binary search to move around.

func (*ListIterator) SeekToIndex

func (l *ListIterator) SeekToIndex(idx int)

SeekToIndex moves the iterator to the specified index.

func (*ListIterator) Val

func (l *ListIterator) Val() uint64

Val returns the value pointed to by the iterator.

func (*ListIterator) Valid

func (l *ListIterator) Valid() bool

Valid returns true if we haven't reached the end of the list.

type WriteIterator

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

WriteIterator is used to append UIDs to a task.List.

func NewWriteIterator

func NewWriteIterator(l *task.List, whence int) WriteIterator

func (*WriteIterator) Append

func (l *WriteIterator) Append(uid uint64)

Append appends an UID to the end of task.List following the blockSize specified.

func (*WriteIterator) End

func (l *WriteIterator) End()

End is called after the write is over to update the MaxInt of the last block.

Jump to

Keyboard shortcuts

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