casacore
Loading...
Searching...
No Matches
SSMIndex.h
Go to the documentation of this file.
1//# SSMIndex.h: The bucket index for a group of columns in the SSM
2//# Copyright (C) 2000
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_SSMINDEX_H
27#define TABLES_SSMINDEX_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Containers/Block.h>
32#include <casacore/casa/Arrays/Vector.h>
33#include <map>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class SSMBase;
39
40
41// <summary>
42// The bucket index for a group of columns in the Standard Storage Manager.
43// </summary>
44
45// <use visibility=local>
46
47// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tStandardStMan.cc">
48// </reviewed>
49
50// <prerequisite>
51//# Classes you should understand before using this one.
52// <li> <linkto class=SSMBase>SSMBase</linkto>
53// </prerequisite>
54
55// <etymology>
56// SSMIndex represent the bucket index in the Standard Storage Manager.
57// </etymology>
58
59// <synopsis>
60// In <linkto class=SSMBase>SSMBase</linkto> it is described that an index
61// is used to map row number to data bucket in a bucket stream.
62// This class implements this index. It serves 2 purposes:
63// <ol>
64// <li> It keeps a block of row numbers giving the last row number
65// stored in each data bucket.
66// <br>Note that each bucket does not need to contain the same number
67// of rows, because rows might be deleted from it.
68// When all rows are deleted from a bucket, the bucket is removed
69// from the index and added to the free bucket list.
70// <li> When a column is deleted, the bucket will have a hole.
71// SSMIndex maintains a map to know the size and offset of each hole.
72// Adjacent holes are combined.
73// When a new column is added <linkto class=SSMBase>SSMBase</linkto>
74// will scan the SSMIndex objects to find the hole fitting best.
75// </ol>
76// </synopsis>
77
78// <todo asof="$DATE:$">
79//# A List of bugs, limitations, extensions or planned refinements.
80// <li> recreate should recreate the itsLastRow && itsBucketNr as well
81// (moving them to the front and rearrange the freespace as one
82// concatenated block)
83// </todo>
84
86{
87public:
88 // Create the object with the given number of rows per bucket.
89 // Note that the default is needed to create the object for existing
90 // tables.
91 explicit SSMIndex (SSMBase* aPtrSSM, uInt rowsPerBucket=0);
92
94
95 // Read the bucket index from the AipsIO object.
96 void get (AipsIO& anOs);
97
98 // Write the bucket index into the AipsIO object.
99 void put (AipsIO& anOs) const;
100
101 // Recreate the object in case all rows are deleted from the table.
102 void recreate();
103
104 // Return all the bucketnrs used in this index.
106
107 // Return the nr of buckets used.
109
110 // Set nr of columns use this index.
111 void setNrColumns (Int aNrColumns, uInt aSizeUsed);
112
113 // Add some rows.
114 void addRow (rownr_t aNrRows);
115
116 // Show Statistics of index.
117 void showStatistics (ostream& anOs) const;
118
119 // A column is removed.
120 // Set the free space at offset for a field with the given nr of bits.
121 // It returns the nr of columns still used in this index.
122 Int removeColumn (Int anOffset, uInt nbits);
123
124 // Try to find free space for a field with a given length (best fit).
125 // -1 is returned if no fit is found.
126 // Otherwise it returns the nr of bytes left unused.
127 Int getFree (Int& anOffset, uInt nbits) const;
128
129 // reuse the space at offset for a field with the given nr of bits.
130 // This is used when column has been added to this bucket.
131 void addColumn (Int anOffset, uInt nbits);
132
133 // Delete the given row.
134 // It returns the bucket nr if it gets empty, otherwise -1.
135 Int deleteRow (rownr_t aRowNumber);
136
137 // Get the number of rows that fits in ach bucket.
138 uInt getRowsPerBucket() const;
139
140 // Find the bucket containing the given row.
141 // An exception is thrown if not found.
142 // It also sets the first and last row number fitting in that bucket.
143 void find (rownr_t aRowNumber, uInt& aBucketNr, rownr_t& aStartRow,
144 rownr_t& anEndRow, const String& colName) const;
145
146private:
147 // Get the index of the bucket containing the given row.
148 uInt getIndex (rownr_t aRowNr, const String& colName) const;
149
150
151 //# Pointer to specific Storage Manager.
153
154 //# Nr of entries used in blocks.
156
157 //# Last row nr indexed together with itsBucketNumber
159
160 //# Bucketnumbers indexed together with itsLastRow.
161 //# So itsLastRow[0] contains the last rownumber of the bucket
162 //# in itsBucketNumber[0]
164
165 //# Map that contains length/offset pairs for free size (size in bytes).
166 std::map<Int,Int> itsFreeSpace;
167
168 //# How many rows fit in a bucket?
170
171 //# Nr of columns using this index.
173};
174
175
177{
178 return itsRowsPerBucket;
179}
180
181
182
183} //# NAMESPACE CASACORE - END
184
185#endif
simple 1-D array
Definition Block.h:198
void showStatistics(ostream &anOs) const
Show Statistics of index.
SSMBase * itsSSMPtr
Definition SSMIndex.h:152
Block< uInt > itsBucketNumber
Definition SSMIndex.h:163
uInt getRowsPerBucket() const
Get the number of rows that fits in ach bucket.
Definition SSMIndex.h:176
void put(AipsIO &anOs) const
Write the bucket index into the AipsIO object.
Int getFree(Int &anOffset, uInt nbits) const
Try to find free space for a field with a given length (best fit).
void recreate()
Recreate the object in case all rows are deleted from the table.
void setNrColumns(Int aNrColumns, uInt aSizeUsed)
Set nr of columns use this index.
void addColumn(Int anOffset, uInt nbits)
reuse the space at offset for a field with the given nr of bits.
void addRow(rownr_t aNrRows)
Add some rows.
std::map< Int, Int > itsFreeSpace
Definition SSMIndex.h:166
Int removeColumn(Int anOffset, uInt nbits)
A column is removed.
void get(AipsIO &anOs)
Read the bucket index from the AipsIO object.
Block< rownr_t > itsLastRow
Definition SSMIndex.h:158
Int deleteRow(rownr_t aRowNumber)
Delete the given row.
void find(rownr_t aRowNumber, uInt &aBucketNr, rownr_t &aStartRow, rownr_t &anEndRow, const String &colName) const
Find the bucket containing the given row.
uInt getNrBuckets() const
Return the nr of buckets used.
Vector< uInt > getBuckets() const
Return all the bucketnrs used in this index.
uInt getIndex(rownr_t aRowNr, const String &colName) const
Get the index of the bucket containing the given row.
SSMIndex(SSMBase *aPtrSSM, uInt rowsPerBucket=0)
Create the object with the given number of rows per bucket.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44