Class AdvancedMultiSpatialMap<T>
A more complex version of MultiSpatialMap<T> that does not require the items in it to implement IHasID, instead requiring the specification of a custom System.Collections.Generic.IEqualityComparer<T> to use for hashing and comparison of items.
Implements
Inherited Members
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
public class AdvancedMultiSpatialMap<T> : ISpatialMap<T>, IReadOnlySpatialMap<T>, IEnumerable<ISpatialTuple<T>>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T | The type of object that will be contained by this AdvancedMultiSpatialMap. |
Remarks
This class is useful for cases where you do not want to implement IHasID, or if you need to use a value type in a spatial map. For simple cases, it is recommended to use MultiSpatialMap<T> instead.
Be mindful of the efficiency of your hashing function specified in the System.Collections.Generic.IEqualityComparer<T> -- it will in large part determine the performance of AdvancedMultiSpatialMap!
Constructors
| Improve this Doc View SourceAdvancedMultiSpatialMap(IEqualityComparer<T>, Int32)
Constructor.
Declaration
public AdvancedMultiSpatialMap(IEqualityComparer<T> comparer, int initialCapacity = 32)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEqualityComparer<T> | comparer | Equality comparer to use for comparison and hashing of type T. Be especially mindful of the efficiency of its GetHashCode function, as it will determine the efficiency of many AdvancedMultiSpatialMap functions. |
| System.Int32 | initialCapacity | The initial maximum number of elements the AdvancedMultiSpatialMap can hold before it has to internally resize data structures. Defaults to 32. |
Properties
| Improve this Doc View SourceCount
See Count.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Items
See Items.
Declaration
public IEnumerable<T> Items { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> |
Positions
See Positions.
Declaration
public IEnumerable<Coord> Positions { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Coord> |
Methods
| Improve this Doc View SourceAdd(T, Coord)
Adds the given item at the given position, provided the item is not already in the spatial map. If the item is already contained in it, does nothing and returns false. Otherwise (if item was successfully added), returns true.
Declaration
public bool Add(T newItem, Coord position)
Parameters
| Type | Name | Description |
|---|---|---|
| T | newItem | The item to add. |
| Coord | position | The position at which to add the new item. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the item was added, false if the add operation failed. |
Add(T, Int32, Int32)
Adds the given item at the given position, provided the item is not already in the spatial map. If the item is already contained in it, does nothing and returns false. Otherwise (if item was successfully added), returns true.
Declaration
public bool Add(T newItem, int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| T | newItem | The item to add. |
| System.Int32 | x | x-value of the position to add item to. |
| System.Int32 | y | y-value of the position to add item to. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the item was added, false if the add operation failed. |
AsReadOnly()
See AsReadOnly().
Declaration
public IReadOnlySpatialMap<T> AsReadOnly()
Returns
| Type | Description |
|---|---|
| IReadOnlySpatialMap<T> |
Clear()
See Clear().
Declaration
public void Clear()
Contains(T)
See Contains(T).
Declaration
public bool Contains(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Contains(Coord)
See Contains(Coord).
Declaration
public bool Contains(Coord position)
Parameters
| Type | Name | Description |
|---|---|---|
| Coord | position |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Contains(Int32, Int32)
Declaration
public bool Contains(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | |
| System.Int32 | y |
Returns
| Type | Description |
|---|---|
| System.Boolean |
GetEnumerator()
Used by foreach loop, so that the class will give ISpatialTuple objects when used in a foreach loop. Generally should never be called explicitly.
Declaration
public IEnumerator<ISpatialTuple<T>> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<ISpatialTuple<T>> | An enumerator for the spatial map. |
GetItems(Coord)
See GetItems(Coord).
Declaration
public IEnumerable<T> GetItems(Coord position)
Parameters
| Type | Name | Description |
|---|---|---|
| Coord | position |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> |
GetItems(Int32, Int32)
Declaration
public IEnumerable<T> GetItems(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | |
| System.Int32 | y |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> |
GetPosition(T)
Declaration
public Coord GetPosition(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item |
Returns
| Type | Description |
|---|---|
| Coord |
Move(T, Coord)
Moves the item specified to the position specified. If the item does not exist in the spatial map, the function does nothing and returns false. Otherwise, returns true.
Declaration
public bool Move(T item, Coord target)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to move. |
| Coord | target | The position to move it to. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the item was moved, false if the move failed. |
Move(T, Int32, Int32)
Move the item specified to the position specified. If the item does not exist in the spatial map, the function does nothing and returns false. Otherwise, returns true.
Declaration
public bool Move(T item, int targetX, int targetY)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to move. |
| System.Int32 | targetX | X-value of the location to move it to. |
| System.Int32 | targetY | Y-value of the location to move it to. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the item was moved, false if the move failed. |
Move(Coord, Coord)
Moves everything at current, if anything, to target.
If something was moved, returns everything that was moved. If nothing was moved, eg. there
was nothing at current, returns nothing.
Declaration
public IEnumerable<T> Move(Coord current, Coord target)
Parameters
| Type | Name | Description |
|---|---|---|
| Coord | current | The position of the items to move. |
| Coord | target | The position to move the item to. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> | The items moved if something was moved, or nothing if no item was moved. |
Move(Int32, Int32, Int32, Int32)
Moves whatever is at the "current" position specified, if anything, to the "target" position. If something was moved, returns what was moved. If nothing was moved, eg. there was nothing at the "current" position given, returns nothing.
Declaration
public IEnumerable<T> Move(int currentX, int currentY, int targetX, int targetY)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | currentX | X-value of the location to move items from. |
| System.Int32 | currentY | Y-value of the location to move items from. |
| System.Int32 | targetX | X-value of the location to move items to. |
| System.Int32 | targetY | Y-value of the location to move items to. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> | The items moved if something was moved, or nothing if no item was moved. |
Remove(T)
Removes the item specified, if it exists, and returns true. Returns false if the item was not in the spatial map.
Declaration
public bool Remove(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to remove. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the item was removed, false if the item was not found. |
Remove(Coord)
Removes everything at the given position, and returns the items removed. Returns nothing if no items were at the position specified.
Declaration
public IEnumerable<T> Remove(Coord position)
Parameters
| Type | Name | Description |
|---|---|---|
| Coord | position | The position of the item to remove. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> | The items removed, if any were removed; nothing if no items were found at that position. |
Remove(Int32, Int32)
Removes everything at the given position, and returns the items removed. Returns nothing if no item was at the position specified.
Declaration
public IEnumerable<T> Remove(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X-value of the position to remove items from. |
| System.Int32 | y | Y-value of the position to remove items from. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> | The items removed, if any were removed; nothing if no items were found at that position. |
ToString()
Returns a string representation of the spatial map.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A string representation of the spatial map. |
Overrides
ToString(Func<T, String>)
Returns a string representation of the spatial map, allowing display of the spatial map's items in a specified way.
Declaration
public string ToString(Func<T, string> itemStringifier)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Func<T, System.String> | itemStringifier | Function that turns an item into a string. |
Returns
| Type | Description |
|---|---|
| System.String | A string representation of the spatial map. |
Events
| Improve this Doc View SourceItemAdded
See ItemAdded.
Declaration
public event EventHandler<ItemEventArgs<T>> ItemAdded
Event Type
| Type | Description |
|---|---|
| System.EventHandler<ItemEventArgs<T>> |
ItemMoved
See ItemMoved.
Declaration
public event EventHandler<ItemMovedEventArgs<T>> ItemMoved
Event Type
| Type | Description |
|---|---|
| System.EventHandler<ItemMovedEventArgs<T>> |
ItemRemoved
See ItemRemoved.
Declaration
public event EventHandler<ItemEventArgs<T>> ItemRemoved
Event Type
| Type | Description |
|---|---|
| System.EventHandler<ItemEventArgs<T>> |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Non-generic verion of enumerable used by foreach loop internally.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator | Enumerator of ISpatialTuples. |