hash

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeGridKey

func DecodeGridKey(key uint64) (x, y int32)

func EncodeGridKey

func EncodeGridKey(x, y int32) uint64

Types

type Grid

type Grid[T comparable] struct {
	// contains filtered or unexported fields
}

Grid is a simple spatial hash grid that stores items in cells based on their coordinates.

Use this for static or infrequently-updated items. It is a minimalist implementation.

func NewGrid

func NewGrid[T comparable](cellWidth, cellHeight float32) *Grid[T]

func (*Grid[T]) CellSize

func (g *Grid[T]) CellSize() (cellWidth, cellHeight float32)

func (*Grid[T]) Cells

func (g *Grid[T]) Cells() []uint64

func (*Grid[T]) Clear

func (g *Grid[T]) Clear()

Clear removes all items from the grid.

func (*Grid[T]) Contains

func (g *Grid[T]) Contains(item T) bool

Contains checks if the item is already in the grid.

func (*Grid[T]) Each

func (g *Grid[T]) Each(region [4]float32, fn func(item T) bool)

func (*Grid[T]) ForEach

func (g *Grid[T]) ForEach(fn func(item T))

ForEach calls the given function for each item in the grid.

func (*Grid[T]) Insert

func (g *Grid[T]) Insert(item T, region [4]float32, padding GridItemPadding) bool

Insert adds an item to the grid. Returns false if the item was already present.

func (*Grid[T]) InsertFunc

func (g *Grid[T]) InsertFunc(item T, region [4]float32, padding GridItemPadding, fn GridInsertionFunc[T]) bool

InsertFunc is like Insert but allows a function to determine per-cell insertion.

func (*Grid[T]) Query

func (g *Grid[T]) Query(region [4]float32) []T

Query returns all items that intersect the given AABB.

func (*Grid[T]) QueryCells

func (g *Grid[T]) QueryCells(region [4]float32) []uint64

func (*Grid[T]) Remove

func (g *Grid[T]) Remove(item T)

Remove removes an item from the grid.

Cells are removed if they are no longer storing an item.

func (*Grid[T]) Resize

func (g *Grid[T]) Resize(cellWidth, cellHeight float32)

Resize changes the cell size of the grid, clearing all existing items. If the size is unchanged, no action is taken.

WARNING: This will remove all existing items in the grid.

type GridInsertionFunc

type GridInsertionFunc[T comparable] func(minX, minY, maxX, maxY float32) bool

type GridItemPadding

type GridItemPadding uint8
const (
	NoGridPadding   GridItemPadding = 0
	GridCellPadding GridItemPadding = 1
)

type Set

type Set[T comparable] map[T]struct{}

func NewSet

func NewSet[T comparable](size ...int) Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(item T) bool

func (*Set[T]) Contains

func (s *Set[T]) Contains(item T) bool

func (*Set[T]) Remove

func (s *Set[T]) Remove(item T)

func (*Set[T]) Size

func (s *Set[T]) Size() int

func (*Set[T]) ToSlice

func (s *Set[T]) ToSlice() []T

Jump to

Keyboard shortcuts

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