00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined(INTERVAL_TREE_H)
00025 #define INTERVAL_TREE_H
00026 #include <stdio.h>
00027 #include <vector>
00028 #include <list>
00029 #include <set>
00030 #include "rectangle.h"
00031
00032 class IntervalTree
00033 {
00034 public:
00035 IntervalTree( );
00036 ~IntervalTree( );
00037
00038 static IntervalTree *MakeIntervalTree( const OneDimension& );
00039 bool DeleteInterval( const int&, const Interval& );
00040 bool WindowQuery( const Interval&, KeySet& keys );
00041
00042 void Display( FILE *fp );
00043
00044 private:
00045 struct Secondary {
00046 double value;
00047 bool open;
00048 int key;
00049 Secondary *next;
00050 };
00051 struct IntervalTreeNode {
00052 IntervalTreeNode(){
00053 nodeValue = max = min = 0;
00054 LS = RS = NULL;
00055 LT = RT = -1;
00056 active = false;
00057 activeDesc = false;
00058 closestActive = -1;
00059 }
00060 double nodeValue, max, min;
00061 bool active, activeDesc;
00062 int closestActive, LT, RT;
00063 Secondary *LS, *RS;
00064 };
00065
00066 IntervalTreeNode *nodes;
00067 int size;
00068 int rootT;
00069
00070 static bool InsertInLeftSecondary(Secondary *&, const int &, double, bool);
00071 static bool InsertInRightSecondary(Secondary *&, const int &, double, bool);
00072 static bool DeleteFromSecondary(Secondary*&, const int &, double, bool );
00073 void VisitActive( int, KeySet& );
00074 };
00075
00076 #endif