package datastruct
import "github.com/jphsd/datastruct"
Index ¶
- func Bounds(points ...[]float64) [][]float64
- func Contains(a, b Set) bool
- func Disjoint(a, b Set) bool
- func InvertSort(values []int) []int
- func Within(d1, d2, e float64) bool
- type BBGrid
- func NewBBGrid(r, c int, bb [][]float64) *BBGrid
- func (g *BBGrid) Add(id int, bb [][]float64) error
- func (g *BBGrid) Cell(r, c int) []int
- func (g *BBGrid) Len() int
- func (g *BBGrid) Location(p []float64) (int, int, error)
- func (g *BBGrid) Range(bb [][]float64) []int
- func (g *BBGrid) Remove(id int)
- type BBNode
- func NewBBNode(id int, parent *BBNode, bb [][]float64) *BBNode
- func (bn *BBNode) Contains(pt []float64) bool
- func (bn *BBNode) Decompose(id int, bb [][]float64)
- func (bn *BBNode) Flatten() [][][]float64
- func (bn *BBNode) Intersection(bb [][]float64) [][]float64
- func (bn *BBNode) Leaves() [][][]float64
- func (bn *BBNode) Search(pt []float64, path []*BBNode) []*BBNode
- type BBTree
- func NewBBTree() *BBTree
- func (bt *BBTree) Flatten() [][][]float64
- func (bt *BBTree) Insert(id int, bb [][]float64)
- func (bt *BBTree) Leaves() [][][]float64
- func (bt *BBTree) Search(pt []float64) []*BBNode
- type BRRow
- func NewBRRow(c int, b []float64) *BRRow
- func (g *BRRow) Add(id int, br []float64) error
- func (g *BRRow) Cell(c int) []int
- func (g *BRRow) Len() int
- func (g *BRRow) Location(p float64) (int, error)
- func (g *BRRow) Remove(id int)
- type Bits
- func BitsFromSlice(in []bool) Bits
- func NewBits(n int) Bits
- func (b Bits) Clear(i int)
- func (b Bits) Get(i int) bool
- func (b Bits) Set(i int)
- func (b Bits) Slice() []bool
- type KDNode
- func (n *KDNode) Insert(dims int, p []float64, axis int) *KDNode
- func (n *KDNode) Points() [][]float64
- func (n *KDNode) String() string
- type KDTree
- func NewKDTree(dims int, points ...[]float64) *KDTree
- func (t *KDTree) Balance()
- func (t *KDTree) DNN(pt []float64, d float64) ([][]float64, []float64, []int)
- func (t *KDTree) InOrderPoints() [][]float64
- func (t *KDTree) Insert(pt []float64) int
- func (t *KDTree) KNN(pt []float64, k int) ([][]float64, []float64, []int)
- func (t *KDTree) Points() [][]float64
- func (t *KDTree) RemoveById(id int) bool
- func (t *KDTree) RemoveByPoint(pt []float64) bool
- func (t *KDTree) String() string
- type PointGrid
- func NewPointGrid(rows, columns int, bounds [][]float64, wrap bool) *PointGrid
- func (g *PointGrid) Add(p []float64) (int, int, error)
- func (g *PointGrid) AdjacentCells(row, column int) [][]float64
- func (g *PointGrid) Cell(row, column int) [][]float64
- func (g *PointGrid) Len() int
- func (g *PointGrid) Location(p []float64) (int, int, error)
- func (g *PointGrid) NearestPoint(p []float64) ([]float64, float64, error)
- type PriorityItem
- type PriorityList
- func NewPriorityList(items ...PriorityItem) *PriorityList
- func (pq *PriorityList) Delete(v PriorityItem) bool
- func (pq *PriorityList) DeleteEntry(e int) bool
- func (pq *PriorityList) DeleteId(id int) bool
- func (pq *PriorityList) Insert(v PriorityItem) int
- func (pq *PriorityList) Where(v float64, left bool) int
- type Set
- func Difference(a, b Set) Set
- func Intersection(a, b Set) Set
- func NewSet(elts ...int) Set
- func Sub(a, b Set) Set
- func Union(a, b Set) Set
- func (s Set) Add(e int) bool
- func (s Set) Contains(b Set) bool
- func (s Set) Copy() Set
- func (s Set) Difference(b Set) Set
- func (s Set) Disjoint(b Set) bool
- func (s Set) Element(e int) bool
- func (s Set) Empty() bool
- func (s Set) Intersection(b Set) Set
- func (s Set) Len() int
- func (s Set) Purge()
- func (s Set) Remove(e int) bool
- func (s Set) Slice() []int
- func (s Set) String() string
- func (s Set) Sub(b Set) Set
- func (s Set) Union(b Set) Set
Functions ¶
func Bounds ¶
func Contains ¶
Contains returns true if b is completely contained in a.
func Disjoint ¶
Disjoint returns true if a and b share no elements in common.
func InvertSort ¶
InvertSort returns the list of switches that need to be made to render a list of integers into a sorted one.
func Within ¶
Within returns true if the two values are within e of each other.
Types ¶
type BBGrid ¶
type BBGrid struct { Rows, Columns int // Grid cells down and across Min, Max []float64 // Bounds of the space // contains filtered or unexported fields }
func NewBBGrid ¶
func (*BBGrid) Add ¶
func (*BBGrid) Cell ¶
func (*BBGrid) Len ¶
func (*BBGrid) Location ¶
func (*BBGrid) Range ¶
func (*BBGrid) Remove ¶
This is expensive as every cell is checked
type BBNode ¶
func NewBBNode ¶
func (*BBNode) Contains ¶
func (*BBNode) Decompose ¶
func (*BBNode) Flatten ¶
func (*BBNode) Intersection ¶
Find the bounding box of the intersection of bb with bn.BBox
func (*BBNode) Leaves ¶
func (*BBNode) Search ¶
type BBTree ¶
type BBTree struct { Root *BBNode }
func NewBBTree ¶
func NewBBTree() *BBTree
func (*BBTree) Flatten ¶
func (*BBTree) Insert ¶
func (*BBTree) Leaves ¶
func (*BBTree) Search ¶
type BRRow ¶
type BRRow struct { Columns int // Columns across Min, Max float64 // Bounds of the space // contains filtered or unexported fields }
Bounded region row, like BBGrid but for 1D regions
func NewBRRow ¶
func (*BRRow) Add ¶
func (*BRRow) Cell ¶
func (*BRRow) Len ¶
func (*BRRow) Location ¶
func (*BRRow) Remove ¶
This is expensive as every column is checked
type Bits ¶
type Bits []uint64
Bits contains a compact representation of booleans in a uint64.
func BitsFromSlice ¶
BitsFromSlice returns Bits initialized with the contents of the boolean slice
func NewBits ¶
NewBits allocates a new Bits with the given length rounded up to the nearest whole uint64
func (Bits) Clear ¶
Reset clears bit i
func (Bits) Get ¶
Get returns the state of bit i
func (Bits) Set ¶
Set sets bit i to true
func (Bits) Slice ¶
Slice returns the bit array as a slice of bool
type KDNode ¶
func (*KDNode) Insert ¶
func (*KDNode) Points ¶
func (*KDNode) String ¶
type KDTree ¶
func NewKDTree ¶
func (*KDTree) Balance ¶
func (t *KDTree) Balance()
func (*KDTree) DNN ¶
Find all points within d of pt. Note d must in in the same space as the Dist function
func (*KDTree) InOrderPoints ¶
func (*KDTree) Insert ¶
func (*KDTree) KNN ¶
Find up to k nearest points to pt Returns points, distances, indices to kdnodes
func (*KDTree) Points ¶
Insertion order
func (*KDTree) RemoveById ¶
func (*KDTree) RemoveByPoint ¶
Poor man's expensive
func (*KDTree) String ¶
type PointGrid ¶
type PointGrid struct { Rows, Columns int // Grid cells down and across Min, Max []float64 // Bounds of the space Wrap bool // Whether points should be wrapped in Min, Max // contains filtered or unexported fields }
PointGrid provides a simple way of finding points that are close to eachother.
func NewPointGrid ¶
NewPointGrid creates a new PointGrid with the supplied attributes.
func (*PointGrid) Add ¶
Add adds a point to the appropriate cell and returns its location.
func (*PointGrid) AdjacentCells ¶
AdjacentCells returns the points of the cell and the cells adjacent to it.
func (*PointGrid) Cell ¶
Cell returns all the points in it.
func (*PointGrid) Len ¶
Len returns the number of points stored in the grid.
func (*PointGrid) Location ¶
Location returns the grid location of a point (if it is within range).
func (*PointGrid) NearestPoint ¶
NearestPoint looks in the cell containing the point and adjacent cells for the closest point. Returns the point (if any) and its distance or an error. A very poor implementation of nearest neighbor.
type PriorityItem ¶
PriorityItem contains the priority value and an id.
type PriorityList ¶
type PriorityList []PriorityItem
PriorityList holds the prioritized list of items. The lower the priority, the closer to the start of the list the item is.
func NewPriorityList ¶
func NewPriorityList(items ...PriorityItem) *PriorityList
NewPriorityList creates a new PriorityList with the items inserted. Lower values are inserted before higher ones.
func (*PriorityList) Delete ¶
func (pq *PriorityList) Delete(v PriorityItem) bool
Delete removes the entry in the list with the item (if found) and returns true. If the item isn't then false is returned. The priority value in the item is used to find where the item occurs in the list.
func (*PriorityList) DeleteEntry ¶
func (pq *PriorityList) DeleteEntry(e int) bool
DeleteEntry removes an entry from the list, compacts it and returns true. If the entry is not in range then false is returned.
func (*PriorityList) DeleteId ¶
func (pq *PriorityList) DeleteId(id int) bool
DeleteId removes the entry in the list with the item id (if found) and returns true. If the id isn't found then false is returned. This function uses a linear scan to find the id.
func (*PriorityList) Insert ¶
func (pq *PriorityList) Insert(v PriorityItem) int
Insert inserts the item into the list at the correct point and returns that insertion point. Insertion is performed using a binary search and copy() for speed.
func (*PriorityList) Where ¶
func (pq *PriorityList) Where(v float64, left bool) int
Where returns where an item of priority pri would be inserted. The bool left indicates for priorities of the same value whether the new one should be inserted to the left or right of the current ones.
type Set ¶
Set represents a set of integer elements.
func Difference ¶
Difference returns a new set containing only the elements in either a or b but not in both (XOR).
func Intersection ¶
Intersection returns a new set containing the intersection of a and b (AND).
func NewSet ¶
NewSet returns a new set with the provided elements in it.
func Sub ¶
Sub returns a new set containing the elements in a which are not in b (SUB).
func Union ¶
Union returns a new set containing the union of a and b (OR).
func (Set) Add ¶
Add adds the element e to the set and returns true if it wasn't already in the set. Adding an element when it already exists is a no-op signified by false.
func (Set) Contains ¶
Contains returns true if b is completely contained in the set.
func (Set) Copy ¶
Copy makes a copy of the set.
func (Set) Difference ¶
Difference returns a new set containing only the elements in either the set or b but not in both (XOR).
func (Set) Disjoint ¶
Disjoint returns true if the set and b share no elements in common.
func (Set) Element ¶
Element returns true if the set contains the element e.
func (Set) Empty ¶
Empty returns true if the set is the empty set.
func (Set) Intersection ¶
Intersection returns a new set containing the intersection of the set and b (AND).
func (Set) Len ¶
Len returns the number of elements in the set.
func (Set) Purge ¶
func (s Set) Purge()
Purge clears out removed entries from the set.
func (Set) Remove ¶
Remove removes element e from the set, if it exists by setting it to false, and returns true if it was in the set. Removing a non-existent element is a no-op signified by false. Use Purge() to actually shrink the set.
func (Set) Slice ¶
Slice returns an unsorted slice representation of the set.
func (Set) String ¶
String returns a string representation of the set.
func (Set) Sub ¶
Sub returns a new set containing the elements in the set which are not in b (SUB).
func (Set) Union ¶
Union returns a new set containing the union of the set and b (OR).
Source Files ¶
bbgrid.go bbtree.go bits.go brrow.go inv.go kdtree.go pointgrid.go priority.go set.go
- Version
- v0.0.0-20230819004359-fdb942b23eca (latest)
- Published
- Aug 19, 2023
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 2 months ago –
Tools for package owners.