63 IndexT Add(
const KEYTYPE& key,
const VALUETYPE& value);
93 template<
class RETURNTYPE> RETURNTYPE
KeysAs()
const;
95 template<
class RETURNTYPE> RETURNTYPE
ValuesAs()
const;
114template<
class KEYTYPE,
class VALUETYPE>
124template<
class KEYTYPE,
class VALUETYPE>
126 keyValuePairs(rhs.keyValuePairs),
129 #if NEBULA_BOUNDSCHECKS
137template<
class KEYTYPE,
class VALUETYPE>
139 keyValuePairs(std::move(rhs.keyValuePairs)),
142#if NEBULA_BOUNDSCHECKS
150template<
class KEYTYPE,
class VALUETYPE>
154 #if NEBULA_BOUNDSCHECKS
164template<
class KEYTYPE,
class VALUETYPE>
168#if NEBULA_BOUNDSCHECKS
172 this->keyValuePairs = std::move(rhs.keyValuePairs);
178template<
class KEYTYPE,
class VALUETYPE>
182 #if NEBULA_BOUNDSCHECKS
185 this->keyValuePairs.Clear();
191template<
class KEYTYPE,
class VALUETYPE>
195 return this->keyValuePairs.Size();
201template<
class KEYTYPE,
class VALUETYPE>
205 return (0 == this->keyValuePairs.Size());
211template<
class KEYTYPE,
class VALUETYPE>
215 this->keyValuePairs.Reserve(numElements);
221template<
class KEYTYPE,
class VALUETYPE>
225 #if NEBULA_BOUNDSCHECKS
228 this->inBulkInsert =
true;
234template<
class KEYTYPE,
class VALUETYPE>
238 #if NEBULA_BOUNDSCHECKS
241 this->keyValuePairs.Sort();
242 this->inBulkInsert =
false;
248template<
class KEYTYPE,
class VALUETYPE>
252 this->BeginBulkAdd();
265template<
class KEYTYPE,
class VALUETYPE>
269 if (this->inBulkInsert)
271 this->keyValuePairs.Append(kvp);
272 return this->keyValuePairs.Size() - 1;
276 return this->keyValuePairs.InsertSorted(kvp);
283template<
class KEYTYPE,
class VALUETYPE>
287#if NEBULA_BOUNDSCHECKS
291 if (this->inBulkInsert)
293 this->keyValuePairs.Append(kvp);
294 return this->keyValuePairs.Size() - 1;
298 return this->keyValuePairs.InsertSorted(kvp);
305template<
class KEYTYPE,
class VALUETYPE>
309 IndexT i = this->FindIndex(key);
312 return this->ValueAtIndex(this->Add(key, VALUETYPE()));
316 return this->ValueAtIndex(i);
323template<
class KEYTYPE,
class VALUETYPE>
327 #if NEBULA_BOUNDSCHECKS
330 IndexT eraseIndex = this->keyValuePairs.template BinarySearchIndex<KEYTYPE>(key);
331 #if NEBULA_BOUNDSCHECKS
334 this->keyValuePairs.EraseIndex(eraseIndex);
340template<
class KEYTYPE,
class VALUETYPE>
344 #if NEBULA_BOUNDSCHECKS
347 this->keyValuePairs.EraseIndex(index);
353template<
class KEYTYPE,
class VALUETYPE>
357 #if NEBULA_BOUNDSCHECKS
360 return this->keyValuePairs.template BinarySearchIndex<KEYTYPE>(key);
366template<
class KEYTYPE,
class VALUETYPE>
370 #if NEBULA_BOUNDSCHECKS
373 return (
InvalidIndex != this->keyValuePairs.template BinarySearchIndex<KEYTYPE>(key));
379template<
class KEYTYPE,
class VALUETYPE>
383#if NEBULA_BOUNDSCHECKS
386 index = this->keyValuePairs.template BinarySearchIndex<KEYTYPE>(key);
393template<
class KEYTYPE,
class VALUETYPE>
397 #if NEBULA_BOUNDSCHECKS
400 return this->keyValuePairs[index].Key();
406template<
class KEYTYPE,
class VALUETYPE>
410 #if NEBULA_BOUNDSCHECKS
413 return this->keyValuePairs[index].Value();
419template<
class KEYTYPE,
class VALUETYPE>
420inline const VALUETYPE&
423 #if NEBULA_BOUNDSCHECKS
426 return this->keyValuePairs[index].Value();
432template<
class KEYTYPE,
class VALUETYPE>
436 #if NEBULA_BOUNDSCHECKS
439 return this->keyValuePairs[index];
445template<
class KEYTYPE,
class VALUETYPE>
449 int keyValuePairIndex = this->FindIndex(key);
450 #if NEBULA_BOUNDSCHECKS
453 return this->keyValuePairs[keyValuePairIndex].Value();
459template<
class KEYTYPE,
class VALUETYPE>
460inline const VALUETYPE&
463 int keyValuePairIndex = this->FindIndex(key);
464 #if NEBULA_BOUNDSCHECKS
467 return this->keyValuePairs[keyValuePairIndex].Value();
473template<
class KEYTYPE,
class VALUETYPE>
474template<
class RETURNTYPE>
478 #if NEBULA_BOUNDSCHECKS
481 RETURNTYPE result(this->Size(),this->Size());
483 for (i = 0; i < this->keyValuePairs.Size(); i++)
485 result.Append(this->keyValuePairs[i].Value());
493template<
class KEYTYPE,
class VALUETYPE>
497 return this->ValuesAs<Array<VALUETYPE> >();
503template<
class KEYTYPE,
class VALUETYPE>
504template<
class RETURNTYPE>
508 #if NEBULA_BOUNDSCHECKS
511 RETURNTYPE result(this->Size(),this->Size());
513 for (i = 0; i < this->keyValuePairs.Size(); i++)
515 result.Append(this->keyValuePairs[i].Key());
523template<
class KEYTYPE,
class VALUETYPE>
527 return this->KeysAs<Array<KEYTYPE> >();
533template<
class KEYTYPE,
class VALUETYPE>
537 return this->keyValuePairs.begin();
542template<
class KEYTYPE,
class VALUETYPE>
546 return this->keyValuePairs.end();
551template<
class KEYTYPE,
class VALUETYPE>
560template<
class KEYTYPE,
class VALUETYPE>
564 this->Add(key, value);
Nebula's dynamic array class.
Definition array.h:60
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
void BeginBulkAdd()
begin a bulk insert (array will be sorted at End)
Definition dictionary.h:223
void operator=(Dictionary< KEYTYPE, VALUETYPE > &&rhs) noexcept
move operator
Definition dictionary.h:166
Dictionary(const Dictionary< KEYTYPE, VALUETYPE > &rhs)
copy constructor
Definition dictionary.h:125
void Reserve(SizeT numElements)
reserve space (useful if number of elements is known beforehand)
Definition dictionary.h:213
bool Contains(const KEYTYPE &key) const
return true if key exists in the array
Definition dictionary.h:368
void Clear()
clear the dictionary
Definition dictionary.h:180
SizeT Size() const
return number of key/value pairs in the dictionary
Definition dictionary.h:193
KeyValuePair< KEYTYPE, VALUETYPE > * end() const
Definition dictionary.h:544
const KEYTYPE & KeyAtIndex(IndexT index) const
get a key at given index
Definition dictionary.h:395
IndexT FindIndex(const KEYTYPE &key) const
find index of key/value pair (InvalidIndex if doesn't exist)
Definition dictionary.h:355
Array< KEYTYPE > KeysAsArray() const
get all keys as an Util::Array
Definition dictionary.h:525
Dictionary(Dictionary< KEYTYPE, VALUETYPE > &&rhs) noexcept
move constructor
Definition dictionary.h:138
const VALUETYPE & ValueAtIndex(IndexT index) const
get a value at given index
Definition dictionary.h:421
IndexT Add(const KeyValuePair< KEYTYPE, VALUETYPE > &kvp)
add a key/value pair
Definition dictionary.h:267
void clear()
Definition dictionary.h:553
void EraseAtIndex(IndexT index)
erase a key at index
Definition dictionary.h:342
KeyValuePair< KEYTYPE, VALUETYPE > & KeyValuePairAtIndex(IndexT index) const
get key/value pair at index
Definition dictionary.h:434
const VALUETYPE & operator[](const KEYTYPE &key) const
read-only [] operator
Definition dictionary.h:461
RETURNTYPE ValuesAs() const
get all keys as (typically) an array
Definition dictionary.h:476
bool IsEmpty() const
return true if empty
Definition dictionary.h:203
VALUETYPE & ValueAtIndex(IndexT index)
access to value at given index
Definition dictionary.h:408
RETURNTYPE KeysAs() const
get all keys as (typically) an array
Definition dictionary.h:506
Array< VALUETYPE > ValuesAsArray() const
get all keys as an Util::Array
Definition dictionary.h:495
void emplace(KEYTYPE &&key, VALUETYPE &&value)
Definition dictionary.h:562
void Erase(const KEYTYPE &key)
erase a key and its associated value
Definition dictionary.h:325
VALUETYPE & operator[](const KEYTYPE &key)
read/write [] operator
Definition dictionary.h:447
bool Contains(const KEYTYPE &key, IndexT &index) const
return true if key exists in the array, and saves index
Definition dictionary.h:381
bool inBulkInsert
Definition dictionary.h:108
void Merge(const Dictionary< KEYTYPE, VALUETYPE > &rhs)
merge two dictionaries
Definition dictionary.h:250
IndexT Add(const KEYTYPE &key, const VALUETYPE &value)
add a key and associated value
Definition dictionary.h:285
KeyValuePair< KEYTYPE, VALUETYPE > * begin() const
functions for stl like behaviour
Definition dictionary.h:535
void EndBulkAdd()
end a bulk insert (this will sort the internal array)
Definition dictionary.h:236
void operator=(const Dictionary< KEYTYPE, VALUETYPE > &rhs)
assignment operator
Definition dictionary.h:152
Array< KeyValuePair< KEYTYPE, VALUETYPE > > keyValuePairs
Definition dictionary.h:107
Dictionary()
default constructor
Definition dictionary.h:115
VALUETYPE & Emplace(const KEYTYPE &key)
creates a new entry of VALUETYPE if key does not exist, or returns the existing element
Definition dictionary.h:307
void SortIfDirty() const
make sure the key value pair array is sorted
Key/Value pair objects are used by most assiociative container classes, like Dictionary or HashTable.
Definition keyvaluepair.h:19
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48