74 lines
1.5 KiB
C++
74 lines
1.5 KiB
C++
|
#pragma once
|
|||
|
|
|||
|
#include "HashTable.hpp"
|
|||
|
|
|||
|
namespace Lenyiin
|
|||
|
{
|
|||
|
template <class K, class V, class Hash = _Hash<K>>
|
|||
|
class Unordered_Map
|
|||
|
{
|
|||
|
public:
|
|||
|
struct MapKOfT
|
|||
|
{
|
|||
|
const K& operator()(const std::pair<K, V>& kv)
|
|||
|
{
|
|||
|
return kv.first;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
typedef typename Open_HashTable<K, std::pair<K, V>, MapKOfT, Hash>::iterator iterator;
|
|||
|
|
|||
|
iterator begin()
|
|||
|
{
|
|||
|
return _hashTable.begin();
|
|||
|
}
|
|||
|
|
|||
|
iterator end()
|
|||
|
{
|
|||
|
return _hashTable.end();
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>캯<EFBFBD><ECBAAF>: ָ<><D6B8><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>С
|
|||
|
Unordered_Map(size_t bucket_count = 10)
|
|||
|
: _hashTable(bucket_count)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>
|
|||
|
~Unordered_Map()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
std::pair<iterator, bool> Insert(const std::pair<K, V>& kv)
|
|||
|
{
|
|||
|
return _hashTable.Insert(kv);
|
|||
|
}
|
|||
|
|
|||
|
V& operator[](const K& key)
|
|||
|
{
|
|||
|
std::pair<iterator, bool> ret = _hashTable.Insert(std::make_pair(key, V()));
|
|||
|
return ret.first->second;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>
|
|||
|
bool Find(const K& key)
|
|||
|
{
|
|||
|
return _hashTable.Find(key);
|
|||
|
}
|
|||
|
|
|||
|
// ɾ<><C9BE>Ԫ<EFBFBD><D4AA>
|
|||
|
bool Erase(const K& key)
|
|||
|
{
|
|||
|
return _hashTable.Erase(key);
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ӡ
|
|||
|
void Print() const
|
|||
|
{
|
|||
|
_hashTable.Print();
|
|||
|
}
|
|||
|
|
|||
|
private:
|
|||
|
Open_HashTable<K, std::pair<K, V>, MapKOfT, Hash> _hashTable;
|
|||
|
};
|
|||
|
}
|