Photon Fusion 2.0.3

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
NetworkDictionary< K, V > Struct Template Reference

Fusion type for networking Dictionaries. Maximum capacity is fixed, and is set with the CapacityAttribute.

More...

Inherits IEnumerable< KeyValuePair< K, V >>, and INetworkDictionary.

Classes

struct  Enumerator
 Enumerator for NetworkDictionary. More...
 

Public Member Functions

bool Add (K key, V value)
 Adds a new key value pair to the Dictionary. If the key already exists, will return false. More...
 
void INetworkDictionary. Add (object item)
 Adds an item to the networked dictionary. More...
 
void Clear ()
 Remove all entries from the Dictionary, and clear backing memory. More...
 
void ClrEntry (int entry)
 
bool ContainsKey (K key)
 Returns true if the Dictionary contains an entry for the given key. More...
 
bool ContainsValue (V value, IEqualityComparer< V > equalityComparer=null)
 Returns true if the Dictionary contains an entry value which compares as equal to given value. More...
 
int Find (K key)
 
Get (K key)
 Returns the value for the given key. Will throw an error if the key is not found. More...
 
uint GetBucketFromHashCode (int hash)
 
Enumerator GetEnumerator ()
 Returns an enumerator that iterates through the NetworkDictionary. More...
 
IEnumerator< KeyValuePair< K, V > > IEnumerable< KeyValuePair< K, V > >. GetEnumerator ()
 
IEnumerator IEnumerable. GetEnumerator ()
 
GetKey (int entry)
 
int GetKeyHashCode (K key)
 
int GetNxt (int entry)
 
GetVal (int entry)
 
int Insert (K key, V val)
 
 NetworkDictionary (int *data, int capacity, IElementReaderWriter< K > keyReaderWriter, IElementReaderWriter< V > valReaderWriter)
 Initializes a new instance of the NetworkDictionary struct with the specified data, capacity, and reader/writers. More...
 
bool Remove (K key)
 Remove entry from Dictionary. More...
 
bool Remove (K key, out V value)
 Removes entry from Dictionary. If successful (key existed), returns true and the value of removed item. More...
 
Set (K key, V value)
 Sets the value for the given key. Will add a new key if the key does not already exist. More...
 
void SetKey (int entry, K key)
 
void SetNxt (int entry, int next)
 
void SetVal (int entry, V val)
 
NetworkDictionaryReadOnly< K, V > ToReadOnly ()
 Converts the current NetworkDictionary to a read-only version. More...
 
bool TryGet (K key, out V value)
 Attempts to get the value for a given key. If found, returns true. More...
 

Static Public Member Functions

static implicit operator NetworkDictionaryReadOnly< K, V > (NetworkDictionary< K, V > value)
 Converts the current NetworkDictionary to a read-only version. More...
 

Public Attributes

int _bucketsOffset
 
int _capacity
 
int * _data
 
int _entriesOffset
 
int _entryStride
 
EqualityComparer< K > _equalityComparer
 
int _keyOffset
 
IElementReaderWriter< K > _keyReaderWriter
 
int _nxtOffset
 
int _valOffset
 
IElementReaderWriter< V > _valReaderWriter
 

Static Public Attributes

const int FREE_COUNT_OFFSET = 1
 
const int FREE_OFFSET = 0
 
const int INVALID_ENTRY = 0
 
const int META_WORD_COUNT = 3
 Meta word count for NetworkDictionary. More...
 
const int USED_COUNT_OFFSET = 2
 

Properties

int _free [get, set]
 
int _freeCount [get, set]
 
int _usedCount [get, set]
 
int Capacity [get]
 The maximum number of entries this dictionary may contain. More...
 
int Count [get]
 Current number of key/value entries in the Dictionary. More...
 
this[K key] [get, set]
 Key indexer. Gets/Sets value for specified key. More...
 

Detailed Description

Fusion type for networking Dictionaries. Maximum capacity is fixed, and is set with the CapacityAttribute.

Typical Usage: [Networked, Capacity(10)]
NetworkDictionary<int, float> syncedDict => default;

Usage for modifying data: var dict = syncedDict; dict.Add(5, 123); dict[5] = 456; dict.Remove(5);

Template Parameters
KKey can be a primitive, or an INetworkStruct.
VValue can be a primitive, or an INetworkStruct.

Constructor & Destructor Documentation

◆ NetworkDictionary()

NetworkDictionary ( int *  data,
int  capacity,
IElementReaderWriter< K >  keyReaderWriter,
IElementReaderWriter< V >  valReaderWriter 
)

Initializes a new instance of the NetworkDictionary struct with the specified data, capacity, and reader/writers.

Parameters
dataThe pointer to the data of the dictionary.
capacityThe capacity of the dictionary.
keyReaderWriterThe reader/writer for the keys of the dictionary.
valReaderWriterThe reader/writer for the values of the dictionary.

Member Function Documentation

◆ Add() [1/2]

bool Add ( key,
value 
)

Adds a new key value pair to the Dictionary. If the key already exists, will return false.

◆ Add() [2/2]

void INetworkDictionary. Add ( object  item)

Adds an item to the networked dictionary.

Parameters
itemThe item to add to the dictionary.

Implements INetworkDictionary.

◆ Clear()

void Clear ( )

Remove all entries from the Dictionary, and clear backing memory.

◆ ContainsKey()

bool ContainsKey ( key)

Returns true if the Dictionary contains an entry for the given key.

◆ ContainsValue()

bool ContainsValue ( value,
IEqualityComparer< V >  equalityComparer = null 
)

Returns true if the Dictionary contains an entry value which compares as equal to given value.

Parameters
valueThe value to compare against.
equalityComparerSpecify custom IEqualityComparer to be used for compare.

◆ Get()

V Get ( key)

Returns the value for the given key. Will throw an error if the key is not found.

◆ GetEnumerator()

Enumerator GetEnumerator ( )

Returns an enumerator that iterates through the NetworkDictionary.

◆ operator NetworkDictionaryReadOnly< K, V >()

static implicit operator NetworkDictionaryReadOnly< K, V > ( NetworkDictionary< K, V >  value)
static

Converts the current NetworkDictionary to a read-only version.

Parameters
valueThe NetworkDictionary to convert.
Returns
A new instance of NetworkDictionaryReadOnly with the same data, capacity, and reader/writers as the current NetworkDictionary.

◆ Remove() [1/2]

bool Remove ( key)

Remove entry from Dictionary.

Parameters
keyThe key to remove.
Returns
Returns true if key was found.

◆ Remove() [2/2]

bool Remove ( key,
out V  value 
)

Removes entry from Dictionary. If successful (key existed), returns true and the value of removed item.

Parameters
keyThe key to remove.
valueReturns value of removed item. Returns default value if key did not exist.
Returns
Returns true if key was found.

◆ Set()

V Set ( key,
value 
)

Sets the value for the given key. Will add a new key if the key does not already exist.

◆ ToReadOnly()

NetworkDictionaryReadOnly<K, V> ToReadOnly ( )

Converts the current NetworkDictionary to a read-only version.

Returns
A new instance of NetworkDictionaryReadOnly with the same data, capacity, and reader/writers as the current NetworkDictionary.

◆ TryGet()

bool TryGet ( key,
out V  value 
)

Attempts to get the value for a given key. If found, returns true.

Parameters
keyThe key to remove.
valueReturns value of removed item. Returns default value if key did not exist.
Returns
Returns true if key was found.

Member Data Documentation

◆ META_WORD_COUNT

const int META_WORD_COUNT = 3
static

Meta word count for NetworkDictionary.

Property Documentation

◆ Capacity

int Capacity
get

The maximum number of entries this dictionary may contain.

◆ Count

int Count
get

Current number of key/value entries in the Dictionary.

◆ this[K key]

V this[K key]
getset

Key indexer. Gets/Sets value for specified key.