1 #ifndef dsa_HashTable_H__
2 #define dsa_HashTable_H__
14 template<
class Data,
class HashFunc>
17 std::vector<std::list<Data> > table_;
53 for (
size_t i = 0, I = table_.size(); i < I; i++) {
63 table_.resize(std::max(size, 1u));
79 for (
size_t i = 0, I = table_.size(); i < I; i++) {
80 ret += table_[i].size();
88 HashFunc
const&
func()
const {
95 bool add(Data
const& e) {
96 size_t index = func_(e) %
size();
97 table_[index].push_back(e);
105 for (
size_t i = 0, I = h.table_.size(); i < I; i++) {
106 for (std::list<Data>::const_iterator
107 it = h.table_[index].begin(); it != h.table_[index].end(); ++it) {
118 size_t index = func_(e) %
size();
119 for (std::list<Data>::const_iterator
120 it = table_[index].begin(); it != table_[index].end(); ++it) {
122 table_[index].erase(i);
134 for (
size_t i = 0, I = h.table_.size(); i < I; i++) {
135 for (std::list<Data>::const_iterator
136 it = h.table_[index].begin(); it != h.table_[index].end(); ++it) {
142 for (
size_t i = 0, I = table_.size(); i < I; i++) {
143 for (std::list<Data>::const_iterator
144 it = table_[index].begin(); it != table_[index].end(); ) {
146 table_[index].erase(it);
161 size_t index = func_(e) %
size();
162 for (std::list<Data>::const_iterator
163 it = table_[index].begin(); it != table_[index].end(); ++it) {
173 std::vector<Data>
all()
const {
174 std::vector<Data> ret;
175 for (
size_t i = 0, I = table_.size(); i < I; i++) {
176 for (std::list<Data>::const_iterator
177 it = table_[i].begin(); it != table_[i].end(); ++it) {
187 std::vector<Data>
all(
size_t index)
const {
188 index %= table_.size();
189 std::vector<Data> ret;
190 for (std::list<Data>::const_iterator
191 it = table_[index].begin(); it != table_[index].end(); ++it) {
217 #endif // dsa_HashTable_H__