7 #include <unordered_map>
9 #include <boost/iterator/iterator_facade.hpp>
26 template <
typename Label>
56 template <
typename Weight>
87 template <
typename Label,
typename Weight>
114 return this->
label() < that.label();
120 return this->
label() == that.label();
124 template <
typename Label,
typename Weight>
126 -> decltype(m.label())
131 template <
typename Label,
typename Weight>
133 -> decltype(m.weight())
138 template <
typename Label,
typename Weight>
144 template <
typename Label,
typename Weight>
145 const Label&
label_of(
const std::pair<Label, Weight>& m)
150 template <
typename Label,
typename Weight>
151 const Weight&
weight_of(
const std::pair<Label, Weight>& m)
156 template <
typename Label,
typename Weight>
162 template <
typename Label,
typename Weight>
163 void weight_set(std::pair<Label, Weight>& m,
const Weight& w)
185 template <
typename Key,
typename Value,
190 using map_t = std::map<Key, Value, Compare>;
206 wet_map(
const std::initializer_list<value_type>& l)
230 template <
typename Fun>
233 std::for_each(
begin(map_),
end(map_),
237 #define DEFINE(Name, Const) \
238 template <typename... Args> \
240 Name(Args&&... args) Const \
241 -> decltype(map_.Name(std::forward<Args>(args)...)) \
243 return map_.Name(std::forward<Args>(args)...); \
267 template <
typename Key,
typename Value,
268 typename Hash,
typename KeyEqual>
272 using map_t = std::unordered_map<Key, Value, Hash, KeyEqual>;
311 template <
typename Fun>
314 std::for_each(
begin(map_),
end(map_),
318 #define DEFINE(Name, Const) \
319 template <typename... Args> \
321 Name(Args&&... args) Const \
322 -> decltype(map_.Name(std::forward<Args>(args)...)) \
324 return map_.Name(std::forward<Args>(args)...); \
347 template <
typename Key,
typename Compare>
351 using set_t = std::set<Key, Compare>;
363 wet_set(
const std::initializer_list<value_type>& p)
365 for (
const auto& m: p)
370 template <
typename Value,
typename Iterator>
372 :
public boost::iterator_facade<iterator_impl<Value, Iterator>
374 , boost::forward_traversal_tag
382 template <
typename OtherValue,
typename OtherIterator>
420 template <
typename OtherValue,
typename OtherIterator>
458 return set_.erase(pos.iterator());
461 template <
typename... Args>
462 auto find(Args&&... args) const
465 return set_.find(std::forward<Args>(args)...);
468 template <
typename... Args>
472 return set_.find(std::forward<Args>(args)...);
476 #define DEFINE(Name, Const) \
477 template <typename... Args> \
479 Name(Args&&... args) Const \
480 -> decltype(set_.Name(std::forward<Args>(args)...)) \
482 return set_.Name(std::forward<Args>(args)...); \
500 using set_t = boost::dynamic_bitset<>;
526 for (
const auto& m: p)
531 : set_{std::move(
set)}
560 static constexpr
size_t npos = set_t::npos;
563 template <
typename Value,
typename Set>
565 :
public boost::iterator_facade<iterator_impl<Value, Set>
567 , boost::forward_traversal_tag
576 template <
typename OtherValue,
typename OtherSet>
589 ,
it_(set.find_first())
594 assert(&set_ == &that.
set_);
620 it_ = set_.find_next(
it_);
623 template <
typename OtherValue,
typename OtherSet>
653 return static_cast<unsigned char>(k);
676 set_.reset(pos.iterator());
726 template <
typename Key,
typename Value>
733 template <
typename Key>
746 template <
typename Key,
typename Value>
759 typename Key,
typename Value,
760 typename Compare,
typename Hash,
typename KeyEqual>
765 wet_set<Key, Compare>,
767 wet_map<Key, Value, Compare>,
769 wet_unordered_map<Key, Value, Hash, KeyEqual>,
774 template <
typename Key,
typename Value,
775 wet_kind_t Kind = detail::wet_kind<Key, Value>(),
776 typename Compare = std::less<Key>,
777 typename Hash = std::hash<Key>,
778 typename KeyEqual = std::equal_to<Key>>
780 Key, Value, Compare, Hash, KeyEqual>;
783 template <
typename Context,
784 wet_kind_t Kind = detail::wet_kind<labelset_t_of<Context>,
void set(const iterator &i, const value_t &v)
static constexpr wet_kind_t kind
auto find(Args &&...args) const -> const_iterator
welement< key_t, value_t > welement_t
typename map_t::const_iterator const_iterator
auto find(Args &&...args) -> iterator
const weight_t & weight() const
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
welement< typename std::remove_reference< label_t >::type, typename std::remove_reference< weight_t >::type > value_t
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
auto size(Args &&...args) const -> decltype(set_.size(std::forward< Args >(args)...))
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
const iterator_t & iterator() const
typename map_t::value_type value_type
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
iterator_impl(const iterator_impl< OtherValue, OtherIterator > &that)
Set set_t
Underlying "iterator".
Functor to compare Values of ValueSets.
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
auto cbegin() const -> const_iterator
static const key_t & key_of(const value_type &p)
auto cend() const -> const_iterator
auto erase(const_iterator pos) -> void
void for_each(Fun f) const
std::string type(const automaton &a)
The implementation type of a.
typename map_t::iterator iterator
Iterator iterator_t
Underlying iterator.
static const value_t & value_of(const value_type &p)
static constexpr wet_kind_t kind
detail::wet_impl< Kind, Key, Value, Compare, Hash, KeyEqual > wet
friend class boost::iterator_core_access
set_t & set()
FIXME: Avoid this by exposing more interfaces.
iterator_impl & operator=(const iterator_impl &that)
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
bool equal(const iterator_impl< OtherValue, OtherIterator > &that) const
auto operator<(const welement &that) const -> bool
welement_weight(const weight_t &w)
#define DEFINE(Name, Const)
auto find(key_t k) -> iterator
typename map_t::const_iterator const_iterator
iterator_impl(const iterator_t &it)
auto key_comp(Args &&...args) const -> decltype(map_.key_comp(std::forward< Args >(args)...))
void set(const iterator &i, const value_t &v)
void set(const key_t &k, const value_t &v)
const set_t & set() const
iterator_impl(set_t &set)
const set_t & set() const
wet_map(const std::initializer_list< value_type > &l)
welement< key_t, value_t > welement_t
welement_label(const label_t &l)
welement_weight(const weight_t &w)
This is useful to make hashes with labels or weights as keys without using non-default constructors; ...
std::set< Key, Compare > set_t
welement_t operator*() const
bool equal(const iterator_impl< OtherValue, OtherSet > &that) const
welement_label(const label_t &)
static const value_t & value_of(const value_type &p)
std::unordered_map< Key, Value, Hash, KeyEqual > map_t
set_t & set_
Underlying bitset.
std::map< Key, Value, Compare > map_t
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
void increment()
Advance to next position.
auto operator==(const welement &that) const -> bool
void set(const iterator &, const value_t &v)
void set(const key_t k, value_t v=true)
conditional_t< Kind==wet_kind_t::bitset, wet_bitset, conditional_t< Kind==wet_kind_t::set, wet_set< Key, Compare >, conditional_t< Kind==wet_kind_t::map, wet_map< Key, Value, Compare >, conditional_t< Kind==wet_kind_t::unordered_map, wet_unordered_map< Key, Value, Hash, KeyEqual >, void > > > > wet_impl
iterator_impl(set_t &set, size_t pos)
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
const iterator_t & iterator() const
void weight(const weight_t &w)
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
auto find(char k) -> iterator
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
auto find(key_t k) const -> const_iterator
void for_each(Fun f) const
wet_unordered_map(const std::initializer_list< value_type > &l)
typename map_t::iterator iterator
void set(const key_t &k, const value_t &v)
auto erase(const_iterator pos) -> iterator
boost::dynamic_bitset<> set_t
auto size(Args &&...args) const -> decltype(map_.size(std::forward< Args >(args)...))
wet_unordered_map()=default
auto empty(Args &&...args) const -> decltype(map_.empty(std::forward< Args >(args)...))
typename map_t::value_type value_type
void set(const char k, value_t v=true)
const label_t & label() const
auto emplace(Args &&...args) -> decltype(map_.emplace(std::forward< Args >(args)...))
auto cend() const -> const_iterator
constexpr wet_kind_t wet_kind()
auto find(Args &&...args) const -> decltype(map_.find(std::forward< Args >(args)...))
auto begin() const -> const_iterator
static constexpr wet_kind_t kind
void weight(const weight_t &k)
void set(const iterator &, const value_t v=true)
auto end(Args &&...args) const -> decltype(map_.end(std::forward< Args >(args)...))
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.
auto end() const -> const_iterator
welement(const label_t &l, const weight_t &w)
wet_bitset(const std::initializer_list< value_type > &p)
auto begin() const -> const_iterator
auto end() const -> const_iterator
void increment()
Advance to next position.
void weight_set(welement< Label, Weight > &m, const Weight &w)
static key_t key(char k)
Special for char: map -1 to 255 (MAX_UCHAR), not MAX_INT.
static constexpr wet_kind_t kind
auto cbegin() const -> const_iterator
static constexpr wet_kind_t kind
iterator_impl(const iterator_impl< OtherValue, OtherSet > &that)
auto clear(Args &&...args) -> decltype(set_.clear(std::forward< Args >(args)...))
typename map_t::mapped_type mapped_type
wet_set(const std::initializer_list< value_type > &p)
auto erase(Args &&...args) -> decltype(map_.erase(std::forward< Args >(args)...))
auto begin(Args &&...args) const -> decltype(map_.begin(std::forward< Args >(args)...))
void label(const label_t &l)
auto find(char k) const -> const_iterator
friend class boost::iterator_core_access
void set(const key_t &k, const value_t &v)
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
auto clear(Args &&...args) -> decltype(map_.clear(std::forward< Args >(args)...))
static const key_t & key_of(const value_type &p)
auto empty(Args &&...args) const -> decltype(set_.empty(std::forward< Args >(args)...))
welement_t operator*() const
typename std::conditional< B, T, U >::type conditional_t
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
static constexpr size_t npos