Class SerializedSwiftSparseMap<T>
- Namespace
- SwiftCollections.Unity
Unity-serializable adapter for persisted compact integer-ID values consumed as a SwiftSparseMap<T>.
[Serializable]
public sealed class SerializedSwiftSparseMap<T> : ISerializationCallbackReceiver
Type Parameters
TA Unity-serializable value type.
- Inheritance
-
SerializedSwiftSparseMap<T>
- Implements
-
ISerializationCallbackReceiver
- Inherited Members
Properties
Count
Gets the number of mapped IDs.
public int Count { get; }
Property Value
this[int]
Gets or sets a value by integer key and updates the serialized backing entries.
public T this[int key] { get; set; }
Parameters
keyintThe non-negative integer key.
Property Value
- T
The value associated with the key.
Exceptions
- ArgumentOutOfRangeException
keyis negative.
Runtime
Gets the live runtime sparse map rebuilt from Unity serialized data.
public SwiftSparseMap<T> Runtime { get; }
Property Value
Remarks
Direct runtime mutations are copied into serialized backing data before Unity serialization.
Methods
Add(int, T)
Adds a key/value pair to the runtime sparse map and updates the serialized backing entries.
public bool Add(int key, T value)
Parameters
keyintThe non-negative key to add.
valueTThe value to add.
Returns
- bool
truewhen the key was added; otherwisefalse.
Exceptions
- ArgumentOutOfRangeException
keyis negative.
Clear()
Removes all entries from the runtime sparse map and serialized backing array.
public void Clear()
ContainsKey(int)
Returns whether the sparse map contains the key.
public bool ContainsKey(int key)
Parameters
keyintThe non-negative key to find.
Returns
- bool
truewhen the key exists; otherwisefalse.
Exceptions
- ArgumentOutOfRangeException
keyis negative.
GetEnumerator()
Returns an enumerator for the runtime sparse map.
public SwiftSparseMap<T>.SwiftSparseMapEnumerator GetEnumerator()
Returns
- SwiftSparseMap<T>.SwiftSparseMapEnumerator
A SwiftCollections sparse map enumerator.
OnAfterDeserialize()
Rebuilds runtime contents after Unity deserialization.
public void OnAfterDeserialize()
Exceptions
- ArgumentOutOfRangeException
A serialized entry has a negative key.
- InvalidOperationException
Serialized entries contain duplicate keys.
OnBeforeSerialize()
Copies live runtime contents into Unity's serialized backing data.
public void OnBeforeSerialize()
Remove(int)
Removes a key from the runtime sparse map and updates the serialized backing entries.
public bool Remove(int key)
Parameters
keyintThe non-negative key to remove.
Returns
- bool
truewhen the key was removed; otherwisefalse.
Exceptions
- ArgumentOutOfRangeException
keyis negative.
SetItems(params SerializedSwiftSparseMapEntry<T>[])
Replaces the serialized contents with a copy of the supplied entries.
public void SetItems(params SerializedSwiftSparseMapEntry<T>[] items)
Parameters
itemsSerializedSwiftSparseMapEntry<T>[]The key/value entries to persist.
Exceptions
- ArgumentNullException
itemsis null.- ArgumentOutOfRangeException
An entry has a negative key.
- InvalidOperationException
itemscontains duplicate keys.
ToArray()
Returns a copy of the serialized entries.
public SerializedSwiftSparseMapEntry<T>[] ToArray()
Returns
- SerializedSwiftSparseMapEntry<T>[]
A new array containing the current entries.
ToSwiftSparseMap()
Returns a copy as a standalone SwiftSparseMap<T>.
public SwiftSparseMap<T> ToSwiftSparseMap()
Returns
- SwiftSparseMap<T>
A new sparse map containing the current entries.
TryGetValue(int, out T)
Attempts to get the value associated with the key.
public bool TryGetValue(int key, out T value)
Parameters
keyintThe non-negative key to find.
valueTThe associated value when found.
Returns
- bool
truewhen the key exists; otherwisefalse.
Exceptions
- ArgumentOutOfRangeException
keyis negative.