Table of Contents

Class SerializedSwiftSparseMap<T>

Unity-serializable adapter for persisted compact integer-ID values consumed as a SwiftSparseMap<T>.

[Serializable]
public sealed class SerializedSwiftSparseMap<T> : ISerializationCallbackReceiver

Type Parameters

T

A 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

int

this[int]

Gets or sets a value by integer key and updates the serialized backing entries.

public T this[int key] { get; set; }

Parameters

key int

The non-negative integer key.

Property Value

T

The value associated with the key.

Exceptions

ArgumentOutOfRangeException

key is negative.

Runtime

Gets the live runtime sparse map rebuilt from Unity serialized data.

public SwiftSparseMap<T> Runtime { get; }

Property Value

SwiftSparseMap<T>

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

key int

The non-negative key to add.

value T

The value to add.

Returns

bool

true when the key was added; otherwise false.

Exceptions

ArgumentOutOfRangeException

key is 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

key int

The non-negative key to find.

Returns

bool

true when the key exists; otherwise false.

Exceptions

ArgumentOutOfRangeException

key is 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

key int

The non-negative key to remove.

Returns

bool

true when the key was removed; otherwise false.

Exceptions

ArgumentOutOfRangeException

key is negative.

SetItems(params SerializedSwiftSparseMapEntry<T>[])

Replaces the serialized contents with a copy of the supplied entries.

public void SetItems(params SerializedSwiftSparseMapEntry<T>[] items)

Parameters

items SerializedSwiftSparseMapEntry<T>[]

The key/value entries to persist.

Exceptions

ArgumentNullException

items is null.

ArgumentOutOfRangeException

An entry has a negative key.

InvalidOperationException

items contains 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

key int

The non-negative key to find.

value T

The associated value when found.

Returns

bool

true when the key exists; otherwise false.

Exceptions

ArgumentOutOfRangeException

key is negative.