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);
Set of graph edge or vertex pointers (iterators).
void insert(const SrcIterator &begin, const SrcIterator &end)
Insert multiple edges or vertices.
void insert(const Value &item)
Insert the specified edge or vertex if its ID doesn't exist in this set.
void clear()
Remove all edges or vertices from this set.
bool exists(const Value &item) const
Does the edge or vertex exist in this container?
Value popFront()
Removes and returns the least iterator.
bool isEmpty() const
True if container has no edges or vertices.
T Value
Type of values stored in this set.
GraphIteratorSet()
Default construct an empty set.
size_t size() const
Number of items stored in this set.
void insert(const GraphIteratorSet &other)
Insert multiple edges or vertices.
void erase(const Value &item) const
Remove the edge or vertex if it exists.
void updateIdNumbers()
Indicate that an update is necessary due to erasures.
boost::iterator_range< ConstIterator > values() const
Value iterator range.
StlVector::const_iterator ConstIterator
Iterates over values in this set.