-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaesa.h
179 lines (153 loc) · 4.45 KB
/
laesa.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef LAESA_H_321551dgs65fds1f65sd1fs6df51sd6f51sd6f51s6d5fs6df
#define LAESA_H_321551dgs65fds1f65sd1fs6df51sd6f51sd6f51s6d5fs6df
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "vector.h"
#include "result.h"
#include "indexTables.h"
using namespace std;
/**
* Class laesa\n
* Implements the basics of the metric access\n
*
* The types of queries implemented:\n
* kNN query\n
* range query\n
*/
class laesa : public IndexTables
{
public:
struct TObjects
{
struct TObject
{
int m_Id;
vector m_Vector;
double ** m_Array;
int m_Size;
int m_SizeMax;
TObject ( const vector & x );
void resize ( int size = -1 );
friend ostream & operator << ( ostream & os, const TObject & x )
{
os << "[" << setw ( 4 ) << x . m_Id << "]: O";
return os;
}
};
int m_Size;
int m_SizeMax;
TObject ** m_Objects;
TObjects ( void );
~TObjects ( void );
int add ( const vector & x );
void resize ( int size = -1 );
TObject & operator [] ( int index );
const TObject & operator [] ( int index ) const;
};
struct TPivots
{
struct TPivot : TObjects::TObject
{
TPivot ( const vector & x );
void resize ( int size = -1 );
friend ostream & operator << ( ostream & os, const TPivot & x )
{
os << "[" << setw ( 4 ) << x . m_Id << "]: P";
return os;
}
};
int m_Size;
int m_SizeMax;
TPivot ** m_Pivots;
TPivots ( void );
~TPivots ( void );
int add ( const vector & x );
void resize ( int size = -1 );
TPivot & operator [] ( int index );
const TPivot & operator [] ( int index ) const;
};
/**
* Helper class for the oveloaded operator [][]
*/
class Proxy
{
protected:
double ** m_Array;
int m_Size;
public:
Proxy ( double ** array, int size ) : m_Array ( array ), m_Size ( size ) {}
/**
* Overloaed operator [][] for easy access to the laesa table
* @param index second index to the laesa table, e. g. row
* @return the value
* @throws InvalidIndexException if the index is invalid
*/
double & operator [] ( int index )
{
if ( index > m_Size - 1 || index < 0 )
throw new InvalidIndexException ( "Index is out of range" );
return *m_Array[ index ];
}
/**
* Overloaed operator [][] for easy access to the laesa table
* @param index second index to the laesa table, e. g. row
* @return the value
* @throws InvalidIndexException if the index is invalid
*/
const double & operator [] ( int index ) const
{
if ( index > m_Size - 1 || index < 0 )
throw new InvalidIndexException ( "Index is out of range" );
return *m_Array[ index ];
}
};
TObjects m_Objects;
TPivots m_Pivots;
void resize ( int size = -1 );
void print ( ostream & os ) const;
void refresh ( void );
void sort ( TObjects::TObject ** objects, int len ) const;
//static int cmp ( TObjects::TObject * a, TObjects::TObject * b );
public:
laesa ( void );
laesa ( const laesa & x );
virtual ~laesa ( void );
/**
* Add object to the database
* the objects is represented by the vector
* @param x object vector
* @return *this for chaining
*/
laesa & add ( const vector & x );
/**
* Generate the number of pivots\n
* pivots are from the object space
* @param n the number of pivots to generate
*/
void generate ( int n = 3 );
/**
* {@inheritDoc}
*/
result * kNN ( const vector & x, int k, result * results = NULL ) const;
/**
* {@inheritDoc}
*/
result * range ( const vector & x, double range, result * results = NULL ) const;
/**
* Overloaed operator [][] for easy access to the laesa table
* @param index first index to the laesa table, e. g. column
* @return helper class for the second index @see Proxy
* @throws InvalidIndexException if the index is invalid
*/
Proxy operator [] ( int index );
/**
* Overloaed operator [][] for easy access to the laesa table
* @param index first index to the laesa table, e. g. column
* @return helper class for the second index @see Proxy
* @throws InvalidIndexException if the index is invalid
*/
const Proxy operator [] ( int index ) const;
friend ostream & operator << ( ostream & os, const laesa & x );
};
#endif