Class MultiSpatialMap<T>
An implementation of ISpatialMap<T> that allows multiple items to reside at any given position at the same time. If you wish to allow only one item to reside at each location at a time, use SpatialMap<T> instead. For a situation involving different categories or layers of items, you may want to look at LayeredSpatialMap<T>.
Inherited Members
Namespace: SadRogue.Primitives.SpatialMaps
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class MultiSpatialMap<T> : AdvancedMultiSpatialMap<T>, ISpatialMap<T>, IReadOnlySpatialMap<T>, IEnumerable<ItemPositionPair<T>>, IEnumerable where T : class, IHasID
Type Parameters
Name | Description |
---|---|
T | The type of items being stored in the spatial map. Must implement IHasID and be a reference-type. |
Remarks
See the ISpatialMap<T> for documentation on the practical purpose of spatial maps.
The objects stored in a MultiSpatialMap must implement IHasID. This is used internally to keep track of the objects, since uints are easily (and efficiently) hashable. If you cannot or do not wish to implement this interface, use AdvancedMultiSpatialMap<T> instead.
Although MultiSpatialMap is generally quite performant, if you know the spatial map will only have one item at any given position at a time, SpatialMap<T> may yield better performance.
Constructors
MultiSpatialMap(IListPool<T>, IEqualityComparer<Point>, Int32)
Constructor.
Declaration
public MultiSpatialMap(IListPool<T> listPool, IEqualityComparer<Point> pointComparer = null, int initialCapacity = 32)
Parameters
Type | Name | Description |
---|---|---|
IListPool<T> | listPool | The list pool implementation to use. Specify NoPoolingListPool<T> to disable pooling entirely. This implementation may be shared with other spatial maps if you wish, however be aware that no thread safety is implemented by the default list pool implementations or the spatial map itself. |
IEqualityComparer<Point> | pointComparer | Equality comparer to use for comparison and hashing of points, as object are added to/removed from/moved around the spatial map. Be especially mindful of the efficiency of its GetHashCode function, as it will determine the efficiency of many MultiSpatialMap functions. Defaults to the default equality comparer for Point, which uses a fairly efficient generalized hashing algorithm. |
Int32 | initialCapacity | The initial maximum number of elements the spatial map can hold before it has to internally resize data structures. Defaults to 32. |
MultiSpatialMap(IEqualityComparer<Point>, Int32)
Constructor.
Declaration
public MultiSpatialMap(IEqualityComparer<Point> pointComparer = null, int initialCapacity = 32)
Parameters
Type | Name | Description |
---|---|---|
IEqualityComparer<Point> | pointComparer | Equality comparer to use for comparison and hashing of points, as object are added to/removed from/moved around the spatial map. Be especially mindful of the efficiency of its GetHashCode function, as it will determine the efficiency of many MultiSpatialMap functions. Defaults to the default equality comparer for Point, which uses a fairly efficient generalized hashing algorithm. |
Int32 | initialCapacity | The initial maximum number of elements the spatial map can hold before it has to internally resize data structures. Defaults to 32. |