/********************************************************
* Dictionary.h *
* *
* XFX Generic Dictionary class definition file *
* Copyright © XFX Team. All Rights Reserved *
********************************************************/
#ifndef _SYSTEM_COLLECTIONS_GENERIC_DICTIONARY_
#define _SYSTEM_COLLECTIONS_GENERIC_DICTIONARY_
#include "Interfaces.h"
#include "KeyValuePair.h"
namespace System
{
namespace Collections
{
namespace Generic
{
///
/// Represents a collection of keys and values.
///
template
class Dictionary : public IDictionary, public ICollection >
{
private:
template
struct Entry
{
int hashCode;
int next;
UKey key;
UValue value;
};
private:
int buckets[];
static const char* ComparerName;
IEqualityComparer* comparer;
int count;
Entry entries[];
int freeCount;
int freeList;
static const char* HashSizeName;
static const char* KeyValuePairsName;
int version;
static const char* VersionName;
void Add(KeyValuePair keyValuePair);
bool Contains(KeyValuePair keyValuePair);
void CopyTo(KeyValuePair array[], int index);
int FindEntry(TKey key);
bool Remove(KeyValuePair keyValuePair);
void Initialize(int capacity);
void Insert(TKey key, TValue value, bool add);
void Resize();
public:
///
/// Represents the collection of keys in a Dictionary<,>.
///
template
class KeyCollection : public ICollection, public IEnumerable
{
private:
Dictionary *_dictionary;
public:
int Count();
KeyCollection(Dictionary dictionary);
KeyCollection(const KeyCollection &obj);
void Add(UKey item);
void Clear();
bool Contains(UKey item);
void CopyTo(UKey array[], int index);
bool Remove(UKey item);
};
///
/// Represents the collection of values in a Dictionary<,>.
///
template
class ValueCollection : public ICollection, public IEnumerable
{
private:
Dictionary *_dictionary;
public:
int Count();
ValueCollection(Dictionary dictionary);
ValueCollection(const ValueCollection &obj);
void Add(UValue item);
void Clear();
bool Contains(UValue item);
void CopyTo(UValue array[], int index);
bool Remove(UValue item);
};
public:
IEqualityComparer* Comparer();
int Count();
KeyCollection Keys();
ValueCollection Values();
TValue operator[](TKey key);
Dictionary();
Dictionary(IDictionary dictionary);
Dictionary(int capacity);
~Dictionary();
void Add(TKey key, TValue value);
void Clear();
bool ContainsKey(TKey key);
bool ContainsValue(TValue value);
bool Remove(TKey key);
bool TryGetValue(TKey key, out TValue value);
};
}
}
}
#endif //_SYSTEM_COLLECTIONS_GENERIC_DICTIONARY_