*/
#define VMASK (YMASK|XMASK)
-#define ESHIFT (YBITS|XBITS)
+#define ESHIFT (YBITS+XBITS)
class Graph { }; // this is a dummy as our graph has no actual representation
using namespace boost;
/*
- * We use the following alternative numbering for iterating over edges:
+ * We iterate over edges in the following order:
*
- * ix: \0 /1
- * \ /
- * ___ 0 __
- * 2 1 3
- * / \
- * 4/ 5\
+ * \#0 /1#
+ * \ /
+ * ___ 0 __
+ * #2 1 #3
+ * / \
+ * #4/ #5\ and finally #6 is V6
*
*
- * This numbering permits the order-4 nodes at the strip's edge
- * to have a contiguous edge iterator values 2..5 or 0..3.
+ * This ordering permits the order-4 nodes at the strip's edge
+ * to have a contiguous edge iterator values. The iterator
+ * starts at #0 which is edge 2 (see mgraph.h), or #2 (edge 3).
*/
-static const int oee_edgemap[V6]=
- { 2<<ESHIFT, 1<<ESHIFT, 3<<ESHIFT, 2<<ESHIFT, 4<<ESHIFT, 5<<ESHIFT };
+static const int oei_edge_delta[V6]=
+ /* 0 1 2 3 4 5 initial e
+ * #3 #1 #0 #2 #4 #5 initial ix
+ * #4 #2 #1 #3 #5 #6 next ix
+ * 4 3 1 0 5 V6 next e
+ */ {
+ 4<<ESHIFT, 2<<ESHIFT, -1<<ESHIFT,
+ -3<<ESHIFT, 1<<ESHIFT, (V6-5)<<ESHIFT
+};
class OutEdgeIterator :
public iterator_facade<
int const,
forward_traversal_tag
> {
- int v, ix, f;
-
- void setf() { f= v | oee_edgemap[ix]; }
+ int f;
public:
- void increment() { ix++; setf(); }
- bool equal(OutEdgeIterator const& other) const { return ix == other.ix; }
+ void increment() {
+ //printf("incrementing f=%03x..",f);
+ f += oei_edge_delta[f>>ESHIFT];
+ //printf("%03x\n",f);
+ }
+ bool equal(OutEdgeIterator const& other) const { return f == other.f; }
int const& dereference() const { return f; }
OutEdgeIterator() { }
- OutEdgeIterator(int _v, int _ix) : v(_v), ix(_ix) { setf(); }
+ OutEdgeIterator(int _f) : f(_f) { }
+ OutEdgeIterator(int v, int e) : f(e<<ESHIFT | v) {
+ //printf("constructed v=%x e=%x f=%03x\n",v,e,f);
+ }
- static int voe_min(int _v) { return _v & YMASK ? 0 : 2; }
- static int voe_max(int _v) { return ~_v & YMASK ? V6 : 4; }
+ static int voe_min(int _v) { return (_v & YMASK) ? 2 : 3; }
+ static int voe_max(int _v) { return (~_v & YMASK) ? V6 : 4; }
+ static int voe_degree(int _v) { return (_v & YMASK | ~_v & YMASK) ? 4 : V6; }
};
typedef counting_iterator<int> VertexIterator;
OutEdgeIterator(v, OutEdgeIterator::voe_max(v)));
}
inline unsigned out_degree(int v, const Graph&) {
- return OutEdgeIterator::voe_max(v) - OutEdgeIterator::voe_min(v);
+ return OutEdgeIterator::voe_degree(v);
}
// Concept VertexListGraph: