7 #include <unordered_map>
9 #include <boost/iterator/iterator_facade.hpp>
28 template <
typename Label>
65 template <
typename Weight>
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>
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_);
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>
836 wet_set<Key, Compare>,
838 wet_map<Key, Value, Compare>,
840 wet_unordered_map<Key, Value, Hash, 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 find(char k) const -> const_iterator
const weight_t & weight() const
void set(const iterator &, const value_t &v)
iterator_impl & operator=(const iterator_impl &that) noexcept
auto find(Args &&...args) const -> const_iterator
wet_unordered_map()=default
static constexpr wet_kind_t kind
typename map_t::const_iterator const_iterator
welement_label(label_t &&l)
typename map_t::iterator iterator
void set(const iterator &i, const value_t &v)
void set(const key_t &k, const value_t &v)
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
boost::dynamic_bitset<> set_t
auto erase(const_iterator pos) -> void
auto operator==(const welement &that) const -> bool
static const value_t & value_of(const value_type &p)
welement(Label2 &&l, Weight2 &&w)
Functor to compare Values of ValueSets.
welement_weight(weight_t &&w)
void set(const key_t k, value_t v=true)
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
auto find(Args &&...args) -> iterator
welement_label(label_t &&)
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
auto find(char k) -> iterator
typename map_t::const_iterator const_iterator
static const key_t & key_of(const value_type &p)
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
welement_label(const label_t &l)
auto key_comp(Args &&...args) const -> decltype(map_.key_comp(std::forward< Args >(args)...))
typename map_t::value_type value_type
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
welement_weight(weight_t &&w)
iterator_impl(const iterator_t &it) noexcept
std::unordered_map< Key, Value, Hash, KeyEqual > map_t
Weighted set: weights are bools.
void increment()
Advance to next position.
friend class boost::iterator_core_access
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.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
wet_bitset(std::initializer_list< value_type > p)
void for_each(Fun f) const
void set(const key_t &k, const value_t &v)
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
Request the map implementation.
iterator_impl(set_t &set) noexcept
void set(const char k, value_t v=true)
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.
friend class boost::iterator_core_access
Storage for a non-null weight.
auto clear(Args &&...args) -> decltype(set_.clear(std::forward< Args >(args)...))
Set set_t
Underlying "iterator".
std::string type(const automaton &a)
The implementation type of a.
welement< typename std::remove_reference< label_t >::type, typename std::remove_reference< weight_t >::type > value_t
constexpr wet_kind_t wet_kind()
Given a Key and a Value type, the appropriate weighted set type.
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
auto erase(const_iterator pos) -> iterator
Iterator iterator_t
Underlying iterator.
welement< key_t, value_t > welement_t
bool equal(const iterator_impl< OtherValue, OtherSet > &that) const
auto cend() const -> const_iterator
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
auto cbegin() const -> const_iterator
std::set< Key, Compare > set_t
welement_label(const label_t &)
void weight(const weight_t &k)
Weighted set: general, unordered, case.
welement< key_t, value_t > welement_t
const set_t & set() const
Weighted set: general, ordered, case.
auto begin() const -> const_iterator
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
const iterator_t & iterator() const
auto begin() const -> const_iterator
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
void set(const key_t &k, const value_t &v)
auto empty(Args &&...args) const -> decltype(set_.empty(std::forward< Args >(args)...))
welement_weight(const weight_t &w)
self_t operator-(const self_t &rhs) const
Operators for when wet_bitset is used as a bitset.
static constexpr wet_kind_t kind
#define BUILTIN_UNREACHABLE()
void increment()
Advance to next position.
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
void for_each(Fun f) const
typename map_t::iterator iterator
set_t & set_
Underlying bitset.
auto end() const -> const_iterator
const label_t & label() const
void weight(const weight_t &w)
self_t operator&(const self_t &rhs) const
detail::wet_impl< Kind, Key, Value, Compare, Hash, KeyEqual > wet
Given Key/Value types, the appropriate weighted set type.
wet_unordered_map(std::initializer_list< value_type > l)
auto cend() const -> const_iterator
typename map_t::mapped_type mapped_type
iterator_impl(set_t &set, iterator_t it) noexcept
static constexpr wet_kind_t kind
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
bool equal(const iterator_impl< OtherValue, OtherIterator > &that) const
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
std::string to_string(direction d)
Conversion to string.
auto size(Args &&...args) const -> decltype(set_.size(std::forward< Args >(args)...))
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
auto end() const -> const_iterator
typename map_t::value_type value_type
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
static key_t key(char k)
Special for char: map -1 to 255 (MAX_UCHAR), not MAX_INT.
Storage for a label and a non-null weight.
static constexpr wet_kind_t kind
void set(const iterator &, const value_t v=true)
auto cbegin() const -> const_iterator
wet_map(std::initializer_list< value_type > l)
welement_t operator*() const
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
friend bool operator<(const self_t &lhs, const self_t &rhs)
Allow wet_bitset to be used in containers.
Weighted set: labels are non-negative integers, weights are bools.
static constexpr size_t npos
auto find(key_t k) const -> const_iterator
static constexpr wet_kind_t kind
static const value_t & value_of(const value_type &p)
Request the unordered_map implementation.
void label(const label_t &l)
std::map< Key, Value, Compare > map_t
static const key_t & key_of(const value_type &p)
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
void set(const iterator &i, const value_t &v)
auto find(key_t k) -> iterator
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
welement_t operator*() const
Request the bitset implementation (bool weights).
const set_t & set() const
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
wet_kind_t
Different implementations of wets.
Request the set implementation (bool weights).
iterator_impl(const iterator_impl< OtherValue, OtherIterator > &that) noexcept
wet_set(std::initializer_list< value_type > p)
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
welement_weight(const weight_t &w)
void weight_set(welement< Label, Weight > &m, const Weight &w)
Set the weight of a welement.
set_t & set()
FIXME: Avoid this by exposing more interfaces.
auto operator<(const welement &that) const -> bool
const iterator_t & iterator() const