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
429 template <
typename OtherValue,
typename OtherIterator>
467 template <
typename OtherValue,
typename OtherIterator>
505 return set_.erase(pos.iterator());
508 template <
typename... Args>
509 auto find(Args&&... args) const
512 return set_.find(std::forward<Args>(args)...);
515 template <
typename... Args>
519 return set_.find(std::forward<Args>(args)...);
523 #define DEFINE(Name, Const) \
524 template <typename... Args> \
526 Name(Args&&... args) Const \
527 -> decltype(set_.Name(std::forward<Args>(args)...)) \
529 return set_.Name(std::forward<Args>(args)...); \
549 using set_t = boost::dynamic_bitset<>;
575 for (
const auto& m: p)
580 : set_{std::move(
set)}
609 static constexpr
size_t npos = set_t::npos;
612 template <
typename Value,
typename Set>
614 :
public boost::iterator_facade<iterator_impl<Value, Set>
616 , boost::forward_traversal_tag
625 template <
typename OtherValue,
typename OtherSet>
638 ,
it_(set.find_first())
643 assert(&set_ == &that.
set_);
669 it_ = set_.find_next(
it_);
672 template <
typename OtherValue,
typename OtherSet>
702 return static_cast<unsigned char>(k);
725 set_.reset(pos.iterator());
771 return {set_ - rhs.
set_};
776 return {set_ & rhs.
set_};
791 template <
typename Key,
typename Value>
798 template <
typename Key>
813 template <
typename Key,
typename Value>
826 typename Key,
typename Value,
827 typename Compare,
typename Hash,
typename KeyEqual>
832 wet_set<Key, Compare>,
834 wet_map<Key, Value, Compare>,
836 wet_unordered_map<Key, Value, Hash, KeyEqual>,
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>>
848 Key, Value, Compare, Hash, KeyEqual>;
851 template <
typename Context,
852 wet_kind_t Kind = detail::wet_kind<labelset_t_of<Context>,
const set_t & set() const
auto end() const -> const_iterator
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
Storage for a label and a non-null weight.
auto operator<(const welement &that) const -> bool
void label(const label_t &l)
wet_unordered_map(std::initializer_list< value_type > l)
Set set_t
Underlying "iterator".
welement_label(const label_t &)
welement_t operator*() const
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
auto find(char k) -> iterator
auto erase(const_iterator pos) -> void
Weighted set: labels are non-negative integers, weights are bools.
auto erase(const_iterator pos) -> iterator
void increment()
Advance to next position.
friend class boost::iterator_core_access
Iterator iterator_t
Underlying iterator.
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
auto cend() const -> const_iterator
void weight_set(welement< Label, Weight > &m, const Weight &w)
Set the weight of a welement.
auto empty(Args &&...args) const -> decltype(set_.empty(std::forward< Args >(args)...))
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
void set(const key_t k, value_t v=true)
friend class boost::iterator_core_access
auto cbegin() const -> const_iterator
wet_map(std::initializer_list< value_type > l)
static constexpr wet_kind_t kind
welement_weight(weight_t &&w)
welement_label(label_t &&l)
typename map_t::mapped_type mapped_type
void for_each(Fun f) const
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
iterator_impl(const iterator_impl< OtherValue, OtherSet > &that)
Request the set implementation (bool weights).
auto size(Args &&...args) const -> decltype(set_.size(std::forward< Args >(args)...))
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
typename map_t::value_type value_type
welement_label(const label_t &l)
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.
void set(const key_t &k, const value_t &v)
iterator_impl(const iterator_t &it)
std::string to_string(direction d)
Conversion to string.
welement_weight(weight_t &&w)
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
static constexpr wet_kind_t kind
const set_t & set() const
const iterator_t & iterator() const
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
std::string type(const automaton &a)
The implementation type of a.
detail::wet_impl< Kind, Key, Value, Compare, Hash, KeyEqual > wet
Given Key/Value types, the appropriate weighted set type.
auto operator==(const welement &that) const -> bool
welement(Label2 &&l, Weight2 &&w)
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
auto cbegin() const -> const_iterator
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.
static const key_t & key_of(const value_type &p)
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
void set(const iterator &i, const value_t &v)
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
auto begin() const -> const_iterator
set_t & set_
Underlying bitset.
wet_bitset(std::initializer_list< value_type > p)
#define BUILTIN_UNREACHABLE()
iterator_impl(set_t &set)
void set(const char k, value_t v=true)
welement< key_t, value_t > welement_t
bool equal(const iterator_impl< OtherValue, OtherIterator > &that) const
Request the unordered_map implementation.
const label_t & label() const
static constexpr wet_kind_t kind
static const value_t & value_of(const value_type &p)
iterator_impl(const iterator_impl< OtherValue, OtherIterator > &that)
wet_set(std::initializer_list< value_type > p)
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
std::map< Key, Value, Compare > map_t
typename map_t::const_iterator const_iterator
typename map_t::iterator iterator
welement_t operator*() const
auto find(Args &&...args) -> iterator
welement< typename std::remove_reference< label_t >::type, typename std::remove_reference< weight_t >::type > value_t
Weighted set: weights are bools.
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
auto end() const -> const_iterator
static const value_t & value_of(const value_type &p)
static key_t key(char k)
Special for char: map -1 to 255 (MAX_UCHAR), not MAX_INT.
iterator_impl & operator=(const iterator_impl &that)
static constexpr wet_kind_t kind
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
wet_kind_t
Different implementations of wets.
const iterator_t & iterator() const
auto cend() const -> const_iterator
self_t operator-(const self_t &rhs) const
Operators for when wet_bitset is used as a bitset.
Storage for a non-null weight.
void set(const iterator &, const value_t &v)
void weight(const weight_t &k)
auto find(Args &&...args) const -> const_iterator
void set(const key_t &k, const value_t &v)
wet_unordered_map()=default
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
static constexpr size_t npos
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
typename map_t::const_iterator const_iterator
static constexpr wet_kind_t kind
void set(const key_t &k, const value_t &v)
welement_weight(const weight_t &w)
void weight(const weight_t &w)
auto find(key_t k) -> iterator
Request the bitset implementation (bool weights).
void set(const iterator &i, const value_t &v)
Weighted set: general, unordered, case.
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
Weighted set: general, ordered, case.
void for_each(Fun f) const
welement< key_t, value_t > welement_t
bool equal(const iterator_impl< OtherValue, OtherSet > &that) const
auto key_comp(Args &&...args) const -> decltype(map_.key_comp(std::forward< Args >(args)...))
typename map_t::value_type value_type
constexpr wet_kind_t wet_kind()
Given a Key and a Value type, the appropriate weighted set type.
auto find(char k) const -> const_iterator
const weight_t & weight() const
self_t operator&(const self_t &rhs) const
void set(const iterator &, const value_t v=true)
auto clear(Args &&...args) -> decltype(set_.clear(std::forward< Args >(args)...))
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
void increment()
Advance to next position.
welement_label(label_t &&)
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
iterator_impl(set_t &set, size_t pos)
auto begin() const -> const_iterator
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
static const key_t & key_of(const value_type &p)
auto find(key_t k) const -> const_iterator
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
welement_weight(const weight_t &w)
set_t & set()
FIXME: Avoid this by exposing more interfaces.
std::set< Key, Compare > set_t
Functor to compare Values of ValueSets.
std::unordered_map< Key, Value, Hash, KeyEqual > map_t
Request the map implementation.
typename map_t::iterator iterator
boost::dynamic_bitset<> set_t
friend bool operator<(const self_t &lhs, const self_t &rhs)
Allow wet_bitset to be used in containers.