00001 #ifndef SPANNING_TREE_VERTEX
00002 #define SPANNING_TREE_VERTEX
00003
00004 namespace topo {
00005
00007 typedef int vtxType;
00008
00016 class SpanningTreeVertex
00017 {
00018 public:
00020 vtxType id;
00022
00024 std::vector<int> X;
00026 std::vector<int> childIndex;
00028 SpanningTreeVertex(const vtxType _id=-1): id(_id) {}
00029
00032 inline friend bool operator== (const SpanningTreeVertex &obj, const vtxType vtxID)
00033 { return (obj.id == vtxID); }
00034
00035 inline friend bool operator== (const vtxType vtxID, const SpanningTreeVertex &obj)
00036 { return (obj.id == vtxID); }
00037
00038 inline friend bool operator< (const SpanningTreeVertex &obj, const vtxType vtxID)
00039 { return (obj.id < vtxID); }
00040
00041 inline friend bool operator< (const vtxType vtxID, const SpanningTreeVertex &obj)
00042 { return (vtxID < obj.id); }
00044
00046 friend std::ostream& operator<< (std::ostream &out, const SpanningTreeVertex &obj)
00047 {
00048 out<<" "<<obj.id;
00049 if (obj.X.size()>0)
00050 {
00051 out<<"("<<obj.X[0];
00052 for (int i=1,cSize=obj.X.size(); i<cSize; i++)
00053 out<<","<<obj.X[i];
00054 out<<") ";
00055 }
00056 return out;
00057 }
00058 };
00059
00060 inline int getProcID(const vtxType vtx) { return vtx; }
00061 inline int getProcID(const SpanningTreeVertex &vtx) { return vtx.id; }
00062
00064 inline int numHops(const SpanningTreeVertex &vtx1, const SpanningTreeVertex &vtx2)
00065 {
00067
00068
00069 int nHops = 0;
00070 for (int i=0, nDims=vtx1.X.size(); i<nDims; i++)
00071 nHops += abs( vtx1.X[i] - vtx2.X[i] );
00072 return nHops;
00073 }
00074
00075
00076
00078 template <typename Iterator>
00079 inline Iterator pickClosest(const SpanningTreeVertex &parent, const Iterator start, const Iterator end)
00080 {
00082 Iterator itr = start;
00083 Iterator closest = itr++;
00084 int minHops = numHops(parent,*closest);
00086 for (; itr != end; itr++)
00087 {
00088 int hops = numHops(parent,*itr);
00089 if (hops < minHops)
00090 {
00091 closest = itr;
00092 minHops = hops;
00093 }
00094 }
00095 return closest;
00096 }
00097
00098 }
00099
00100 #endif // SPANNING_TREE_VERTEX
00101