35 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ 36 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) 37 #define get16bits(d) (*((const uint16_t *) (d))) 40 #if !defined (get16bits) 41 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ 42 +(uint32_t)(((const uint8_t *)(d))[0]) ) 59 template <
typename Key>
65 template <
typename First,
typename Second>
68 return super_fast_hash<First>(p.first) ^ super_fast_hash<Second>(p.second);
71 template <
typename Key,
72 class Cmp = std::equal_to<Key>>
106 Key * search_in_list(
List & list,
const Key & k)
108 return list.
search_ptr([&k,
this](
const auto & item)
114 const Key * search_in_list(
const List & list,
const Key & k)
const 116 return list.
search_ptr([&k,
this](
const auto & item)
122 nat_t h(
const Key & item)
const 130 :
BaseArray(size), num_items(0), cmp(_cmp), hash_fct(fct),
131 lower_alpha(_lower_alpha), upper_alpha(_upper_alpha)
137 :
LHashTable(size, _cmp, fct, DFT_LOWER_ALPHA, DFT_UPPER_ALPHA)
143 :
LHashTable(size, _cmp, fct, DFT_LOWER_ALPHA, DFT_UPPER_ALPHA)
149 :
LHashTable(size, _cmp, fct, DFT_LOWER_ALPHA, DFT_UPPER_ALPHA)
156 :
LHashTable(size, _cmp, fct, DFT_LOWER_ALPHA, DFT_UPPER_ALPHA)
162 :
LHashTable(DFT_SIZE, _cmp, fct, DFT_LOWER_ALPHA, DFT_UPPER_ALPHA)
168 :
LHashTable(DFT_SIZE, _cmp, fct, DFT_LOWER_ALPHA, DFT_UPPER_ALPHA)
174 :
LHashTable(DFT_SIZE, _cmp, fct, DFT_LOWER_ALPHA, DFT_UPPER_ALPHA)
186 :
BaseArray(h), num_items(h.num_items), cmp(h.cmp), hash_fct(h.hash_fct),
187 lower_alpha(h.lower_alpha), upper_alpha(h.upper_alpha)
198 LHashTable(
const std::initializer_list<Key> &);
206 num_items = h.num_items;
208 hash_fct = h.hash_fct;
209 lower_alpha = h.lower_alpha;
210 upper_alpha = h.upper_alpha;
224 std::swap(num_items, h.num_items);
225 std::swap(cmp, h.cmp);
226 std::swap(hash_fct, h.hash_fct);
227 std::swap(lower_alpha, h.lower_alpha);
228 std::swap(upper_alpha, h.upper_alpha);
279 return num_items == 0;
310 if (not list.
is_empty() and search_in_list(list, item) !=
nullptr)
313 if (
alpha() < upper_alpha)
316 return &list.
append(item);
331 if (not list.
is_empty() and search_in_list(list, item) !=
nullptr)
334 if (
alpha() < upper_alpha)
337 return &list.
insert(std::forward<Key>(item));
352 if (
alpha() < upper_alpha)
355 return &list.
append(item);
370 if (
alpha() < upper_alpha)
373 return &list.
insert(std::forward<Key>(item));
389 return insert(std::forward<Key>(k));
411 return search_in_list(list, k);
423 return search_in_list(list, k);
434 Key * result = search_in_list(list, item);
436 if (result !=
nullptr)
440 if (
alpha() < upper_alpha)
443 return &list.
insert(item);
460 Key * result = search_in_list(list, item);
462 if (result !=
nullptr)
466 if (
alpha() < upper_alpha)
469 return &list.
insert(std::forward<Key>(item));
483 throw std::domain_error(
"Key does not exists");
488 const Key &
find(
const Key & k)
const 490 const Key * ptr =
search(k);
493 throw std::domain_error(
"Key does not exists");
498 bool remove(
const Key & k)
540 void locate_prev(
nat_t);
542 void locate_next(
nat_t);
551 : set_ptr(&const_cast<
LHashTable &>(h)), set_pos(h.
M()),
552 list_it(), pos(h.
N())
559 : set_ptr(nullptr), set_pos(-1), list_it(), pos(-1)
565 : set_ptr(&const_cast<
LHashTable &>(h)), set_pos(0), list_it(), pos(0)
567 locate_next(set_pos);
571 : set_ptr(it.set_ptr), set_pos(it.set_pos), list_it(it.list_it),
588 set_ptr = it.set_ptr;
589 set_pos = it.set_pos;
590 list_it = it.list_it;
604 std::swap(set_ptr, it.set_ptr);
605 std::swap(set_pos, it.set_pos);
606 std::swap(list_it, it.list_it);
607 std::swap(pos, it.pos);
623 return set_pos >= 0 and set_pos < set_ptr->get_capacity();
629 throw std::overflow_error(
"There is not current element");
637 throw std::overflow_error(
"There is not current element");
652 locate_next(set_pos + 1);
662 if (set_pos == set_ptr->M() or list_it == set_ptr->at(set_pos).begin())
663 locate_prev(set_pos);
690 template <
typename Key,
class Cmp>
697 template <
typename Key,
class Cmp>
700 LHashTable new_hash_set(sz, cmp, hash_fct, lower_alpha, upper_alpha);
702 for (Key & item : *
this)
703 new_hash_set.
append(std::move(item));
708 template <
typename Key,
class Cmp>
712 for (
const Key & item : l)
716 template <
typename Key,
class Cmp>
719 while (set_pos > 0 and set_ptr->at(set_pos - 1).is_empty())
723 list_it = set_ptr->
at(set_pos - 1).
end();
728 template <
typename Key,
class Cmp>
731 if (set_ptr->is_empty())
735 set_ptr->at(i).is_empty())
740 assert(not set_ptr->at(i).is_empty());
741 list_it = set_ptr->
at(i).
begin();
747 template <
typename Key,
class Cmp>
750 if (set_ptr->is_empty())
753 while (i > 0 and set_ptr->at(i - 1).is_empty())
758 assert(not set_ptr->at(i - 1).is_empty());
759 list_it = set_ptr->
at(i - 1).
end();
LHashTable(LHashTable &&h)
Definition: hash.H:192
Iterator(const Iterator &it)
Definition: hash.H:570
Key * append_dup(Key &&k)
Definition: hash.H:397
Key * search_or_insert(const Key &item)
Definition: hash.H:426
nat_t(*)(const MapKey< T, nat_t > &) HashFctPtr
Definition: hash.H:87
LHashTable(nat_t size, Cmp &_cmp, HashFctPtr fct=&super_fast_hash)
Definition: hash.H:148
LHashTable(nat_t size, Cmp &&_cmp=Cmp(), HashFctPtr fct=&super_fast_hash)
Definition: hash.H:154
void set_lower_alpha(real_t value)
Definition: hash.H:256
const Key & find(const Key &k) const
Definition: hash.H:488
Iterator()
Definition: hash.H:558
nat_t size() const
Definition: hash.H:282
bool is_empty() const
Definition: nodesdef.H:153
LHashTable(const LHashTable &h)
Definition: hash.H:185
Key * insert_dup(const Key &item)
Definition: hash.H:346
Definition: setalgorithms.H:36
Key * search(const Key &k)
Definition: hash.H:402
double real_t
Definition: types.H:51
void next()
Definition: nodesdef.H:383
LHashTable(Cmp &_cmp, HashFctType fct)
Definition: hash.H:161
std::function< nat_t(const MapKey< T, nat_t > &)> HashFctType
Definition: hash.H:88
Iterator(Iterator &&it)
Definition: hash.H:577
const Cmp & get_cmp() const
Definition: hash.H:236
Iterator end() const
Definition: hash.H:684
Definition: iterator.H:36
Key * insert_dup(Key &&item)
Definition: hash.H:364
Key & get_current()
Definition: hash.H:626
Key & find(const Key &k)
Definition: hash.H:478
lint_t get_position() const
Definition: hash.H:616
Key * append_dup(const Key &k)
Definition: hash.H:392
nat_t M() const
Definition: hash.H:292
Iterator & operator=(const Iterator &it)
Definition: hash.H:583
void clear()
Definition: hash.H:297
Iterator end()
Definition: hash.H:679
Iterator(const LHashTable &h)
Definition: hash.H:564
bool is_empty() const
Definition: hash.H:277
real_t get_upper_alpha() const
Definition: hash.H:251
nat_t N() const
Definition: hash.H:287
void reset()
Definition: hash.H:610
const Key * search(const Key &k) const
Definition: hash.H:414
static constexpr nat_t DFT_SIZE
Definition: hash.H:90
nat_t super_fast_hash(void *, nat_t)
Key * append(Key &&k)
Definition: hash.H:387
Key & key(MapKey< Key, Value > &item)
Definition: map.H:53
LHashTable(nat_t size, Cmp &_cmp, HashFctType fct)
Definition: hash.H:136
void swap(FixedArray &a)
Definition: array.H:258
Key * insert(Key &&item)
Definition: hash.H:325
LHashTable(nat_t size, Cmp &&_cmp, HashFctType fct)
Definition: hash.H:142
bool remove_first_if(Pred &pred)
Definition: containeralgorithms.H:213
real_t alpha() const
Definition: hash.H:272
Iterator begin()
Definition: hash.H:669
bool has_current() const
Definition: nodesdef.H:362
Key * insert(const Key &item)
Definition: hash.H:304
long long lint_t
Definition: types.H:49
T & insert(const T &item)
Definition: list.H:663
LHashTable & operator=(const LHashTable &h)
Definition: hash.H:200
void set_upper_alpha(real_t value)
Definition: hash.H:261
Iterator begin() const
Definition: hash.H:674
LHashTable(nat_t size, Cmp &_cmp, HashFctType fct, real_t _lower_alpha, real_t _upper_alpha)
Definition: hash.H:128
void swap(LHashTable &h)
Definition: hash.H:221
Definition: containeralgorithms.H:33
Key * append(const Key &k)
Definition: hash.H:382
real_t get_lower_alpha() const
Definition: hash.H:246
void prev()
Definition: hash.H:655
nat_t SizeType
Definition: array.H:196
T & append(const T &item)
Definition: list.H:679
void swap(Iterator &it)
Definition: hash.H:602
LHashTable(Cmp &&_cmp, HashFctType fct)
Definition: hash.H:167
void next()
Definition: hash.H:642
const Key & get_current() const
Definition: hash.H:634
Key * search_or_insert(Key &&item)
Definition: hash.H:452
Definition: iterator.H:112
nat_t get_capacity() const
Definition: array.H:266
T * search_ptr(Pred &pred) const
Definition: containeralgorithms.H:200
Iterator begin()
Definition: list.H:883
unsigned long int nat_t
Definition: types.H:50
LHashTable(Cmp &&_cmp=Cmp(), HashFctPtr fct=&super_fast_hash)
Definition: hash.H:179
Value & value(MapKey< Key, Value > &item)
Definition: map.H:77
LHashTable(Cmp &_cmp, HashFctPtr fct=&super_fast_hash)
Definition: hash.H:173
Iterator end()
Definition: list.H:893
Iterator(const LHashTable &h, int)
Definition: hash.H:550
void reset_alpha_values()
Definition: hash.H:266
bool has_current() const
Definition: hash.H:621
static constexpr real_t DFT_LOWER_ALPHA
Definition: hash.H:91
lint_t get_location() const
Definition: hash.H:545
DL * get_current()
Definition: nodesdef.H:367
Cmp & get_cmp()
Definition: hash.H:231
static constexpr real_t DFT_UPPER_ALPHA
Definition: hash.H:92
T & at(nat_t i)
Definition: array.H:276
const HashFctType & get_hash_fct() const
Definition: hash.H:241
Definition: nodesdef.H:293