Vcsn  2.2a
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  template <typename OtherValue, typename OtherIterator>
431  : it_(that.iterator())
432  {}
433 
435  : it_(it)
436  {}
437 
438  const iterator_t& iterator() const
439  {
440  return it_;
441  }
442 
444  {
445  return {*it_, true};
446  }
447 
448  private:
450 
452  void increment()
453  {
454  ++it_;
455  }
456 
457  void decrement()
458  {
459  --it_;
460  }
461 
462  void advance(int n)
463  {
464  it_ += n;
465  }
466 
467  template <typename OtherValue, typename OtherIterator>
469  {
470  return iterator() == that.iterator();
471  }
472 
474  };
475 
478 
480  using const_iterator
482 
483  auto begin() -> iterator { return {set_.begin()}; }
484  auto end() -> iterator { return {set_.end()}; }
485  auto cbegin() const -> const_iterator { return {set_.cbegin()}; }
486  auto cend() const -> const_iterator { return {set_.cend()}; }
487  auto begin() const -> const_iterator { return cbegin(); }
488  auto end() const -> const_iterator { return cend(); }
489 
490  void set(const key_t& k, const value_t& v)
491  {
492  assert(v); (void) v;
493  set_.emplace(k);
494  }
495 
496  // When called, the key is already defined.
497  void set(const iterator&, const value_t& v)
498  {
499  assert(v); (void) v;
500  }
501 
503  -> iterator
504  {
505  return set_.erase(pos.iterator());
506  }
507 
508  template <typename... Args>
509  auto find(Args&&... args) const
510  -> const_iterator
511  {
512  return set_.find(std::forward<Args>(args)...);
513  }
514 
515  template <typename... Args>
516  auto find(Args&&... args)
517  -> iterator
518  {
519  return set_.find(std::forward<Args>(args)...);
520  }
521 
522 
523 #define DEFINE(Name, Const) \
524  template <typename... Args> \
525  auto \
526  Name(Args&&... args) Const \
527  -> decltype(set_.Name(std::forward<Args>(args)...)) \
528  { \
529  return set_.Name(std::forward<Args>(args)...); \
530  }
531 
534  DEFINE(empty,const);
535  DEFINE(size, const);
536 #undef DEFINE
537  };
538 
539 
540  /*---------------------------------------.
541  | wet_bitset<unsigned, bool>: bitsets. |
542  `---------------------------------------*/
543 
547  {
548  private:
549  using set_t = boost::dynamic_bitset<>;
551 
552  public:
554  static constexpr wet_kind_t kind = wet_kind_t::bitset;
555  using key_t = unsigned;
556  using value_t = bool;
559 
560  // A plain "wet_bitset() = default;" fails with GCC 4.8 or 4.9.0:
561  // error: converting to 'const boost::dynamic_bitset<>'
562  // from initializer list would use explicit constructor
563  // 'boost::dynamic_bitset<Block, Allocator>::dynamic_bitset([...])
564  //
565  // wet_bitset() = default;
566  // ^
568 
569  wet_bitset(size_t size)
570  : set_{size}
571  {}
572 
573  wet_bitset(std::initializer_list<value_type> p)
574  {
575  for (const auto& m: p)
576  set(label_of(m), weight_of(m));
577  }
578 
580  : set_{std::move(set)}
581  {}
582 
583  const set_t& set() const
584  {
585  return set_;
586  }
587 
590  {
591  return set_;
592  }
593 
594  void clear()
595  {
596  set_.reset();
597  }
598 
599  bool empty() const
600  {
601  return set_.none();
602  }
603 
604  size_t size() const
605  {
606  return set_.count();
607  }
608 
609  static constexpr size_t npos = set_t::npos;
610 
612  template <typename Value, typename Set>
614  : public boost::iterator_facade<iterator_impl<Value, Set>
615  , Value
616  , boost::forward_traversal_tag
617  >
618  {
620  using set_t = Set;
621  using iterator_t = size_t;
622  using value_t = Value;
624 
625  template <typename OtherValue, typename OtherSet>
627  : set_(that.set())
628  , it_(that.iterator())
629  {}
630 
631  iterator_impl(set_t& set, size_t pos)
632  : set_(set)
633  , it_(pos)
634  {}
635 
637  : set_(set)
638  , it_(set.find_first())
639  {}
640 
642  {
643  assert(&set_ == &that.set_);
644  it_ = that.it_;
645  return *this;
646  }
647 
648  const set_t& set() const
649  {
650  return set_;
651  }
652 
653  const iterator_t& iterator() const
654  {
655  return it_;
656  }
657 
659  {
660  return {key_t(it_), true};
661  }
662 
663  private:
665 
667  void increment()
668  {
669  it_ = set_.find_next(it_);
670  }
671 
672  template <typename OtherValue, typename OtherSet>
674  {
675  return (iterator() == that.iterator()
676  && set() == that.set());
677  }
678 
682  };
683 
686 
689 
690  auto begin() -> iterator { return {set_}; }
691  auto end() -> iterator { return {set_, npos}; }
692 
693  auto cbegin() const -> const_iterator { return {set_}; }
694  auto cend() const -> const_iterator { return {set_, npos}; }
695 
696  auto begin() const -> const_iterator { return cbegin(); }
697  auto end() const -> const_iterator { return cend(); }
698 
700  static key_t key(char k)
701  {
702  return static_cast<unsigned char>(k);
703  }
704 
705  void set(const key_t k, value_t v = true)
706  {
707  assert(v); (void) v;
708  set_.set(k);
709  }
710 
711  void set(const char k, value_t v = true)
712  {
713  set(key(k), v);
714  }
715 
716  // When called, the key is already defined.
717  void set(const iterator&, const value_t v = true)
718  {
719  assert(v); (void) v;
720  }
721 
723  -> void
724  {
725  set_.reset(pos.iterator());
726  }
727 
728  void erase(key_t k)
729  {
730  set_.reset(k);
731  }
732 
733  void erase(char k)
734  {
735  erase(key(k));
736  }
737 
738  auto find(key_t k) const
739  -> const_iterator
740  {
741  if (set_[k])
742  return {set_, k};
743  else
744  return end();
745  }
746 
747  auto find(key_t k)
748  -> iterator
749  {
750  if (set_[k])
751  return {set_, k};
752  else
753  return end();
754  }
755 
756  auto find(char k) const
757  -> const_iterator
758  {
759  return find(key(k));
760  }
761 
762  auto find(char k)
763  -> iterator
764  {
765  return find(key(k));
766  }
767 
769  self_t operator-(const self_t& rhs) const
770  {
771  return {set_ - rhs.set_};
772  }
773 
774  self_t operator&(const self_t& rhs) const
775  {
776  return {set_ & rhs.set_};
777  }
778 
780  friend bool operator<(const self_t& lhs, const self_t& rhs)
781  {
782  return lhs.set_ < rhs.set_;
783  }
784  };
785 
786  /*------------------------.
787  | wet_kind<Key, Value>. |
788  `------------------------*/
789 
791  template <typename Key, typename Value>
793  {
794  static constexpr wet_kind_t kind = wet_kind_t::map;
795  };
796 
798  template <typename Key>
799  struct wet_kind_impl<Key, bool>
800  {
801  static constexpr wet_kind_t kind = wet_kind_t::set;
802  };
803 
805  template <>
806  struct wet_kind_impl<char, bool>
807  {
808  static constexpr wet_kind_t kind = wet_kind_t::bitset;
809  };
810 
813  template <typename Key, typename Value>
814  constexpr wet_kind_t wet_kind()
815  {
817  }
818 
819 
820  /*------------------------.
821  | wet_impl<Key, Value>. |
822  `------------------------*/
823 
825  template <wet_kind_t Kind,
826  typename Key, typename Value,
827  typename Compare, typename Hash, typename KeyEqual>
828  using wet_impl
829  = std::conditional_t<Kind == wet_kind_t::bitset,
830  wet_bitset,
831  std::conditional_t<Kind == wet_kind_t::set,
832  wet_set<Key, Compare>,
833  std::conditional_t<Kind == wet_kind_t::map,
834  wet_map<Key, Value, Compare>,
835  std::conditional_t<Kind == wet_kind_t::unordered_map,
836  wet_unordered_map<Key, Value, Hash, KeyEqual>,
837  void> > > >;
838 
839  }
840 
842  template <typename Key, typename Value,
843  wet_kind_t Kind = detail::wet_kind<Key, Value>(),
844  typename Compare = std::less<Key>,
845  typename Hash = std::hash<Key>,
846  typename KeyEqual = std::equal_to<Key>>
847  using wet = detail::wet_impl<Kind,
848  Key, Value, Compare, Hash, KeyEqual>;
849 
851  template <typename Context,
852  wet_kind_t Kind = detail::wet_kind<labelset_t_of<Context>,
856  Kind,
860 }
void set(const iterator &i, const value_t &v)
Definition: wet.hh:353
Weighted set: weights are bools.
Definition: wet.hh:395
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
Definition: wet.hh:380
static key_t key(char k)
Special for char: map -1 to 255 (MAX_UCHAR), not MAX_INT.
Definition: wet.hh:700
auto cend() const -> const_iterator
Definition: wet.hh:486
auto erase(const_iterator pos) -> void
Definition: wet.hh:722
Request the unordered_map implementation.
auto end() const -> const_iterator
Definition: wet.hh:697
void increment()
Advance to next position.
Definition: wet.hh:452
typename map_t::const_iterator const_iterator
Definition: wet.hh:330
typename map_t::mapped_type mapped_type
Definition: wet.hh:246
wet_bitset(std::initializer_list< value_type > p)
Definition: wet.hh:573
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
Definition: traits.hh:54
Storage for a label.
Definition: wet.hh:29
iterator_impl(const iterator_t &it)
Definition: wet.hh:434
auto size(Args &&...args) const -> decltype(set_.size(std::forward< Args >(args)...))
Definition: wet.hh:535
void set(const char k, value_t v=true)
Definition: wet.hh:711
iterator_impl(const iterator_impl< OtherValue, OtherIterator > &that)
Definition: wet.hh:430
weight_t weight() const
Definition: wet.hh:96
friend bool operator<(const self_t &lhs, const self_t &rhs)
Allow wet_bitset to be used in containers.
Definition: wet.hh:780
typename map_t::value_type value_type
Definition: wet.hh:247
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
void set(const iterator &, const value_t v=true)
Definition: wet.hh:717
void set(const key_t &k, const value_t &v)
Definition: wet.hh:267
friend class boost::iterator_core_access
Definition: wet.hh:449
const iterator_t & iterator() const
Definition: wet.hh:438
auto find(key_t k) -> iterator
Definition: wet.hh:747
void for_each(Fun f) const
Definition: wet.hh:359
static constexpr wet_kind_t kind
Definition: wet.hh:242
auto erase(const_iterator pos) -> iterator
Definition: wet.hh:502
static constexpr size_t npos
Definition: wet.hh:609
typename map_t::iterator iterator
Definition: wet.hh:329
const set_t & set() const
Definition: wet.hh:583
const weight_t & weight() const
Definition: wet.hh:75
Request the bitset implementation (bool weights).
Weighted set: general, ordered, case.
Definition: wet.hh:234
static constexpr wet_kind_t kind
Definition: wet.hh:554
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
Definition: wet.hh:384
wet_kind_t
Different implementations of wets.
Definition: wet.hh:197
welement(Label2 &&l, Weight2 &&w)
Definition: wet.hh:121
const set_t & set() const
Definition: wet.hh:648
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
Definition: wet.hh:297
welement< key_t, value_t > welement_t
Definition: wet.hh:557
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
Definition: wet.hh:296
static constexpr wet_kind_t kind
Definition: wet.hh:794
auto begin() const -> const_iterator
Definition: wet.hh:487
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
Definition: wet.hh:383
auto find(char k) const -> const_iterator
Definition: wet.hh:756
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
Definition: wet.hh:299
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
Definition: wet.hh:146
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:837
welement_weight(const weight_t &w)
Definition: wet.hh:69
welement_t operator*() const
Definition: wet.hh:658
Looking downstream.
void set(const iterator &, const value_t &v)
Definition: wet.hh:497
void weight(const weight_t &k)
Definition: wet.hh:76
welement_label(const label_t &)
Definition: wet.hh:51
Iterator iterator_t
Underlying iterator.
Definition: wet.hh:425
std::unordered_map< Key, Value, Hash, KeyEqual > map_t
Definition: wet.hh:319
auto find(char k) -> iterator
Definition: wet.hh:762
self_t operator-(const self_t &rhs) const
Operators for when wet_bitset is used as a bitset.
Definition: wet.hh:769
void weight(const weight_t &w)
Definition: wet.hh:97
typename map_t::iterator iterator
Definition: wet.hh:248
std::string type(const automaton &a)
The implementation type of a.
Definition: others.cc:206
set_t & set_
Underlying bitset.
Definition: wet.hh:680
void set(const key_t &k, const value_t &v)
Definition: wet.hh:348
auto end() -> iterator
Definition: wet.hh:484
wet_bitset(size_t size)
Definition: wet.hh:569
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
Definition: wet.hh:376
auto cbegin() const -> const_iterator
Definition: wet.hh:693
wet_bitset(set_t &&set)
Definition: wet.hh:579
static constexpr wet_kind_t kind
Definition: wet.hh:403
self_t operator&(const self_t &rhs) const
Definition: wet.hh:774
welement< key_t, value_t > welement_t
Definition: wet.hh:406
Storage for a label and a non-null weight.
Definition: wet.hh:107
std::map< Key, Value, Compare > map_t
Definition: wet.hh:237
auto key_comp(Args &&...args) const -> decltype(map_.key_comp(std::forward< Args >(args)...))
Definition: wet.hh:293
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
Definition: wet.hh:300
typename map_t::value_type value_type
Definition: wet.hh:328
welement< typename std::remove_reference< label_t >::type, typename std::remove_reference< weight_t >::type > value_t
Definition: wet.hh:118
auto end() -> iterator
Definition: wet.hh:691
auto clear(Args &&...args) -> decltype(set_.clear(std::forward< Args >(args)...))
Definition: wet.hh:532
static constexpr wet_kind_t kind
Definition: wet.hh:324
auto begin() -> iterator
Definition: wet.hh:690
Request the map implementation.
Storage for a non-null weight.
Definition: wet.hh:66
void for_each(Fun f) const
Definition: wet.hh:278
void weight_set(welement< Label, Weight > &m, const Weight &w)
Set the weight of a welement.
Definition: wet.hh:162
static const key_t & key_of(const value_type &p)
Definition: wet.hh:338
iterator_impl & operator=(const iterator_impl &that)
Definition: wet.hh:641
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
Definition: functional.hh:42
welement_label(const label_t &l)
Definition: wet.hh:32
wet_impl: map.
Definition: wet.hh:792
bool equal(const iterator_impl< OtherValue, OtherSet > &that) const
Definition: wet.hh:673
std::set< Key, Compare > set_t
Definition: wet.hh:398
welement_weight(weight_t &&w)
Definition: wet.hh:72
wet_set(std::initializer_list< value_type > p)
Definition: wet.hh:410
bool empty() const
Definition: wet.hh:599
typename map_t::const_iterator const_iterator
Definition: wet.hh:249
void increment()
Advance to next position.
Definition: wet.hh:667
Request the set implementation (bool weights).
Weighted set: general, unordered, case.
Definition: wet.hh:316
auto end() const -> const_iterator
Definition: wet.hh:488
auto find(Args &&...args) -> iterator
Definition: wet.hh:516
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
Definition: wet.hh:379
void label(const label_t &l)
Definition: wet.hh:40
wet_unordered_map(std::initializer_list< value_type > l)
Definition: wet.hh:334
auto begin() -> iterator
Definition: wet.hh:483
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
Definition: functional.hh:12
bool equal(const iterator_impl< OtherValue, OtherIterator > &that) const
Definition: wet.hh:468
void erase(key_t k)
Definition: wet.hh:728
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
Definition: wet.hh:295
STL namespace.
Empty labels, for LAO.
Definition: empty.hh:8
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
Definition: wet.hh:375
void erase(char k)
Definition: wet.hh:733
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
Definition: traits.hh:59
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:859
auto find(Args &&...args) const -> const_iterator
Definition: wet.hh:509
void set(const key_t &k, const value_t &v)
Definition: wet.hh:490
auto empty(Args &&...args) const -> decltype(set_.empty(std::forward< Args >(args)...))
Definition: wet.hh:534
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
Definition: wet.hh:304
auto cbegin() const -> const_iterator
Definition: wet.hh:485
wet_map(std::initializer_list< value_type > l)
Definition: wet.hh:253
welement_label(label_t &&l)
Definition: wet.hh:35
Weighted set: labels are non-negative integers, weights are bools.
Definition: wet.hh:546
auto begin() const -> const_iterator
Definition: wet.hh:696
Set set_t
Underlying "iterator".
Definition: wet.hh:620
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
#define DEFINE(K)
Definition: wet.hh:523
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
Definition: wet.hh:377
iterator_impl(set_t &set, size_t pos)
Definition: wet.hh:631
welement_weight(const weight_t &w)
Definition: wet.hh:88
void set(const iterator &i, const value_t &v)
Definition: wet.hh:272
boost::dynamic_bitset<> set_t
Definition: wet.hh:549
const iterator_t & iterator() const
Definition: wet.hh:653
const label_t & label() const
Definition: wet.hh:39
static const value_t & value_of(const value_type &p)
Definition: wet.hh:343
set_t & set()
FIXME: Avoid this by exposing more interfaces.
Definition: wet.hh:589
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
Definition: wet.hh:294
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
Definition: wet.hh:374
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:55
detail::wet_impl< Kind, Key, Value, Compare, Hash, KeyEqual > wet
Given Key/Value types, the appropriate weighted set type.
Definition: wet.hh:848
void set(const key_t k, value_t v=true)
Definition: wet.hh:705
friend class boost::iterator_core_access
Definition: wet.hh:664
size_t size() const
Definition: wet.hh:604
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
Definition: wet.hh:154
auto operator==(const welement &that) const -> bool
Definition: wet.hh:137
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Definition: traits.hh:58
constexpr wet_kind_t wet_kind()
Given a Key and a Value type, the appropriate weighted set type.
Definition: wet.hh:814
auto find(key_t k) const -> const_iterator
Definition: wet.hh:738
iterator_impl(const iterator_impl< OtherValue, OtherSet > &that)
Definition: wet.hh:626
auto operator<(const welement &that) const -> bool
Definition: wet.hh:131
auto cend() const -> const_iterator
Definition: wet.hh:694
static const value_t & value_of(const value_type &p)
Definition: wet.hh:262
Functor to compare Values of ValueSets.
Definition: functional.hh:78
welement_t operator*() const
Definition: wet.hh:443
static const key_t & key_of(const value_type &p)
Definition: wet.hh:257
Definition: a-star.hh:8
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
Definition: wet.hh:303