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// <summary>
41// The bucket index for a group of columns in the Standard Storage Manager.
42// </summary>
43
44// <use visibility=local>
45
46// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tStandardStMan.cc">
47// </reviewed>
48
49// <prerequisite>
50// # Classes you should understand before using this one.
51// <li> <linkto class=SSMBase>SSMBase</linkto>
52// </prerequisite>
53
54// <etymology>
55// SSMIndex represent the bucket index in the Standard Storage Manager.
56// </etymology>
57
58// <synopsis>
59// In <linkto class=SSMBase>SSMBase</linkto> it is described that an index
60// is used to map row number to data bucket in a bucket stream.
61// This class implements this index. It serves 2 purposes:
62// <ol>
63// <li> It keeps a block of row numbers giving the last row number
64// stored in each data bucket.
65// <br>Note that each bucket does not need to contain the same number
66// of rows, because rows might be deleted from it.
67// When all rows are deleted from a bucket, the bucket is removed
68// from the index and added to the free bucket list.
69// <li> When a column is deleted, the bucket will have a hole.
70// SSMIndex maintains a map to know the size and offset of each hole.
71// Adjacent holes are combined.
72// When a new column is added <linkto class=SSMBase>SSMBase</linkto>
73// will scan the SSMIndex objects to find the hole fitting best.
74// </ol>
75// </synopsis>
76
77// <todo asof="$DATE:$">
78// # A List of bugs, limitations, extensions or planned refinements.
79// <li> recreate should recreate the itsLastRow && itsBucketNr as well
80// (moving them to the front and rearrange the freespace as one
81// concatenated block)
82// </todo>
83
84class SSMIndex {
85 public:
86 // Create the object with the given number of rows per bucket.
87 // Note that the default is needed to create the object for existing
88 // tables.
89 explicit SSMIndex(SSMBase* aPtrSSM, uInt rowsPerBucket = 0);
90
92
93 // Read the bucket index from the AipsIO object.
94 void get(AipsIO& anOs);
95
96 // Write the bucket index into the AipsIO object.
97 void put(AipsIO& anOs) const;
98
99 // Recreate the object in case all rows are deleted from the table.
100 void recreate();
101
102 // Return all the bucketnrs used in this index.
104
105 // Return the nr of buckets used.
107
108 // Set nr of columns use this index.
109 void setNrColumns(Int aNrColumns, uInt aSizeUsed);
110
111 // Add some rows.
112 void addRow(rownr_t aNrRows);
113
114 // Show Statistics of index.
115 void showStatistics(ostream& anOs) const;
116
117 // A column is removed.
118 // Set the free space at offset for a field with the given nr of bits.
119 // It returns the nr of columns still used in this index.
120 Int removeColumn(Int anOffset, uInt nbits);
121
122 // Try to find free space for a field with a given length (best fit).
123 // -1 is returned if no fit is found.
124 // Otherwise it returns the nr of bytes left unused.
125 Int getFree(Int& anOffset, uInt nbits) const;
126
127 // reuse the space at offset for a field with the given nr of bits.
128 // This is used when column has been added to this bucket.
129 void addColumn(Int anOffset, uInt nbits);
130
131 // Delete the given row.
132 // It returns the bucket nr if it gets empty, otherwise -1.
133 Int deleteRow(rownr_t aRowNumber);
134
135 // Get the number of rows that fits in ach bucket.
136 uInt getRowsPerBucket() const;
137
138 // Find the bucket containing the given row.
139 // An exception is thrown if not found.
140 // It also sets the first and last row number fitting in that bucket.
141 void find(rownr_t aRowNumber, uInt& aBucketNr, rownr_t& aStartRow, rownr_t& anEndRow,
142 const String& colName) const;
143
144 private:
145 // Get the index of the bucket containing the given row.
146 uInt getIndex(rownr_t aRowNr, const String& colName) const;
147
148 // # Pointer to specific Storage Manager.
150
151 // # Nr of entries used in blocks.
153
154 // # Last row nr indexed together with itsBucketNumber
156
157 // # Bucketnumbers indexed together with itsLastRow.
158 // # So itsLastRow[0] contains the last rownumber of the bucket
159 // # in itsBucketNumber[0]
161
162 // # Map that contains length/offset pairs for free size (size in bytes).
163 std::map<Int, Int> itsFreeSpace;
164
165 // # How many rows fit in a bucket?
167
168 // # Nr of columns using this index.
170};
171
173
174} // namespace casacore
175
176#endif
void showStatistics(ostream &anOs) const
Show Statistics of index.
SSMBase * itsSSMPtr
Definition SSMIndex.h:149
Block< uInt > itsBucketNumber
Definition SSMIndex.h:160
uInt getRowsPerBucket() const
Get the number of rows that fits in ach bucket.
Definition SSMIndex.h:172
void put(AipsIO &anOs) const
Write the bucket index into the AipsIO object.
std::map< Int, Int > itsFreeSpace
Definition SSMIndex.h:163
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.
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:155
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
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