8 #ifndef Sawyer_GraphIteratorSet_H
9 #define Sawyer_GraphIteratorSet_H
11 #include <Sawyer/Graph.h>
34 typedef std::vector<Value> StlVector;
35 mutable StlVector items_;
36 mutable bool needsUpdate_;
51 : needsUpdate_(false) {}
60 boost::iterator_range<ConstIterator>
values()
const {
62 return boost::iterator_range<ConstIterator>(items_.begin(), items_.end());
96 template<
class SrcIterator>
97 void insert(
const SrcIterator &begin,
const SrcIterator &end) {
99 for (SrcIterator i = begin; i != end; ++i)
106 typename std::vector<Value>::iterator lb = std::lower_bound(items_.begin(), items_.end(), item, sortById);
107 if (lb != items_.end() && (*lb)->id() == item->id())
115 Value retval = items_[0];
116 items_.erase(items_.begin());
123 needsUpdate_ =
false;
133 typename std::vector<Value>::iterator lb = std::lower_bound(items_.begin(), items_.end(), item, sortById);
134 return lb != items_.end() && (*lb)->id() == item->id();
139 return items_.empty();
141 bool empty()
const {
return isEmpty(); }
145 return items_.size();
152 static bool sortById(
const Value &a,
const Value &b) {
153 return a->id() < b->id();
156 void update()
const {
158 std::sort(items_.begin(), items_.end(), sortById);
159 needsUpdate_ =
false;
166 for (
size_t i = 1; i < items_.size(); ++i)
167 ASSERT_require(sortById(items_[i-1], items_[i]));
170 void insertUnique(
const Value &item) {
171 typename std::vector<Value>::iterator lb = std::lower_bound(items_.begin(), items_.end(), item, sortById);
172 if (lb == items_.end() || (*lb)->id() != item->id())
173 items_.insert(lb, item);