space

package
v0.0.0-...-6719cd2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package space defines abstract notions of points and ranges. It's used in Akutan to describe the keys and hashes that servers host.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ImplementPoint = []Point{
	Key(""),
	Hash64(0),
	Infinity,
}

ImplementPoint is a list of types that implement Point in this package. This serves as documentation and as a compile-time check.

Functions

func PointEq

func PointEq(a, b Point) bool

PointEq returns true if a == b.

func PointGeq

func PointGeq(a, b Point) bool

PointGeq returns true if a >= b.

func PointGt

func PointGt(a, b Point) bool

PointGt returns true if a > b.

func PointLeq

func PointLeq(a, b Point) bool

PointLeq returns true if a <= b.

func PointLt

func PointLt(a, b Point) bool

PointLt returns true if a < b.

Types

type Hash64

type Hash64 uint64

Hash64 is a type of Point in a 64-bit hash-space.

func (Hash64) Less

func (a Hash64) Less(b Point) bool

Less implements Point.Less using < on the integers values. All Hash64 values compare less than 'Infinity', so the full key-space is given by the following range:

Range { Start: Hash64(0), End: Infinity }

func (Hash64) String

func (a Hash64) String() string

String() returns the hex-formatted hash value.

Example
fmt.Printf("%v\n", Hash64(0))
fmt.Printf("%v\n", Hash64(0x100))
fmt.Printf("%v\n", Hash64(^uint64(0)))
Output:

0x0000000000000000
0x0000000000000100
0xFFFFFFFFFFFFFFFF

type InfinitePoint

type InfinitePoint struct{}

InfinitePoint is a sentinel for the largest possible Point value. It's commonly used as being the end of an entire space.

var Infinity InfinitePoint

Infinity is an instance of InfinitePoint, for convenience.

func (InfinitePoint) Less

func (a InfinitePoint) Less(b Point) bool

Less implements Point.Less by always returning false.

func (InfinitePoint) String

func (a InfinitePoint) String() string

Returns "∞".

type Key

type Key string

Key is a type of Point in a lexically-ordered string key-space.

func (Key) Less

func (a Key) Less(b Point) bool

Less implements Point.Less using < on the string values. All Key values compare less than 'Infinity', so the full key-space is given by the following range:

Range { Start: Key(""), End: Infinity }

func (Key) String

func (a Key) String() string

a.String() simply returns string(a). Note: this is not suitable for binary keys.

Example
var zero Key
fmt.Printf("1. %v.\n", zero)
fmt.Printf("2. %v.\n", Key(""))
fmt.Printf("3. %v.\n", Key("hello"))
Output:

1. .
2. .
3. hello.

type PartitionedRange

type PartitionedRange struct {
	// The first point of each subrange, in sorted order. StartPoints[i] represents
	// the subrange from StartPoints[i] to StartPoints[i+1]. The last entry
	// represents the subrange from itself to End.
	StartPoints []Point
	// Just past the final point in the overall range.
	End Point
}

A PartitionedRange is a compressed representation of a split up range. The entire range is StartPoints[0] to End. It's partitioned at the boundaries given by StartPoints[1:], so the number of subranges is len(StartPoints).

func (*PartitionedRange) Find

func (ranges *PartitionedRange) Find(point Point) int

Find returns the index of the subrange containing 'point'. It returns -1 if the point falls outside OverallRange().

Example
ranges := PartitionedRange{
	StartPoints: []Point{Key("d"), Key("m"), Key("t")},
	End:         Key("x"),
}
fmt.Print(
	ranges.Find(Key("diego")),
	ranges.Find(Key("alice")),
	ranges.Find(Key("raymond")),
	ranges.Find(Key("zara")),
	ranges.Find(Key("taylor")),
	ranges.Find(Key("simon")),
)
Output:

0 -1 1 -1 2 1

func (*PartitionedRange) Get

func (ranges *PartitionedRange) Get(i int) Range

Get returns the i-th subrange.

Example
ranges := PartitionedRange{
	StartPoints: []Point{Key("d"), Key("m"), Key("t")},
	End:         Key("x"),
}
fmt.Printf("%+v\n", ranges.Get(0))
fmt.Printf("%+v\n", ranges.Get(2))
Output:

{Start:d End:m}
{Start:t End:x}

func (*PartitionedRange) OverallRange

func (ranges *PartitionedRange) OverallRange() Range

OverallRange returns the range from the first point of the first subrange to the end point of the last subrange.

Example
ranges := PartitionedRange{
	StartPoints: []Point{Key("d"), Key("m"), Key("t")},
	End:         Key("x"),
}
fmt.Printf("%+v\n", ranges.OverallRange())
Output:

{Start:d End:x}

type Point

type Point interface {
	// Less compares point values. It returns true if this point has a strictly
	// smaller value than 'other', false otherwise.
	Less(other Point) bool
}

A Point is a location in a space. For example, a hash value in a hash-space is a Point. In this package, Hash64 and Key implement Point.

func PointMin

func PointMin(a, b Point) Point

PointMin returns the lesser of the 2 points

type Range

type Range struct {
	// The first Point in the range.
	Start Point
	// Just past the last Point in the range.
	End Point
}

A Range is an interval from the Start point up to but excluding the End point.

func (Range) Contains

func (r Range) Contains(point Point) bool

Contains returns true if the point falls within the range, false otherwise.

func (Range) Equals

func (r Range) Equals(other Range) bool

Equals returns true if both ranges cover the exact same points, false otherwise.

func (Range) Overlaps

func (r Range) Overlaps(other Range) bool

Overlaps returns true if both ranges cover at least one common point, false otherwise.

Jump to

Keyboard shortcuts

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