Vcsn  2.4
Be Rational
wet.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cassert>
4 #include <map>
5 #include <set>
6 #include <type_traits>
7 #include <unordered_map>
8 
9 #include <boost/iterator/iterator_facade.hpp>
10 
11 #include <vcsn/ctx/traits.hh> // labelset_t_of
12 #include <vcsn/misc/builtins.hh>
14 #include <vcsn/misc/empty.hh>
15 #include <vcsn/misc/functional.hh> // vcsn::equal_to
16 #include <vcsn/misc/type_traits.hh>
17 
18 namespace vcsn
19 {
20  namespace detail
21  {
22 
23  /*------------------.
24  | welement_label. |
25  `------------------*/
26 
28  template <typename Label>
30  {
31  using label_t = Label;
33  : label_{l}
34  {}
36  : label_{std::move(l)}
37  {}
38 
39  const label_t& label() const { return label_; }
40  void label(const label_t& l) { label_ = l; }
41 
42  private:
44  };
45 
47  template <>
49  {
50  using label_t = empty_t;
52  {}
54  {}
55  label_t label() const { return {}; }
56  void label(label_t) {}
57  };
58 
59 
60  /*-------------------.
61  | welement_weight. |
62  `-------------------*/
63 
65  template <typename Weight>
67  {
68  using weight_t = Weight;
70  : weight_{w}
71  {}
73  : weight_{std::move(w)}
74  {}
75  const weight_t& weight() const { return weight_; }
76  void weight(const weight_t& k) { weight_ = k; }
77 
78  private:
80  };
81 
84  template <>
85  struct welement_weight<bool>
86  {
87  using weight_t = bool;
89  {
90  (void) w; assert(w);
91  }
93  {
94  (void) w; assert(w);
95  }
96  weight_t weight() const { return true; }
97  void weight(const weight_t& w) { (void) w; assert(w); }
98  };
99  }
100 
101  /*------------.
102  | welement. |
103  `------------*/
104 
106  template <typename Label, typename Weight>
107  struct welement
108  : detail::welement_label<Label>
109  , detail::welement_weight<Weight>
110  {
113 
116 
119 
120  template <typename Label2, typename Weight2>
121  welement(Label2&& l, Weight2&& w)
122  : welement_label_t(std::forward<Label2>(l))
123  , welement_weight_t(std::forward<Weight2>(w))
124  {}
125 
126  operator value_t() const
127  {
128  return {this->label(), this->weight()};
129  }
130 
131  auto operator<(const welement& that) const
132  -> bool
133  {
134  return this->label() < that.label();
135  }
136 
137  auto operator==(const welement& that) const
138  -> bool
139  {
140  return this->label() == that.label();
141  }
142  };
143 
145  template <typename Label, typename Weight>
147  -> decltype(m.label())
148  {
149  return m.label();
150  }
151 
153  template <typename Label, typename Weight>
155  -> decltype(m.weight())
156  {
157  return m.weight();
158  }
159 
161  template <typename Label, typename Weight>
162  void weight_set(welement<Label, Weight>& m, const Weight& w)
163  {
164  m.weight(w);
165  }
166 
168  template <typename Label, typename Weight>
169  const Label& label_of(const std::pair<Label, Weight>& m)
170  {
171  return m.first;
172  }
173 
175  template <typename Label, typename Weight>
176  const Weight& weight_of(const std::pair<Label, Weight>& m)
177  {
178  return m.second;
179  }
180 
182  template <typename Label, typename Weight>
183  Label& label_of(std::pair<Label, Weight>& m)
184  {
185  return m.first;
186  }
187 
189  template <typename Label, typename Weight>
190  void weight_set(std::pair<Label, Weight>& m, const Weight& w)
191  {
192  m.second = w;
193  }
194 
195 
197  enum class wet_kind_t
198  {
200  bitset,
202  map,
204  set,
207  };
208 
210  inline std::string to_string(wet_kind_t k)
211  {
212 #define DEFINE(K) case wet_kind_t::K: return "vcsn::wet_kind_t::" #K
213  switch (k)
214  {
215  DEFINE(bitset);
216  DEFINE(map);
217  DEFINE(set);
219  }
220 #undef DEFINE
222  }
223 
224  namespace detail
225  {
226 
227  /*-----------------------.
228  | wet_map<Key, Value>. |
229  `-----------------------*/
230 
232  template <typename Key, typename Value,
233  typename Compare>
234  class wet_map
235  {
236  private:
237  using map_t = std::map<Key, Value, Compare>;
239 
240  public:
241  using self_t = wet_map;
242  static constexpr wet_kind_t kind = wet_kind_t::map;
243  using key_t = Key;
244  using value_t = Value;
246  using mapped_type = typename map_t::mapped_type;
247  using value_type = typename map_t::value_type;
248  using iterator = typename map_t::iterator;
249  using const_iterator = typename map_t::const_iterator;
250 
251  wet_map() = default;
252 
253  wet_map(std::initializer_list<value_type> l)
254  : map_{l}
255  {}
256 
257  static const key_t& key_of(const value_type& p)
258  {
259  return p.first;
260  }
261 
262  static const value_t& value_of(const value_type& p)
263  {
264  return p.second;
265  }
266 
267  void set(const key_t& k, const value_t& v)
268  {
269  map_[k] = v;
270  }
271 
272  void set(const iterator& i, const value_t& v)
273  {
274  i->second = v;
275  }
276 
277  template <typename Fun>
278  void for_each(Fun f) const
279  {
280  std::for_each(begin(map_), end(map_),
281  f);
282  }
283 
284 #define DEFINE(Name, Const) \
285  template <typename... Args> \
286  auto \
287  Name(Args&&... args) Const \
288  -> decltype(map_.Name(std::forward<Args>(args)...)) \
289  { \
290  return map_.Name(std::forward<Args>(args)...); \
291  }
292 
293  DEFINE(key_comp, const);
296  DEFINE(begin,const);
297  DEFINE(find,const);
300  DEFINE(end, const);
303  DEFINE(empty,const);
304  DEFINE(size, const);
305 #undef DEFINE
306  };
307 
308 
309  /*---------------------------------.
310  | wet_unordered_map<Key, Value>. |
311  `---------------------------------*/
312 
314  template <typename Key, typename Value,
315  typename Hash, typename KeyEqual>
317  {
318  private:
319  using map_t = std::unordered_map<Key, Value, Hash, KeyEqual>;
321 
322  public:
325  using key_t = Key;
326  using value_t = Value;
328  using value_type = typename map_t::value_type;
329  using iterator = typename map_t::iterator;
330  using const_iterator = typename map_t::const_iterator;
331 
332  wet_unordered_map() = default;
333 
334  wet_unordered_map(std::initializer_list<value_type> l)
335  : map_{l}
336  {}
337 
338  static const key_t& key_of(const value_type& p)
339  {
340  return p.first;
341  }
342 
343  static const value_t& value_of(const value_type& p)
344  {
345  return p.second;
346  }
347 
348  void set(const key_t& k, const value_t& v)
349  {
350  map_[k] = v;
351  }
352 
353  void set(const iterator& i, const value_t& v)
354  {
355  i->second = v;
356  }
357 
358  template <typename Fun>
359  void for_each(Fun f) const
360  {
361  std::for_each(begin(map_), end(map_),
362  f);
363  }
364 
365 #define DEFINE(Name, Const) \
366  template <typename... Args> \
367  auto \
368  Name(Args&&... args) Const \
369  -> decltype(map_.Name(std::forward<Args>(args)...)) \
370  { \
371  return map_.Name(std::forward<Args>(args)...); \
372  }
373 
376  DEFINE(begin,const);
377  DEFINE(find,const);
380  DEFINE(end, const);
383  DEFINE(empty,const);
384  DEFINE(size, const);
385 #undef DEFINE
386  };
387 
388 
389  /*----------------------.
390  | wet_set<Key, bool>. |
391  `----------------------*/
392 
394  template <typename Key, typename Compare>
395  class wet_set
396  {
397  private:
398  using set_t = std::set<Key, Compare>;
400 
401  public:
402  using self_t = wet_set;
403  static constexpr wet_kind_t kind = wet_kind_t::set;
404  using key_t = Key;
405  using value_t = bool;
408 
409  wet_set() = default;
410  wet_set(std::initializer_list<value_type> p)
411  {
412  for (const auto& m: p)
413  set(label_of(m), weight_of(m));
414  }
415 
417  template <typename Value, typename Iterator>
419  : public boost::iterator_facade<iterator_impl<Value, Iterator>
420  , Value
421  , boost::forward_traversal_tag
422  >
423  {
425  using iterator_t = Iterator;
426  using value_t = Value;
428 
429  iterator_impl(const iterator_t& it) noexcept
430  : it_{it}
431  {}
432 
433  template <typename OtherValue, typename OtherIterator>
435  noexcept
436  : iterator_impl{that.iterator()}
437  {}
438 
439  iterator_impl(const iterator_impl&) noexcept = default;
440 
441  const iterator_t& iterator() const
442  {
443  return it_;
444  }
445 
447  {
448  return {*it_, true};
449  }
450 
451  private:
453 
455  void increment()
456  {
457  ++it_;
458  }
459 
460  void decrement()
461  {
462  --it_;
463  }
464 
465  void advance(int n)
466  {
467  it_ += n;
468  }
469 
470  template <typename OtherValue, typename OtherIterator>
472  {
473  return iterator() == that.iterator();
474  }
475 
477  };
478 
481 
483  using const_iterator
485 
486  auto begin() -> iterator { return {set_.begin()}; }
487  auto end() -> iterator { return {set_.end()}; }
488  auto cbegin() const -> const_iterator { return {set_.cbegin()}; }
489  auto cend() const -> const_iterator { return {set_.cend()}; }
490  auto begin() const -> const_iterator { return cbegin(); }
491  auto end() const -> const_iterator { return cend(); }
492 
493  void set(const key_t& k, const value_t& v)
494  {
495  assert(v); (void) v;
496  set_.emplace(k);
497  }
498 
499  // When called, the key is already defined.
500  void set(const iterator&, const value_t& v)
501  {
502  assert(v); (void) v;
503  }
504 
506  -> iterator
507  {
508  return set_.erase(pos.iterator());
509  }
510 
511  template <typename... Args>
512  auto find(Args&&... args) const
513  -> const_iterator
514  {
515  return set_.find(std::forward<Args>(args)...);
516  }
517 
518  template <typename... Args>
519  auto find(Args&&... args)
520  -> iterator
521  {
522  return set_.find(std::forward<Args>(args)...);
523  }
524 
525 
526 #define DEFINE(Name, Const) \
527  template <typename... Args> \
528  auto \
529  Name(Args&&... args) Const \
530  -> decltype(set_.Name(std::forward<Args>(args)...)) \
531  { \
532  return set_.Name(std::forward<Args>(args)...); \
533  }
534 
537  DEFINE(empty,const);
538  DEFINE(size, const);
539 #undef DEFINE
540  };
541 
542 
543  /*---------------------------------------.
544  | wet_bitset<unsigned, bool>: bitsets. |
545  `---------------------------------------*/
546 
550  {
551  private:
552  using set_t = boost::dynamic_bitset<>;
554 
555  public:
557  static constexpr wet_kind_t kind = wet_kind_t::bitset;
558  using key_t = unsigned;
559  using value_t = bool;
562 
563  // A plain "wet_bitset() = default;" fails with GCC 4.8 or 4.9.0:
564  // error: converting to 'const boost::dynamic_bitset<>'
565  // from initializer list would use explicit constructor
566  // 'boost::dynamic_bitset<Block, Allocator>::dynamic_bitset([...])
567  //
568  // wet_bitset() = default;
569  // ^
571 
572  wet_bitset(size_t size)
573  : set_{size}
574  {}
575 
576  wet_bitset(std::initializer_list<value_type> p)
577  {
578  for (const auto& m: p)
579  set(label_of(m), weight_of(m));
580  }
581 
583  : set_{std::move(set)}
584  {}
585 
586  const set_t& set() const
587  {
588  return set_;
589  }
590 
593  {
594  return set_;
595  }
596 
597  void clear()
598  {
599  set_.reset();
600  }
601 
602  bool empty() const
603  {
604  return set_.none();
605  }
606 
607  size_t size() const
608  {
609  return set_.count();
610  }
611 
612  static constexpr size_t npos = set_t::npos;
613 
615  template <typename Value, typename Set>
617  : public boost::iterator_facade<iterator_impl<Value, Set>
618  , Value
619  , boost::forward_traversal_tag
620  >
621  {
623  using set_t = Set;
624  using iterator_t = size_t;
625  using value_t = Value;
627 
629  : set_{set}
630  , it_{it}
631  {}
632 
634  : iterator_impl{set, set.find_first()}
635  {}
636 
637  iterator_impl(const iterator_impl&) noexcept = default;
638 
639  template <typename OtherValue, typename OtherIterator>
640  iterator_impl(const iterator_impl<OtherValue, OtherIterator>& that)
641  noexcept
642  : iterator_impl{that.set, that.iterator()}
643  {}
644 
645  iterator_impl& operator=(const iterator_impl& that) noexcept
646  {
647  assert(&set_ == &that.set_);
648  it_ = that.it_;
649  return *this;
650  }
651 
652  const set_t& set() const
653  {
654  return set_;
655  }
656 
657  const iterator_t& iterator() const
658  {
659  return it_;
660  }
661 
663  {
664  return {key_t(it_), true};
665  }
666 
667  private:
669 
671  void increment()
672  {
673  it_ = set_.find_next(it_);
674  }
675 
676  template <typename OtherValue, typename OtherSet>
678  {
679  assert(&set() == &that.set());
680  return (iterator() == that.iterator());
681  }
682 
686  };
687 
690 
693 
694  auto begin() -> iterator { return {set_}; }
695  auto end() -> iterator { return {set_, npos}; }
696 
697  auto cbegin() const -> const_iterator { return {set_}; }
698  auto cend() const -> const_iterator { return {set_, npos}; }
699 
700  auto begin() const -> const_iterator { return cbegin(); }
701  auto end() const -> const_iterator { return cend(); }
702 
704  static key_t key(char k)
705  {
706  return static_cast<unsigned char>(k);
707  }
708 
709  void set(const key_t k, value_t v = true)
710  {
711  assert(v); (void) v;
712  set_.set(k);
713  }
714 
715  void set(const char k, value_t v = true)
716  {
717  set(key(k), v);
718  }
719 
720  // When called, the key is already defined.
721  void set(const iterator&, const value_t v = true)
722  {
723  assert(v); (void) v;
724  }
725 
727  -> void
728  {
729  set_.reset(pos.iterator());
730  }
731 
732  void erase(key_t k)
733  {
734  set_.reset(k);
735  }
736 
737  void erase(char k)
738  {
739  erase(key(k));
740  }
741 
742  auto find(key_t k) const
743  -> const_iterator
744  {
745  if (set_[k])
746  return {set_, k};
747  else
748  return end();
749  }
750 
751  auto find(key_t k)
752  -> iterator
753  {
754  if (set_[k])
755  return {set_, k};
756  else
757  return end();
758  }
759 
760  auto find(char k) const
761  -> const_iterator
762  {
763  return find(key(k));
764  }
765 
766  auto find(char k)
767  -> iterator
768  {
769  return find(key(k));
770  }
771 
773  self_t operator-(const self_t& rhs) const
774  {
775  return {set_ - rhs.set_};
776  }
777 
778  self_t operator&(const self_t& rhs) const
779  {
780  return {set_ & rhs.set_};
781  }
782 
784  friend bool operator<(const self_t& lhs, const self_t& rhs)
785  {
786  return lhs.set_ < rhs.set_;
787  }
788  };
789 
790  /*------------------------.
791  | wet_kind<Key, Value>. |
792  `------------------------*/
793 
795  template <typename Key, typename Value>
797  {
798  static constexpr wet_kind_t kind = wet_kind_t::map;
799  };
800 
802  template <typename Key>
803  struct wet_kind_impl<Key, bool>
804  {
805  static constexpr wet_kind_t kind = wet_kind_t::set;
806  };
807 
809  template <>
810  struct wet_kind_impl<char, bool>
811  {
812  static constexpr wet_kind_t kind = wet_kind_t::bitset;
813  };
814 
817  template <typename Key, typename Value>
818  constexpr wet_kind_t wet_kind()
819  {
821  }
822 
823 
824  /*------------------------.
825  | wet_impl<Key, Value>. |
826  `------------------------*/
827 
829  template <wet_kind_t Kind,
830  typename Key, typename Value,
831  typename Compare, typename Hash, typename KeyEqual>
832  using wet_impl
833  = std::conditional_t<Kind == wet_kind_t::bitset,
834  wet_bitset,
835  std::conditional_t<Kind == wet_kind_t::set,
836  wet_set<Key, Compare>,
837  std::conditional_t<Kind == wet_kind_t::map,
838  wet_map<Key, Value, Compare>,
839  std::conditional_t<Kind == wet_kind_t::unordered_map,
840  wet_unordered_map<Key, Value, Hash, KeyEqual>,
841  void> > > >;
842 
843  }
844 
846  template <typename Key, typename Value,
847  wet_kind_t Kind = detail::wet_kind<Key, Value>(),
848  typename Compare = std::less<Key>,
849  typename Hash = std::hash<Key>,
850  typename KeyEqual = std::equal_to<Key>>
851  using wet = detail::wet_impl<Kind,
852  Key, Value, Compare, Hash, KeyEqual>;
853 
855  template <typename Context,
856  wet_kind_t Kind = detail::wet_kind<labelset_t_of<Context>,
860  Kind,
864 }
auto find(char k) const -> const_iterator
Definition: wet.hh:760
const weight_t & weight() const
Definition: wet.hh:75
STL namespace.
void set(const iterator &, const value_t &v)
Definition: wet.hh:500
iterator_impl & operator=(const iterator_impl &that) noexcept
Definition: wet.hh:645
auto find(Args &&...args) const -> const_iterator
Definition: wet.hh:512
static constexpr wet_kind_t kind
Definition: wet.hh:403
wet_bitset(size_t size)
Definition: wet.hh:572
typename map_t::const_iterator const_iterator
Definition: wet.hh:249
welement_label(label_t &&l)
Definition: wet.hh:35
typename map_t::iterator iterator
Definition: wet.hh:329
void set(const iterator &i, const value_t &v)
Definition: wet.hh:272
void set(const key_t &k, const value_t &v)
Definition: wet.hh:493
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
Definition: functional.hh:12
boost::dynamic_bitset<> set_t
Definition: wet.hh:552
auto erase(const_iterator pos) -> void
Definition: wet.hh:726
auto operator==(const welement &that) const -> bool
Definition: wet.hh:137
static const value_t & value_of(const value_type &p)
Definition: wet.hh:262
welement(Label2 &&l, Weight2 &&w)
Definition: wet.hh:121
Functor to compare Values of ValueSets.
Definition: functional.hh:76
auto begin() -> iterator
Definition: wet.hh:694
welement_weight(weight_t &&w)
Definition: wet.hh:72
void set(const key_t k, value_t v=true)
Definition: wet.hh:709
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
Definition: functional.hh:57
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
Definition: wet.hh:384
auto find(Args &&...args) -> iterator
Definition: wet.hh:519
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
Definition: wet.hh:154
auto find(char k) -> iterator
Definition: wet.hh:766
auto begin() -> iterator
Definition: wet.hh:486
typename map_t::const_iterator const_iterator
Definition: wet.hh:330
static const key_t & key_of(const value_type &p)
Definition: wet.hh:338
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
Definition: wet.hh:303
welement_label(const label_t &l)
Definition: wet.hh:32
auto key_comp(Args &&...args) const -> decltype(map_.key_comp(std::forward< Args >(args)...))
Definition: wet.hh:293
typename map_t::value_type value_type
Definition: wet.hh:328
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Definition: traits.hh:62
iterator_impl(const iterator_t &it) noexcept
Definition: wet.hh:429
std::unordered_map< Key, Value, Hash, KeyEqual > map_t
Definition: wet.hh:319
Weighted set: weights are bools.
Definition: wet.hh:395
void increment()
Advance to next position.
Definition: wet.hh:455
friend class boost::iterator_core_access
Definition: wet.hh:452
std::conditional_t< Kind==wet_kind_t::bitset, wet_bitset, std::conditional_t< Kind==wet_kind_t::set, wet_set< Key, Compare >, std::conditional_t< Kind==wet_kind_t::map, wet_map< Key, Value, Compare >, std::conditional_t< Kind==wet_kind_t::unordered_map, wet_unordered_map< Key, Value, Hash, KeyEqual >, void > > > > wet_impl
A weighted set type from its kind.
Definition: wet.hh:841
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:63
wet_bitset(std::initializer_list< value_type > p)
Definition: wet.hh:576
void for_each(Fun f) const
Definition: wet.hh:359
void set(const key_t &k, const value_t &v)
Definition: wet.hh:348
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
Definition: wet.hh:376
Request the map implementation.
iterator_impl(set_t &set) noexcept
Definition: wet.hh:633
void set(const char k, value_t v=true)
Definition: wet.hh:715
wet< label_t_of< Context >, weight_t_of< Context >, Kind, vcsn::less< labelset_t_of< Context >>, vcsn::hash< labelset_t_of< Context >>, vcsn::equal_to< labelset_t_of< Context >>> wet_of
The corresponding wet for a LabelSet -> WeightSet context.
Definition: wet.hh:863
friend class boost::iterator_core_access
Definition: wet.hh:668
Storage for a non-null weight.
Definition: wet.hh:66
auto clear(Args &&...args) -> decltype(set_.clear(std::forward< Args >(args)...))
Definition: wet.hh:535
Set set_t
Underlying "iterator".
Definition: wet.hh:623
std::string type(const automaton &a)
The implementation type of a.
Definition: others.cc:239
welement< typename std::remove_reference< label_t >::type, typename std::remove_reference< weight_t >::type > value_t
Definition: wet.hh:118
constexpr wet_kind_t wet_kind()
Given a Key and a Value type, the appropriate weighted set type.
Definition: wet.hh:818
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
Definition: wet.hh:296
Definition: a-star.hh:8
void erase(key_t k)
Definition: wet.hh:732
auto erase(const_iterator pos) -> iterator
Definition: wet.hh:505
Iterator iterator_t
Underlying iterator.
Definition: wet.hh:425
welement< key_t, value_t > welement_t
Definition: wet.hh:406
bool equal(const iterator_impl< OtherValue, OtherSet > &that) const
Definition: wet.hh:677
weight_t weight() const
Definition: wet.hh:96
auto cend() const -> const_iterator
Definition: wet.hh:489
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
Definition: wet.hh:304
auto cbegin() const -> const_iterator
Definition: wet.hh:697
#define DEFINE(K)
Definition: wet.hh:526
std::set< Key, Compare > set_t
Definition: wet.hh:398
welement_label(const label_t &)
Definition: wet.hh:51
void weight(const weight_t &k)
Definition: wet.hh:76
Weighted set: general, unordered, case.
Definition: wet.hh:316
welement< key_t, value_t > welement_t
Definition: wet.hh:560
const set_t & set() const
Definition: wet.hh:652
Weighted set: general, ordered, case.
Definition: wet.hh:234
auto begin() const -> const_iterator
Definition: wet.hh:490
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
Definition: wet.hh:383
const iterator_t & iterator() const
Definition: wet.hh:441
auto begin() const -> const_iterator
Definition: wet.hh:700
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Definition: traits.hh:66
void set(const key_t &k, const value_t &v)
Definition: wet.hh:267
auto empty(Args &&...args) const -> decltype(set_.empty(std::forward< Args >(args)...))
Definition: wet.hh:537
welement_weight(const weight_t &w)
Definition: wet.hh:88
self_t operator-(const self_t &rhs) const
Operators for when wet_bitset is used as a bitset.
Definition: wet.hh:773
static constexpr wet_kind_t kind
Definition: wet.hh:324
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
void increment()
Advance to next position.
Definition: wet.hh:671
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
Definition: wet.hh:295
wet_impl: map.
Definition: wet.hh:796
void for_each(Fun f) const
Definition: wet.hh:278
typename map_t::iterator iterator
Definition: wet.hh:248
size_t size() const
Definition: wet.hh:607
set_t & set_
Underlying bitset.
Definition: wet.hh:684
auto end() const -> const_iterator
Definition: wet.hh:491
wet_bitset(set_t &&set)
Definition: wet.hh:582
const label_t & label() const
Definition: wet.hh:39
void weight(const weight_t &w)
Definition: wet.hh:97
self_t operator&(const self_t &rhs) const
Definition: wet.hh:778
detail::wet_impl< Kind, Key, Value, Compare, Hash, KeyEqual > wet
Given Key/Value types, the appropriate weighted set type.
Definition: wet.hh:852
wet_unordered_map(std::initializer_list< value_type > l)
Definition: wet.hh:334
auto cend() const -> const_iterator
Definition: wet.hh:698
typename map_t::mapped_type mapped_type
Definition: wet.hh:246
iterator_impl(set_t &set, iterator_t it) noexcept
Definition: wet.hh:628
static constexpr wet_kind_t kind
Definition: wet.hh:242
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
Definition: wet.hh:299
auto end() -> iterator
Definition: wet.hh:487
bool equal(const iterator_impl< OtherValue, OtherIterator > &that) const
Definition: wet.hh:471
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
Definition: wet.hh:380
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
bool empty() const
Definition: wet.hh:602
auto size(Args &&...args) const -> decltype(set_.size(std::forward< Args >(args)...))
Definition: wet.hh:538
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
Definition: wet.hh:377
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
Definition: wet.hh:300
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
Definition: traits.hh:67
auto end() const -> const_iterator
Definition: wet.hh:701
typename map_t::value_type value_type
Definition: wet.hh:247
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
Definition: wet.hh:379
static key_t key(char k)
Special for char: map -1 to 255 (MAX_UCHAR), not MAX_INT.
Definition: wet.hh:704
Storage for a label and a non-null weight.
Definition: wet.hh:107
static constexpr wet_kind_t kind
Definition: wet.hh:798
void set(const iterator &, const value_t v=true)
Definition: wet.hh:721
auto cbegin() const -> const_iterator
Definition: wet.hh:488
wet_map(std::initializer_list< value_type > l)
Definition: wet.hh:253
welement_t operator*() const
Definition: wet.hh:662
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
Definition: wet.hh:375
void erase(char k)
Definition: wet.hh:737
friend bool operator<(const self_t &lhs, const self_t &rhs)
Allow wet_bitset to be used in containers.
Definition: wet.hh:784
auto end() -> iterator
Definition: wet.hh:695
Empty labels, for LAO.
Definition: empty.hh:8
Weighted set: labels are non-negative integers, weights are bools.
Definition: wet.hh:549
static constexpr size_t npos
Definition: wet.hh:612
auto find(key_t k) const -> const_iterator
Definition: wet.hh:742
static constexpr wet_kind_t kind
Definition: wet.hh:557
static const value_t & value_of(const value_type &p)
Definition: wet.hh:343
Request the unordered_map implementation.
void label(const label_t &l)
Definition: wet.hh:40
std::map< Key, Value, Compare > map_t
Definition: wet.hh:237
static const key_t & key_of(const value_type &p)
Definition: wet.hh:257
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
Definition: wet.hh:374
void set(const iterator &i, const value_t &v)
Definition: wet.hh:353
auto find(key_t k) -> iterator
Definition: wet.hh:751
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
Definition: wet.hh:146
welement_t operator*() const
Definition: wet.hh:446
Looking downstream.
Request the bitset implementation (bool weights).
const set_t & set() const
Definition: wet.hh:586
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
Definition: wet.hh:297
wet_kind_t
Different implementations of wets.
Definition: wet.hh:197
Request the set implementation (bool weights).
iterator_impl(const iterator_impl< OtherValue, OtherIterator > &that) noexcept
Definition: wet.hh:434
Storage for a label.
Definition: wet.hh:29
wet_set(std::initializer_list< value_type > p)
Definition: wet.hh:410
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
Definition: wet.hh:294
welement_weight(const weight_t &w)
Definition: wet.hh:69
void weight_set(welement< Label, Weight > &m, const Weight &w)
Set the weight of a welement.
Definition: wet.hh:162
set_t & set()
FIXME: Avoid this by exposing more interfaces.
Definition: wet.hh:592
auto operator<(const welement &that) const -> bool
Definition: wet.hh:131
const iterator_t & iterator() const
Definition: wet.hh:657