Main Page | Class Hierarchy | Class List | File List | Class Members

intervalTree.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
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