Class SquareEdgeMap<TData>
Lightweight dictionary wrapper that stores arbitrary data keyed by SquareEdgeCoord.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class SquareEdgeMap<TData>
Type Parameters
| Name | Description |
|---|---|
| TData | The type of data stored per edge. May be any managed type, including value types, reference types, and nullable value types. |
Remarks
SquareEdgeMap<TData> is intended for sparse per-edge annotations such as
wall flags, door states, flow magnitudes, or passage costs. Only edges that have been
explicitly set via Set(SquareEdgeCoord, TData) consume memory; absent edges return nothing from
TryGet(SquareEdgeCoord, out TData).
All keys use the canonical N/W encoding defined by SquareEdgeDirection. To avoid duplicate entries ensure that edges are always addressed through their canonical anchor cell (see SquareEdgeCoord for the canonicalization rules).
Iteration is allocation-free when performed with foreach on the concrete type
because GetEnumerator() returns a value-type SquareEdgeMap<TData>.Enumerator.
Constructors
SquareEdgeMap()
Creates a new empty square edge map with the default initial capacity.
Declaration
public SquareEdgeMap()
SquareEdgeMap(int)
Creates a new empty square edge map pre-allocated for at least
capacity entries.
Declaration
public SquareEdgeMap(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | The initial number of entries to reserve space for. Providing an accurate estimate avoids rehashing overhead as the map grows. Must be non-negative. |
Properties
Count
Gets the number of edges that currently have data stored in this map.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | A non-negative integer equal to the number of successful Set(SquareEdgeCoord, TData) calls that have not been subsequently undone by TryRemove(SquareEdgeCoord, out TData) or Clear(). |
Methods
Clear()
Removes all entries from this map, resetting Count to zero.
Declaration
public void Clear()
Remarks
The internal dictionary's capacity is retained after clearing; the underlying memory is not released. Call after a batch operation that no longer needs the stored data.
Contains(SquareEdgeCoord)
Determines whether data exists at coord.
Declaration
public bool Contains(SquareEdgeCoord coord)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | coord | The canonical edge coordinate to check. |
Returns
| Type | Description |
|---|---|
| bool |
|
GetEnumerator()
Returns a value-type enumerator that iterates through all populated edge entries.
Declaration
public SquareEdgeMap<TData>.Enumerator GetEnumerator()
Returns
| Type | Description |
|---|---|
| SquareEdgeMap<TData>.Enumerator | An SquareEdgeMap<TData>.Enumerator positioned before the first entry. Iteration order matches the internal dictionary's unspecified insertion-dependent order. |
Remarks
Because the return type is the concrete value-type SquareEdgeMap<TData>.Enumerator (not
IEnumerator<T>), using this method in a foreach loop on the
concrete SquareEdgeMap<TData> type avoids heap allocation.
Set(SquareEdgeCoord, TData)
Sets the data at coord, inserting a new entry or overwriting an
existing one as needed.
Declaration
public void Set(SquareEdgeCoord coord, TData value)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | coord | The canonical edge coordinate to write. |
| TData | value | The data to associate with |
TryGet(SquareEdgeCoord, out TData)
Attempts to retrieve the data stored at coord.
Declaration
public bool TryGet(SquareEdgeCoord coord, out TData value)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | coord | The canonical edge coordinate to look up. |
| TData | value | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryRemove(SquareEdgeCoord, out TData)
Attempts to remove the entry at coord and retrieve its value.
Declaration
public bool TryRemove(SquareEdgeCoord coord, out TData value)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareEdgeCoord | coord | The canonical edge coordinate to remove. |
| TData | value | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|