Bentley-Otmann Algorithm 2.0
An implementation of Bentley-Ottmann algorithm in order to count the m,n-cubes
|
00001 00016 #ifndef H_BST 00017 #define H_BST 00018 00019 #include <set> 00020 #include <vector> 00021 #include <map> 00022 00034 template <class T, class Comp> struct compare { 00035 Comp* comp; 00043 compare(Comp* c) : comp(c) { }; 00044 00052 bool operator() (T* a, T* b) { 00053 return a->less(*b,*comp); 00054 } 00055 }; 00056 00070 template <class T, class Comp> struct BST { 00071 typedef std::set <T*, compare<T,Comp> > Type; 00072 }; 00073 00074 00086 template <class T, class A> struct PriorityQueue_t { 00087 typedef std::map<T, std::vector<A> > Type; 00088 }; 00089 00090 00100 template <class T, class A> class PriorityQueue : public PriorityQueue_t<T,A>::Type { 00101 public: 00108 void push(const T& value) { 00109 std::vector<A> v; //empty vector 00110 this->insert(std::pair<T, std::vector<A> > (value, v)); 00111 } 00112 00122 void push(const T& value, const A& assoc) { 00123 std::vector<A> v; v.push_back(assoc); 00124 std::pair<typename PriorityQueue_t<T,A>::Type::iterator, bool> ret = 00125 this->insert(std::pair<T, std::vector<A> > (value, v)); 00126 if(false == ret.second) 00127 ret.first->second.push_back(assoc); 00128 return; 00129 } 00130 00137 T top() { 00138 return this->begin()->first; 00139 } 00140 00145 void pop() { 00146 this->erase(this->begin()); 00147 } 00148 00157 bool mem(const T& value) { 00158 return (this->find(value) != this->end()); 00159 } 00160 }; 00161 00162 #endif //H_BST