Table of Contents

Class SwiftSpatialHash<TKey, TVolume>

Namespace
SwiftCollections.Query
Assembly
SwiftCollections.dll

Represents a mutable spatial hash that indexes keyed bounding volumes into deterministic integer grid cells.

public class SwiftSpatialHash<TKey, TVolume> where TKey : notnull where TVolume : struct, IBoundVolume<TVolume>

Type Parameters

TKey

The key used to identify each stored entry.

TVolume

The volume type used for broad-phase registration and queries.

Inheritance
SwiftSpatialHash<TKey, TVolume>
Derived
Inherited Members

Constructors

SwiftSpatialHash(int, ISpatialHashCellMapper<TVolume>)

Initializes a new instance of the SwiftSpatialHash<TKey, TVolume> class.

public SwiftSpatialHash(int capacity, ISpatialHashCellMapper<TVolume> cellMapper)

Parameters

capacity int

The initial entry capacity.

cellMapper ISpatialHashCellMapper<TVolume>

The mapper that projects volumes into deterministic cell coordinates.

SwiftSpatialHash(int, ISpatialHashCellMapper<TVolume>, SwiftSpatialHashOptions)

Initializes a new instance of the SwiftSpatialHash<TKey, TVolume> class.

public SwiftSpatialHash(int capacity, ISpatialHashCellMapper<TVolume> cellMapper, SwiftSpatialHashOptions options)

Parameters

capacity int

The initial entry capacity.

cellMapper ISpatialHashCellMapper<TVolume>

The mapper that projects volumes into deterministic cell coordinates.

options SwiftSpatialHashOptions

Spatial hash query options.

Properties

Count

Gets the number of active entries stored in the spatial hash.

public int Count { get; }

Property Value

int

Options

Gets the options used by this spatial hash.

public SwiftSpatialHashOptions Options { get; }

Property Value

SwiftSpatialHashOptions

Methods

Clear()

Removes all entries and cell registrations from the spatial hash.

public void Clear()

CollectCellCandidates(SwiftSpatialHashCellIndex, ICollection<TKey>)

Collects every entry registered in one already-mapped spatial cell.

protected void CollectCellCandidates(SwiftSpatialHashCellIndex cell, ICollection<TKey> results)

Parameters

cell SwiftSpatialHashCellIndex
results ICollection<TKey>

Contains(TKey)

Determines whether the spatial hash contains the specified key.

public bool Contains(TKey key)

Parameters

key TKey

Returns

bool

EnsureCapacity(int)

Ensures the spatial hash can store the specified number of entries without growing its entry storage.

public void EnsureCapacity(int capacity)

Parameters

capacity int

Insert(TKey, TVolume)

Inserts a new entry or replaces the bounds of an existing key.

public bool Insert(TKey key, TVolume bounds)

Parameters

key TKey

The entry key.

bounds TVolume

The entry bounds.

Returns

bool

true when a new key was added; false when an existing key was replaced.

Query(TVolume, ICollection<TKey>)

Queries the spatial hash and returns only entries whose bounds intersect the supplied query volume.

public void Query(TVolume queryBounds, ICollection<TKey> results)

Parameters

queryBounds TVolume
results ICollection<TKey>

QueryNeighborhood(TVolume, ICollection<TKey>)

Queries the spatial hash using the supplied query volume plus the configured neighborhood padding.

public void QueryNeighborhood(TVolume queryBounds, ICollection<TKey> results)

Parameters

queryBounds TVolume
results ICollection<TKey>

Remove(TKey)

Removes an entry from the spatial hash.

public bool Remove(TKey key)

Parameters

key TKey

The entry key.

Returns

bool

true when the key existed and was removed; otherwise, false.

TryGetBounds(TKey, out TVolume)

Attempts to retrieve the bounds registered for the supplied key.

public bool TryGetBounds(TKey key, out TVolume bounds)

Parameters

key TKey
bounds TVolume

Returns

bool

UpdateEntryBounds(TKey, TVolume)

Updates the bounds for an existing entry.

public bool UpdateEntryBounds(TKey key, TVolume newBounds)

Parameters

key TKey

The entry key.

newBounds TVolume

The replacement bounds.

Returns

bool

true when the key existed; otherwise, false.