ROSE 0.11.145.147
Sawyer/Map.h
1// WARNING: Changes to this file must be contributed back to Sawyer or else they will
2// be clobbered by the next update from Sawyer. The Sawyer repository is at
3// https://gitlab.com/charger7534/sawyer.git.
4
5
6
7
8#ifndef Sawyer_Map_H
9#define Sawyer_Map_H
10
11#include <Sawyer/Interval.h>
12#include <Sawyer/Optional.h>
13#include <Sawyer/Sawyer.h>
14#include <boost/range/iterator_range.hpp>
15
16#ifdef SAWYER_HAVE_BOOST_SERIALIZATION
17#include <boost/serialization/map.hpp>
18#endif
19
20#ifdef SAWYER_HAVE_CEREAL
21#include <cereal/types/map.hpp>
22#endif
23
24#include <stdexcept>
25
26namespace Sawyer {
27
53namespace Container {
54
68template<class K,
69 class T,
70 class Cmp = std::less<K>,
71 class Alloc = std::allocator<std::pair<const K, T> > >
72class Map {
73public:
74 typedef K Key;
75 typedef T Value;
76 typedef Cmp Comparator;
77 typedef Alloc Allocator;
79private:
80 typedef std::map<Key, Value, Comparator, Alloc> StlMap;
81 StlMap map_;
82
83#ifdef SAWYER_HAVE_BOOST_SERIALIZATION
84private:
85 friend class boost::serialization::access;
86
87 template<class S>
88 void serialize(S &s, const unsigned /*version*/) {
89 s & BOOST_SERIALIZATION_NVP(map_);
90 }
91#endif
92
93#ifdef SAWYER_HAVE_CEREAL
94private:
95 friend class cereal::access;
96
97 template<class Archive>
98 void CEREAL_SERIALIZE_FUNCTION_NAME(Archive &archive) {
99 archive(CEREAL_NVP(map_));
100 }
101#endif
102
103public:
107 class Node: private std::pair<const Key, Value> {
108 // This class MUST BE binary compatible with its super class (see NodeIterator::operator* below)
109 public:
110 explicit Node(const std::pair<const Key, Value> &pair): std::pair<const Key, Value>(pair) {}
111 Node(const Key &key, Value &value): std::pair<const Key, Value>(key, value) {}
112 public:
116 const Key& key() const { return this->first; }
117
123 Value& value() { return this->second; }
124 const Value& value() const { return this->second; }
126 };
127
129 // Iterators
131private:
132 template<class Derived, class Value, class BaseIterator>
133 class BidirectionalIterator {
134
135 public:
136 // Five standard iterator types
137 using iterator_category = std::bidirectional_iterator_tag;
138 using value_type = Value;
139 using difference_type = std::ptrdiff_t;
140 using pointer = Value*;
141 using reference = Value&;
142
143 protected:
144 BaseIterator base_;
145 BidirectionalIterator() {}
146 BidirectionalIterator(const BaseIterator &base): base_(base) {}
147 BidirectionalIterator(const BidirectionalIterator &other): base_(other.base_) {}
148
149 public:
150 Derived& operator=(const Derived &other) { base_ = other.base(); return *derived(); }
151 BidirectionalIterator& operator=(const BidirectionalIterator &other) { base_ = other.base(); return *this; }
152
154 Derived& operator++() { ++base_; return *derived(); }
155
157 Derived operator++(int) { Derived old=*derived(); ++*this; return old; }
158
160 Derived& operator--() { --base_; return *derived(); }
161
163 Derived operator--(int) { Derived old=*derived(); --*this; return old; }
164
169 template<class OtherIter> bool operator==(const OtherIter &other) const { return base_ == other.base(); }
170
174 template<class OtherIter> bool operator!=(const OtherIter &other) const { return base_ != other.base(); }
175
176 const BaseIterator& base() const { return base_; }
177 protected:
178 Derived* derived() { return static_cast<Derived*>(this); }
179 const Derived* derived() const { return static_cast<const Derived*>(this); }
180 };
181
182public:
187 class NodeIterator: public BidirectionalIterator<NodeIterator, Node, typename StlMap::iterator> {
188 typedef BidirectionalIterator<NodeIterator, Node, typename StlMap::iterator> Super;
189 public:
190 NodeIterator() {}
191
193 NodeIterator(const NodeIterator &other): Super(other) {}
194
196 NodeIterator& operator=(const NodeIterator &other) { this->Super::operator=(other); return *this; }
197
198 // std::map stores std::pair nodes, but we want to return Node, which must have the same layout.
200 Node& operator*() const { return *(Node*)&*this->base_; }
201
203 Node* operator->() const { return (Node*)&*this->base_; }
204 private:
205 friend class Map;
206 NodeIterator(const typename StlMap::iterator &base): Super(base) {}
207 };
208
213 class ConstNodeIterator: public BidirectionalIterator<ConstNodeIterator, const Node, typename StlMap::const_iterator> {
214 typedef BidirectionalIterator<ConstNodeIterator, const Node, typename StlMap::const_iterator> Super;
215 public:
217
219 ConstNodeIterator(const ConstNodeIterator &other): Super(other) {}
220
222 ConstNodeIterator(const NodeIterator &other): Super(typename StlMap::const_iterator(other.base())) {}
223
225 ConstNodeIterator& operator=(const ConstNodeIterator &other) { this->Super::operator=(other); return *this; }
226
227 // std::map stores std::pair nodes, but we want to return Node, which must have the same layout.
229 const Node& operator*() const { return *(const Node*)&*this->base_; }
230
232 const Node* operator->() const { return (const Node*)&*this->base_; }
233 private:
234 friend class Map;
235 ConstNodeIterator(const typename StlMap::const_iterator &base): Super(base) {}
236 ConstNodeIterator(const typename StlMap::iterator &base): Super(typename StlMap::const_iterator(base)) {}
237 };
238
243 class ConstKeyIterator: public BidirectionalIterator<ConstKeyIterator, const Key, typename StlMap::const_iterator> {
244 typedef BidirectionalIterator<ConstKeyIterator, const Key, typename StlMap::const_iterator> Super;
245 public:
247
249 ConstKeyIterator(const ConstKeyIterator &other): Super(other) {}
250
252 ConstKeyIterator(const NodeIterator &other): Super(typename StlMap::const_iterator(other.base())) {}
253
255 ConstKeyIterator(const ConstNodeIterator &other): Super(other.base()) {}
256
258 ConstKeyIterator& operator=(const ConstKeyIterator &other) { this->Super::operator=(other); return *this; }
259
261 const Key& operator*() const { return this->base()->first; }
262
264 const Key* operator->() const { return &this->base()->first; }
265 };
266
271 class ValueIterator: public BidirectionalIterator<ValueIterator, Value, typename StlMap::iterator> {
272 typedef BidirectionalIterator<ValueIterator, Value, typename StlMap::iterator> Super;
273 public:
274 ValueIterator() {}
275
277 ValueIterator(const ValueIterator &other): Super(other) {}
278
280 ValueIterator(const NodeIterator &other): Super(other.base()) {}
281
283 ValueIterator& operator=(const ValueIterator &other) { this->Super::operator=(other); return *this; }
284
286 Value& operator*() const { return this->base()->second; }
287
289 Value* operator->() const { return &this->base()->second; }
290 };
291
296 class ConstValueIterator: public BidirectionalIterator<ConstValueIterator, const Value, typename StlMap::const_iterator> {
297 typedef BidirectionalIterator<ConstValueIterator, const Value, typename StlMap::const_iterator> Super;
298 public:
300
302 ConstValueIterator(const ConstValueIterator &other): Super(other) {}
303
305 ConstValueIterator(const ValueIterator &other): Super(typename StlMap::const_iterator(other.base())) {}
306
308 ConstValueIterator(const ConstNodeIterator &other): Super(other.base()) {}
309
311 ConstValueIterator(const NodeIterator &other): Super(typename StlMap::const_iterator(other.base())) {}
312
314 ConstValueIterator& operator=(const ConstValueIterator &other) { this->Super::operator=(other); return *this; }
315
317 const Value& operator*() const { return this->base()->second; }
318
320 const Value* operator->() const { return &this->base()->second; }
321 };
322
323
325 // Constructors
327public:
328
332 Map() {}
333
337 explicit Map(const Comparator &comparator, const Allocator &allocator = Allocator())
338 : map_(comparator, allocator) {}
339
341 Map(const Map& other) {
342 map_ = other.map_;
343 }
344
349 template<class Key2, class T2, class Cmp2, class Alloc2>
351 typedef typename Map<Key2, T2, Cmp2, Alloc2>::ConstNodeIterator OtherIterator;
352 boost::iterator_range<OtherIterator> otherNodes = other.nodes();
353 for (OtherIterator otherIter=otherNodes.begin(); otherIter!=otherNodes.end(); ++otherIter)
354 map_.insert(map_.end(), std::make_pair(Key(otherIter->key()), Value(otherIter->value())));
355 }
356
357 Map& operator=(const Map &other) {
358 clear();
359 for (const auto &node: other.nodes())
360 map_.insert(map_.end(), std::make_pair(node.key(), node.value()));
361 return *this;
362 }
363
367 template<class Key2, class T2, class Cmp2, class Alloc2>
369 typedef typename Map<Key2, T2, Cmp2, Alloc2>::ConstNodeIterator OtherIterator;
370 clear();
371 boost::iterator_range<OtherIterator> otherNodes = other.nodes();
372 for (OtherIterator otherIter=otherNodes.begin(); otherIter!=otherNodes.end(); ++otherIter)
373 map_.insert(map_.end(), std::make_pair(Key(otherIter->key()), Value(otherIter->value())));
374 return *this;
375 }
376
377
379 // Iteration
381public:
387 boost::iterator_range<NodeIterator> nodes() {
388 return boost::iterator_range<NodeIterator>(NodeIterator(map_.begin()), NodeIterator(map_.end()));
389 }
390 boost::iterator_range<ConstNodeIterator> nodes() const {
391 return boost::iterator_range<ConstNodeIterator>(ConstNodeIterator(map_.begin()), ConstNodeIterator(map_.end()));
392 }
400 boost::iterator_range<ConstKeyIterator> keys() {
401 return boost::iterator_range<ConstKeyIterator>(NodeIterator(map_.begin()), NodeIterator(map_.end()));
402 }
403 boost::iterator_range<ConstKeyIterator> keys() const {
404 return boost::iterator_range<ConstKeyIterator>(ConstNodeIterator(map_.begin()), ConstNodeIterator(map_.end()));
405 }
414 boost::iterator_range<ValueIterator> values() {
415 return boost::iterator_range<ValueIterator>(NodeIterator(map_.begin()), NodeIterator(map_.end()));
416 }
417 boost::iterator_range<ConstValueIterator> values() const {
418 return boost::iterator_range<ConstValueIterator>(ConstNodeIterator(map_.begin()), ConstNodeIterator(map_.end()));
419 }
424 // Size and capacity
426public:
427
431 bool isEmpty() const {
432 return map_.empty();
433 }
434
438 size_t size() const {
439 return map_.size();
440 }
441
443 Key least() const {
444 ASSERT_forbid(isEmpty());
445 return map_.begin()->first;
446 }
447
449 Key greatest() const {
450 ASSERT_forbid(isEmpty());
451 typename StlMap::const_iterator last = map_.end();
452 --last;
453 return last->first;
454 }
455
465 }
466
467
469 // Searching
471public:
472
480 NodeIterator find(const Key &key) {
481 return map_.find(key);
482 }
483 ConstNodeIterator find(const Key &key) const {
484 return map_.find(key);
485 }
493 bool exists(const Key &key) const {
494 return map_.find(key)!=map_.end();
495 }
496
507 return map_.lower_bound(key);
508 }
509 ConstNodeIterator lowerBound(const Key &key) const {
510 return map_.lower_bound(key);
511 }
524 return map_.upper_bound(key);
525 }
526 ConstNodeIterator upperBound(const Key &key) const {
527 return map_.upper_bound(key);
528 }
533 // Accessors
535public:
536
549 Value& operator[](const Key &key) {
550 return get(key);
551 }
552 const Value& operator[](const Key &key) const {
553 return get(key);
554 }
565 Value& get(const Key &key) {
566 typename StlMap::iterator found = map_.find(key);
567 if (found==map_.end())
568 throw std::domain_error("key lookup failure; key is not in map domain");
569 return found->second;
570 }
571 const Value& get(const Key &key) const {
572 typename StlMap::const_iterator found = map_.find(key);
573 if (found==map_.end())
574 throw std::domain_error("key lookup failure; key is not in map domain");
575 return found->second;
576 }
602 Optional<Value> getOptional(const Key &key) const {
603 typename StlMap::const_iterator found = map_.find(key);
604 return found == map_.end() ? Optional<Value>() : Optional<Value>(found->second);
605 }
606
614 Value& getOrElse(const Key &key, Value &dflt) {
615 typename StlMap::iterator found = map_.find(key);
616 return found == map_.end() ? dflt : found->second;
617 }
618 const Value& getOrElse(const Key &key, const Value &dflt) const {
619 typename StlMap::const_iterator found = map_.find(key);
620 return found == map_.end() ? dflt : found->second;
621 }
629 const Value& getOrDefault(const Key &key) const {
630 static const Value dflt;
631 typename StlMap::const_iterator found = map_.find(key);
632 return found==map_.end() ? dflt : found->second;
633 }
634
636 // Mutators
638public:
639
646 Map& insert(const Key &key, const Value &value) {
647 std::pair<typename StlMap::iterator, bool> inserted = map_.insert(std::make_pair(key, value));
648 if (!inserted.second)
649 inserted.first->second = value;
650 return *this;
651 }
652
659 Map& insertDefault(const Key &key) {
660 map_[key] = T();
661 return *this;
662 }
663
681 template<class OtherNodeIterator>
682 Map& insertMultiple(const OtherNodeIterator &begin, const OtherNodeIterator &end) {
683 for (OtherNodeIterator otherIter=begin; otherIter!=end; ++otherIter)
684 insert(Key(otherIter->key()), Value(otherIter->value()));
685 return *this;
686 }
687 template<class OtherNodeIterator>
688 Map& insertMultiple(const boost::iterator_range<OtherNodeIterator> &range) {
689 return insertMultiple(range.begin(), range.end());
690 }
700 Value& insertMaybe(const Key &key, const Value &value) {
701 return map_.insert(std::make_pair(key, value)).first->second;
702 }
703
712 return map_.insert(std::make_pair(key, T())).first->second;
713 }
714
721 template<class OtherNodeIterator>
722 Map& insertMaybeMultiple(const boost::iterator_range<OtherNodeIterator> &range) {
723 for (OtherNodeIterator otherIter=range.begin(); otherIter!=range.end(); ++otherIter)
724 insertMaybe(Key(otherIter->key()), Value(otherIter->value()));
725 return *this;
726 }
727
733 map_.clear();
734 return *this;
735 }
736
744 Map& erase(const Key &key) {
745 map_.erase(key);
746 return *this;
747 }
748
757 template<class OtherKeyIterator>
758 Map& eraseMultiple(const boost::iterator_range<OtherKeyIterator> &range) {
759 for (OtherKeyIterator otherIter=range.begin(); otherIter!=range.end(); ++otherIter)
760 map_.erase(Key(*otherIter));
761 return *this;
762 }
763
771 Map& eraseAt(const NodeIterator &iter) {
772 map_.erase(iter.base());
773 return *this;
774 }
776 // std::map can't erase using a const_iterator
777 ASSERT_require(iter != keys().end());
778 typename StlMap::iterator stdIter = map_.find(*iter);
779 ASSERT_require(stdIter != map_.end());
780 map_.erase(stdIter);
781 return *this;
782 }
783 Map& eraseAt(const ValueIterator &iter) {
784 map_.erase(iter.base());
785 return *this;
786 }
796 template<class Iter>
797 Map& eraseAtMultiple(const Iter &begin, const Iter &end) {
798 map_.erase(begin.base(), end.base());
799 return *this;
800 }
801 template<class Iter>
802 Map& eraseAtMultiple(const boost::iterator_range<Iter> &range) {
803 map_.erase(range.begin().base(), range.end().base());
804 return *this;
805 }
808};
809
810} // namespace
811} // namespace
812
813#endif
Range of values delimited by endpoints.
Definition Interval.h:31
static Interval hull(T v1, T v2)
Construct an interval from two endpoints.
Definition Interval.h:162
Bidirectional iterator over keys.
Definition Sawyer/Map.h:243
ConstKeyIterator(const ConstNodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:255
ConstKeyIterator(const NodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:252
const Key * operator->() const
Returns a pointer to the interval of the storage node.
Definition Sawyer/Map.h:264
ConstKeyIterator(const ConstKeyIterator &other)
Copy constructor.
Definition Sawyer/Map.h:249
ConstKeyIterator & operator=(const ConstKeyIterator &other)
Assignment.
Definition Sawyer/Map.h:258
const Key & operator*() const
Dereference iterator to return the interval of the storage node.
Definition Sawyer/Map.h:261
Bidirectional iterator over key/value nodes.
Definition Sawyer/Map.h:213
const Node & operator*() const
Dereference iterator to return a storage node.
Definition Sawyer/Map.h:229
ConstNodeIterator(const NodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:222
const Node * operator->() const
Returns a pointer to a storage node.
Definition Sawyer/Map.h:232
ConstNodeIterator & operator=(const ConstNodeIterator &other)
Assignment.
Definition Sawyer/Map.h:225
ConstNodeIterator(const ConstNodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:219
Bidirectional iterator over values.
Definition Sawyer/Map.h:296
ConstValueIterator(const ConstValueIterator &other)
Copy constructor.
Definition Sawyer/Map.h:302
ConstValueIterator(const ConstNodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:308
ConstValueIterator & operator=(const ConstValueIterator &other)
Assignment.
Definition Sawyer/Map.h:314
ConstValueIterator(const ValueIterator &other)
Copy constructor.
Definition Sawyer/Map.h:305
const Value & operator*() const
Dereference iterator to return the value of the storage node.
Definition Sawyer/Map.h:317
ConstValueIterator(const NodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:311
const Value * operator->() const
Returns a pointer to the value of the storage node.
Definition Sawyer/Map.h:320
Bidirectional iterator over key/value nodes.
Definition Sawyer/Map.h:187
NodeIterator(const NodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:193
NodeIterator & operator=(const NodeIterator &other)
Assignment.
Definition Sawyer/Map.h:196
Node * operator->() const
Returns a pointer to a storage node.
Definition Sawyer/Map.h:203
Node & operator*() const
Dereference iterator to return a storage node.
Definition Sawyer/Map.h:200
Type for stored nodes.
Definition Sawyer/Map.h:107
const Key & key() const
Key part of key/value node.
Definition Sawyer/Map.h:116
const Value & value() const
Value part of key/value node.
Definition Sawyer/Map.h:124
Value & value()
Value part of key/value node.
Definition Sawyer/Map.h:123
Bidirectional iterator over values.
Definition Sawyer/Map.h:271
ValueIterator(const ValueIterator &other)
Copy constructor.
Definition Sawyer/Map.h:277
Value & operator*() const
Dereference iterator to return the value of the storage node.
Definition Sawyer/Map.h:286
ValueIterator & operator=(const ValueIterator &other)
Assignment.
Definition Sawyer/Map.h:283
ValueIterator(const NodeIterator &other)
Copy constructor.
Definition Sawyer/Map.h:280
Value * operator->() const
Returns a pointer to the value of the storage node.
Definition Sawyer/Map.h:289
Container associating values with keys.
Definition Sawyer/Map.h:72
NodeIterator upperBound(const Key &key)
Find a node close to a key.
Definition Sawyer/Map.h:523
Map & insertDefault(const Key &key)
Insert or update a key with a default value.
Definition Sawyer/Map.h:659
NodeIterator find(const Key &key)
Find a node by key.
Definition Sawyer/Map.h:480
const Value & get(const Key &key) const
Lookup and return an existing value.
Definition Sawyer/Map.h:571
Map & eraseAt(const NodeIterator &iter)
Remove a node by iterator.
Definition Sawyer/Map.h:771
Map & eraseAtMultiple(const boost::iterator_range< Iter > &range)
Remove multiple nodes by iterator range.
Definition Sawyer/Map.h:802
boost::iterator_range< ConstNodeIterator > nodes() const
Iterators for container nodes.
Definition Sawyer/Map.h:390
Map & eraseAt(const ValueIterator &iter)
Remove a node by iterator.
Definition Sawyer/Map.h:783
boost::iterator_range< ConstKeyIterator > keys() const
Iterators for container keys.
Definition Sawyer/Map.h:403
Value & operator[](const Key &key)
Return a reference to an existing value.
Definition Sawyer/Map.h:549
bool exists(const Key &key) const
Determine if a key exists.
Definition Sawyer/Map.h:493
Map & eraseMultiple(const boost::iterator_range< OtherKeyIterator > &range)
Remove keys stored in another Map.
Definition Sawyer/Map.h:758
Map & insertMaybeMultiple(const boost::iterator_range< OtherNodeIterator > &range)
Conditionally insert multiple key/value pairs.
Definition Sawyer/Map.h:722
K Key
Type for keys.
Definition Sawyer/Map.h:74
Key greatest() const
Returns the maximum key.
Definition Sawyer/Map.h:449
const Value & operator[](const Key &key) const
Return a reference to an existing value.
Definition Sawyer/Map.h:552
Map & operator=(const Map< Key2, T2, Cmp2, Alloc2 > &other)
Make this map be a copy of another map.
Definition Sawyer/Map.h:368
boost::iterator_range< ValueIterator > values()
Iterators for container values.
Definition Sawyer/Map.h:414
Map(const Map &other)
Copy constructor.
Definition Sawyer/Map.h:341
Map & insertMultiple(const boost::iterator_range< OtherNodeIterator > &range)
Insert multiple values.
Definition Sawyer/Map.h:688
ConstNodeIterator find(const Key &key) const
Find a node by key.
Definition Sawyer/Map.h:483
size_t size() const
Number of nodes, keys, or values in this container.
Definition Sawyer/Map.h:438
Cmp Comparator
Type of comparator, third template argument.
Definition Sawyer/Map.h:76
Value & get(const Key &key)
Lookup and return an existing value.
Definition Sawyer/Map.h:565
bool isEmpty() const
Determines whether this container is empty.
Definition Sawyer/Map.h:431
Optional< Value > getOptional(const Key &key) const
Lookup and return a value or nothing.
Definition Sawyer/Map.h:602
Alloc Allocator
Type of allocator, fourth template argument.
Definition Sawyer/Map.h:77
Map & erase(const Key &key)
Remove a node with specified key.
Definition Sawyer/Map.h:744
const Value & getOrElse(const Key &key, const Value &dflt) const
Lookup and return a value or something else.
Definition Sawyer/Map.h:618
NodeIterator lowerBound(const Key &key)
Find a node close to a key.
Definition Sawyer/Map.h:506
Value & insertMaybeDefault(const Key &key)
Conditionally insert a new key with default value.
Definition Sawyer/Map.h:711
ConstNodeIterator lowerBound(const Key &key) const
Find a node close to a key.
Definition Sawyer/Map.h:509
boost::iterator_range< NodeIterator > nodes()
Iterators for container nodes.
Definition Sawyer/Map.h:387
Map & eraseAtMultiple(const Iter &begin, const Iter &end)
Remove multiple nodes by iterator range.
Definition Sawyer/Map.h:797
Value & insertMaybe(const Key &key, const Value &value)
Conditionally insert a new key/value pair.
Definition Sawyer/Map.h:700
Map(const Map< Key2, T2, Cmp2, Alloc2 > &other)
Copy constructor.
Definition Sawyer/Map.h:350
boost::iterator_range< ConstKeyIterator > keys()
Iterators for container keys.
Definition Sawyer/Map.h:400
Map & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
Definition Sawyer/Map.h:646
ConstNodeIterator upperBound(const Key &key) const
Find a node close to a key.
Definition Sawyer/Map.h:526
Map & clear()
Remove all nodes.
Definition Sawyer/Map.h:732
Value & getOrElse(const Key &key, Value &dflt)
Lookup and return a value or something else.
Definition Sawyer/Map.h:614
Map & insertMultiple(const OtherNodeIterator &begin, const OtherNodeIterator &end)
Insert multiple values.
Definition Sawyer/Map.h:682
Map(const Comparator &comparator, const Allocator &allocator=Allocator())
Constructs an empty map.
Definition Sawyer/Map.h:337
const Value & getOrDefault(const Key &key) const
Lookup and return a value or a default.
Definition Sawyer/Map.h:629
Key least() const
Returns the minimum key.
Definition Sawyer/Map.h:443
T Value
Type for values associated with each key.
Definition Sawyer/Map.h:75
Interval< Key > hull() const
Returns the range of keys in this map.
Definition Sawyer/Map.h:463
Map()
Default constructor.
Definition Sawyer/Map.h:332
boost::iterator_range< ConstValueIterator > values() const
Iterators for container values.
Definition Sawyer/Map.h:417
Map & eraseAt(const ConstKeyIterator &iter)
Remove a node by iterator.
Definition Sawyer/Map.h:775
Holds a value or nothing.
Definition Optional.h:56
Sawyer support library.