7 #include <unordered_map> 9 #include <boost/iterator/iterator_facade.hpp> 28 template <
typename Label>
65 template <
typename Weight>
73 : weight_{std::move(w)}
106 template <
typename Label,
typename Weight>
120 template <
typename Label2,
typename Weight2>
134 return this->
label() < that.label();
140 return this->
label() == that.label();
145 template <
typename Label,
typename Weight>
147 -> decltype(m.label())
153 template <
typename Label,
typename Weight>
155 -> decltype(m.weight())
161 template <
typename Label,
typename Weight>
168 template <
typename Label,
typename Weight>
169 const Label&
label_of(
const std::pair<Label, Weight>& m)
175 template <
typename Label,
typename Weight>
176 const Weight&
weight_of(
const std::pair<Label, Weight>& m)
182 template <
typename Label,
typename Weight>
189 template <
typename Label,
typename Weight>
190 void weight_set(std::pair<Label, Weight>& m,
const Weight& w)
212 #define DEFINE(K) case wet_kind_t::K: return "vcsn::wet_kind_t::" #K 232 template <
typename Key,
typename Value,
237 using map_t = std::map<Key, Value, Compare>;
277 template <
typename Fun>
280 std::for_each(begin(map_), end(map_),
284 #define DEFINE(Name, Const) \ 285 template <typename... Args> \ 287 Name(Args&&... args) Const \ 288 -> decltype(map_.Name(std::forward<Args>(args)...)) \ 290 return map_.Name(std::forward<Args>(args)...); \ 314 template <
typename Key,
typename Value,
315 typename Hash,
typename KeyEqual>
319 using map_t = std::unordered_map<Key, Value, Hash, KeyEqual>;
358 template <
typename Fun>
361 std::for_each(begin(map_), end(map_),
365 #define DEFINE(Name, Const) \ 366 template <typename... Args> \ 368 Name(Args&&... args) Const \ 369 -> decltype(map_.Name(std::forward<Args>(args)...)) \ 371 return map_.Name(std::forward<Args>(args)...); \ 394 template <
typename Key,
typename Compare>
398 using set_t = std::set<Key, Compare>;
412 for (
const auto& m: p)
417 template <
typename Value,
typename Iterator>
419 :
public boost::iterator_facade<iterator_impl<Value, Iterator>
421 , boost::forward_traversal_tag
433 template <
typename OtherValue,
typename OtherIterator>
452 friend class boost::iterator_core_access;
470 template <
typename OtherValue,
typename OtherIterator>
508 return set_.erase(pos.iterator());
511 template <
typename... Args>
512 auto find(Args&&... args)
const 515 return set_.find(std::forward<Args>(args)...);
518 template <
typename... Args>
522 return set_.find(std::forward<Args>(args)...);
526 #define DEFINE(Name, Const) \ 527 template <typename... Args> \ 529 Name(Args&&... args) Const \ 530 -> decltype(set_.Name(std::forward<Args>(args)...)) \ 532 return set_.Name(std::forward<Args>(args)...); \ 552 using set_t = boost::dynamic_bitset<>;
578 for (
const auto& m: p)
583 : set_{std::move(
set)}
612 static constexpr
size_t npos = set_t::npos;
615 template <
typename Value,
typename Set>
617 :
public boost::iterator_facade<iterator_impl<Value, Set>
619 , boost::forward_traversal_tag
639 template <
typename OtherValue,
typename OtherIterator>
647 assert(&set_ == &that.set_);
664 return {
key_t(it_),
true};
668 friend class boost::iterator_core_access;
673 it_ = set_.find_next(it_);
676 template <
typename OtherValue,
typename OtherSet>
679 assert(&
set() == &that.
set());
706 return static_cast<unsigned char>(k);
729 set_.reset(pos.iterator());
775 return {set_ - rhs.
set_};
780 return {set_ & rhs.
set_};
795 template <
typename Key,
typename Value>
802 template <
typename Key>
817 template <
typename Key,
typename Value>
830 typename Key,
typename Value,
831 typename Compare,
typename Hash,
typename KeyEqual>
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>>
852 Key, Value, Compare, Hash, KeyEqual>;
855 template <
typename Context,
856 wet_kind_t Kind = detail::wet_kind<labelset_t_of<Context>,
auto cend() const -> const_iterator
Iterator iterator_t
Underlying iterator.
iterator_impl(set_t &set, iterator_t it) noexcept
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
iterator_impl & operator=(const iterator_impl &that) noexcept
auto find(char k) const -> const_iterator
const iterator_t & iterator() const
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
Request the map implementation.
typename map_t::const_iterator const_iterator
typename map_t::iterator iterator
wet_set(std::initializer_list< value_type > p)
set_t & set_
Underlying bitset.
welement_label(label_t &&)
auto cend() const -> const_iterator
static const key_t & key_of(const value_type &p)
welement_label(const label_t &l)
self_t operator-(const self_t &rhs) const
Operators for when wet_bitset is used as a bitset.
Request the set implementation (bool weights).
welement_weight(weight_t &&w)
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.
iterator_impl(set_t &set) noexcept
bool equal(const iterator_impl< OtherValue, OtherSet > &that) const
typename map_t::value_type value_type
friend bool operator<(const self_t &lhs, const self_t &rhs)
Allow wet_bitset to be used in containers.
auto operator==(const welement &that) const -> bool
constexpr wet_kind_t wet_kind()
Given a Key and a Value type, the appropriate weighted set type.
bool equal(const iterator_impl< OtherValue, OtherIterator > &that) const
wet_kind_t
Different implementations of wets.
const iterator_t & iterator() const
detail::wet_impl< Kind, Key, Value, Compare, Hash, KeyEqual > wet
Given Key/Value types, the appropriate weighted set type.
void weight(const weight_t &k)
welement_label(const label_t &)
Weighted set: general, ordered, case.
auto find(Args &&... args) const -> const_iterator
Storage for a non-null weight.
welement(Label2 &&l, Weight2 &&w)
auto find(Args &&... args) -> iterator
welement_weight(const weight_t &w)
Set set_t
Underlying "iterator".
welement_t operator*() const
static const value_t & value_of(const value_type &p)
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
welement_weight(weight_t &&w)
Weighted set: weights are bools.
boost::dynamic_bitset<> set_t
auto operator &(const Lhs &l, const Rhs &r) -> decltype(conjunction(l, r))
auto find(char k) -> iterator
static const value_t & value_of(const value_type &p)
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.
typename detail::labelset_t_of_impl< base_t< ValueSet > >::type labelset_t_of
void weight(const weight_t &w)
iterator_impl(const iterator_impl< OtherValue, OtherIterator > &that) noexcept
typename map_t::value_type value_type
auto operator<(const welement &that) const -> bool
const label_t & label() const
wet_unordered_map(std::initializer_list< value_type > l)
void label(const label_t &l)
auto erase(const_iterator pos) -> void
Request the bitset implementation (bool weights).
std::map< Key, Value, Compare > map_t
std::string type(const automaton &a)
The implementation type of a.
typename detail::label_t_of_impl< base_t< ValueSet > >::type label_t_of
static const key_t & key_of(const value_type &p)
auto cbegin() const -> const_iterator
Storage for a label and a non-null weight.
auto cbegin() const -> const_iterator
static key_t key(char k)
Special for char: map -1 to 255 (MAX_UCHAR), not MAX_INT.
std::unordered_map< Key, Value, Hash, KeyEqual > map_t
auto erase(const_iterator pos) -> iterator
void weight_set(welement< Label, Weight > &m, const Weight &w)
Set the weight of a welement.
auto find(key_t k) const -> const_iterator
wet_bitset(std::initializer_list< value_type > p)
auto begin() const -> const_iterator
welement_t operator*() const
typename map_t::const_iterator const_iterator
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
Weighted set: labels are non-negative integers, weights are bools.
auto find(key_t k) -> iterator
Weighted set: general, unordered, case.
iterator_impl(const iterator_impl< OtherValue, OtherIterator > &that) noexcept
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
typename map_t::mapped_type mapped_type
auto end() const -> const_iterator
welement_label(label_t &&l)
std::set< Key, Compare > set_t
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
typename map_t::iterator iterator
const set_t & set() const
Functor to compare Values of ValueSets.
wet_impl<Key, Value>: map.
void increment()
Advance to next position.
auto begin() const -> const_iterator
void for_each(Fun f) const
iterator_impl(const iterator_t &it) noexcept
Request the unordered_map implementation.
welement_weight(const weight_t &w)
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of
std::string to_string(direction d)
Conversion to string.
auto end() const -> const_iterator
void increment()
Advance to next position.
#define BUILTIN_UNREACHABLE()
value_impl< detail::weight_tag > weight
auto map(const std::tuple< Ts... > &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
wet_map(std::initializer_list< value_type > l)
const weight_t & weight() const
void for_each(Fun f) const