ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Tree-M/MT/MTentry.h
Revision: 1.3
Committed: Fri Jul 27 12:48:23 2001 UTC (22 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /*********************************************************************
2     * *
3     * Copyright (c) 1997,1998, 1999 *
4     * Multimedia DB Group and DEIS - CSITE-CNR, *
5     * University of Bologna, Bologna, ITALY. *
6     * *
7     * All Rights Reserved. *
8     * *
9     * Permission to use, copy, and distribute this software and its *
10     * documentation for NON-COMMERCIAL purposes and without fee is *
11     * hereby granted provided that this copyright notice appears in *
12     * all copies. *
13     * *
14     * THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE *
15     * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING *
16     * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, *
17     * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR *
18     * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A *
19     * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS *
20     * DERIVATIVES. *
21     * *
22     *********************************************************************/
23    
24     #ifndef MTENTRY_H
25     #define MTENTRY_H
26    
27     #include <string.h>
28     #include <stdio.h>
29 root 1.2 #include <float.h>
30 root 1.1 #ifndef MAXDOUBLE
31     #define MAXDOUBLE DBL_MAX
32     #endif
33     #include "GiST.h"
34     #include "MTobject.h"
35    
36     class MTentry;
37    
38     // MTkey is a covering region indicated by an object and its covering radii: obj, rmin, rmax
39     // We also throw in some standard geo operators to support various query predicates, etc.
40    
41     class MTkey: public GiSTobject {
42     public:
43     Object obj; // object
44     private:
45     double rmin, rmax; // covering radii
46     public:
47 root 1.3 friend class MTentry;
48 root 1.1 // constructors, destructors, assignment, etc.
49     MTkey(): rmin(0), rmax(MAXDOUBLE), distance(-maxDist()), splitted(FALSE), recomp(FALSE) { }
50    
51     MTkey(const MTkey& k): obj(k.obj), rmin(k.rmin), rmax(k.rmax), distance(k.distance), splitted(k.splitted), recomp(k.recomp) { }
52    
53     MTkey(Object& p_obj, const double p_rmin, const double p_rmax, const double p_distance=-maxDist(), const BOOL p_splitted=FALSE, const BOOL p_recomp=FALSE):
54     obj(p_obj), rmin(p_rmin), rmax(p_rmax), distance(p_distance), splitted(p_splitted), recomp(p_recomp) { }
55    
56     GiSTobject *Copy() const { return new MTkey(*this); }
57    
58     ~MTkey() { }
59     GiSTobjid IsA() { return MTKEY_CLASS; }
60    
61     MTkey& operator = (const MTkey& k) {
62     obj=k.obj;
63     rmin=k.rmin;
64     rmax=k.rmax;
65     distance=k.distance;
66     splitted=k.splitted;
67     recomp=k.recomp;
68     return *this;
69     }
70    
71     // covering region property and comparison methods
72     int operator==(const MTkey& k) {
73     return ((!recomp)&&(!k.recomp)&&(obj==k.obj)&&(rmin==k.rmin)&&(rmax==k.rmax)&&(distance==k.distance));
74     }
75    
76     int overlap (const MTkey& k) {
77     double d=obj.distance(k.obj);
78    
79     return ((d+rmax>=k.rmin)&&(d+k.rmax>=rmin)&&(d<rmax+k.rmax));
80     }
81    
82     int contained(const MTkey& k) {
83     double d=obj.distance(k.obj);
84    
85     return ((d-rmax>=k.rmin)&&(d+rmax<=k.rmax));
86     }
87    
88     int contains(const MTkey& k) {
89     double d=obj.distance(k.obj);
90    
91     return ((d-k.rmax>=rmin)&&(d+k.rmax<=rmax));
92     }
93    
94     double area() { return obj.area(rmax); }
95    
96     // expand this covering region to contain k
97     MTkey *expand(const MTkey& k) {
98     MTkey *result;
99     double d=obj.distance(k.obj);
100    
101     result=new MTkey(obj, MIN(rmin, d), MAX(rmax, d));
102     return result;
103     }
104    
105     Object object() const { return obj; }
106     double minradius() const { return rmin; }
107     double maxradius() const { return rmax; }
108    
109     double distance; // Here we store the distance between the entry and its parent, only for index performance, in order to minimize the number of distance computations;
110     BOOL splitted; // indicate that the node has been splitted
111     BOOL recomp; // indicate that the node has been splitted but that no Union has been performed (thus radii are in a potentially inconsistent state): this can happen after a split
112    
113     // I/O methods
114     #ifdef PRINTING_OBJECTS
115     void Print(ostream& os) const {
116     os << '"';
117     os << "(" << obj << ", " << rmin << ", " << rmax << ")" << '"';
118     }
119     #endif
120     };
121    
122     #ifdef PRINTING_OBJECTS
123     inline ostream& operator<< (ostream& os, const MTkey& k) {
124     k.Print(os);
125     return os;
126     }
127     #endif
128    
129     class MTpenalty: public GiSTpenalty { // we have to create a sub-class in order to add the member value distance
130     public:
131     MTpenalty(): GiSTpenalty(), distance(-maxDist()) { }
132    
133     MTpenalty(const double v, const double d): GiSTpenalty(v), distance(d) { }
134    
135     double distance; // this is necessary since each penalty is defined by two values: the radius increase and the distance from the entry
136     };
137    
138     int sizeofEntry();
139    
140     class MTentry: public GiSTentry { // this are the entries stored in each node
141     public:
142     // constructors, destructors, etc.
143     MTentry() { }
144    
145     MTentry(const MTkey& k, const GiSTpage p) {
146     key=new MTkey(k);
147     ptr=p;
148     }
149    
150     MTentry(const MTentry& e): GiSTentry(e) {
151     key=new MTkey(*(MTkey *)(e.key));
152     }
153    
154     GiSTobjid IsA() const { return MTENTRY_CLASS; }
155    
156     GiSTobject *Copy() const { return new MTentry(*this); }
157    
158     void InitKey() { key=new MTkey; }
159    
160     int IsEqual(const GiSTobject& obj) const {
161     if(obj.IsA()!=MTENTRY_CLASS) return 0;
162     return ((*((MTkey *)key)==(*((MTkey *)(((const MTentry&) obj).key)))));
163     }
164    
165     // cast key member to class MTkey *. Prevents compiler warnings.
166     MTkey *Key() const { return (MTkey *)key; }
167    
168     // basic GiST methods
169     GiSTpenalty *Penalty(const GiSTentry &newEntry) const;
170     GiSTpenalty *Penalty(const GiSTentry &newEntry, MTpenalty *minPenalty) const; // redefined in order to optimize distance computations
171    
172     // Other methods we're required to supply
173     int CompressedLength() const {
174     return object().CompressedLength()+3*sizeof(double)+2*sizeof(BOOL); // compressedEntry is: Object, rmin, rmax, distance, splitted, recomp
175     }
176    
177     GiSTcompressedEntry Compress() const;
178     void Decompress(const GiSTcompressedEntry entry);
179    
180     // Method for ordered domains
181     int Compare(const GiSTentry& entry) const {
182     assert(entry.IsA()==MTENTRY_CLASS);
183     double d=Key()->distance-((MTentry &)entry).Key()->distance;
184     int i=0;
185    
186     if(d>0) i=1;
187     else if(d<0) i=-1;
188     return i;
189     }
190    
191     // I/O methods
192     #ifdef PRINTING_OBJECTS
193     void Print(ostream& os) const {
194     key->Print(os);
195     os << "->" << Ptr() << " (" << Key()->distance << ")";
196     if(Key()->splitted) os << " *";
197     if(Key()->recomp) os << " #";
198     os << endl;
199     }
200     #endif
201    
202     // access to private members
203     const MTkey& cregion() const { return *Key(); }
204     Object& object() const { return Key()->obj; }
205     double minradius() const { return Key()->rmin; }
206     double maxradius() const { return Key()->rmax; }
207     void setobject(const Object& o) { Key()->obj=o; }
208     void setminradius(double d) { Key()->rmin=d; }
209     void setmaxradius(double d) { Key()->rmax=d; }
210     };
211    
212     #endif