| 1 | #include <iostream> |
| 2 | |
| 3 | // Nathan Hurst and Emin Martinian, licenced LGPL and MPL with permission |
| 4 | |
| 5 | |
| 6 | #include "interval_tree.h" |
| 7 | |
| 8 | class SimpleInterval : public Interval { |
| 9 | public: |
| 10 | SimpleInterval() : |
| 11 | _low(0), |
| 12 | _high(0), |
| 13 | _node(NULL) |
| 14 | {} |
| 15 | SimpleInterval(const int low,const int high) |
| 16 | :_low(low), |
| 17 | _high(high), |
| 18 | _node(NULL) |
| 19 | { } |
| 20 | |
| 21 | int GetLowPoint() const { return _low;} |
| 22 | int GetHighPoint() const { return _high;} |
| 23 | IntervalTreeNode * GetNode() { return _node;} |
| 24 | void SetNode(IntervalTreeNode * node) {_node = node;} |
| 25 | virtual void Print() const { |
| 26 | printf("(%d, %d)", _low, _high); |
| 27 | } |
| 28 | protected: |
| 29 | int _low; |
| 30 | int _high; |
| 31 | IntervalTreeNode * _node; |
| 32 | |
| 33 | }; |
| 34 | |
| 35 | using namespace std; |
| 36 | |
| 37 | #include <stdlib.h> |
| 38 | #include <time.h> |
| 39 | |
| 40 | int main() { |
| 41 | const int N = 1L<<24; |
| 42 | SimpleInterval *x = new SimpleInterval[N]; |
| 43 | for(int i = 0; i < N; i++) { |
| 44 | x[i] = SimpleInterval(random(), random()); |
| 45 | } |
| 46 | |
| 47 | cout << "sizeof(SimpleInterval)" << sizeof(SimpleInterval) << endl; |
| 48 | cout << "sizeof(IntervalTreeNode)" << sizeof(IntervalTreeNode) << endl; |
| 49 | cout << "sizeof(it_recursion_node)" << sizeof(it_recursion_node) << endl; |
| 50 | cout << "sizeof(IntervalTree)" << sizeof(IntervalTree) << endl; |
| 51 | |
| 52 | IntervalTree itree; |
| 53 | int onn = 0; |
| 54 | for(int nn = 1; nn < N; nn*=2) { |
| 55 | for(int i = onn; i < nn; i++) { |
| 56 | itree.Insert(&x[i]); |
| 57 | } |
| 58 | onn = nn; |
| 59 | clock_t s = clock(); |
| 60 | |
| 61 | int iters = 0; |
| 62 | int outputs = 0; |
| 63 | while(clock() - s < CLOCKS_PER_SEC/4) { |
| 64 | vector<void *> n = itree.Enumerate(random(), random()) ; |
| 65 | outputs += n.size(); |
| 66 | //cout << n.size() << endl; |
| 67 | iters++; |
| 68 | } |
| 69 | clock_t e = clock(); |
| 70 | double total = double(e - s)/(CLOCKS_PER_SEC); |
| 71 | cout << total << " " << outputs << " " << total/outputs << " " << nn << endl; |
| 72 | } |
| 73 | //itree.Print(); |
| 74 | } |