casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //# $Id$
26 
27 #ifndef TABLES_SSMINDEX_H
28 #define TABLES_SSMINDEX_H
29 
30 //# Includes
31 #include <casacore/casa/aips.h>
34 #include <map>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 class SSMBase;
40 
41 
42 // <summary>
43 // The bucket index for a group of columns in the Standard Storage Manager.
44 // </summary>
45 
46 // <use visibility=local>
47 
48 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tStandardStMan.cc">
49 // </reviewed>
50 
51 // <prerequisite>
52 //# Classes you should understand before using this one.
53 // <li> <linkto class=SSMBase>SSMBase</linkto>
54 // </prerequisite>
55 
56 // <etymology>
57 // SSMIndex represent the bucket index in the Standard Storage Manager.
58 // </etymology>
59 
60 // <synopsis>
61 // In <linkto class=SSMBase>SSMBase</linkto> it is described that an index
62 // is used to map row number to data bucket in a bucket stream.
63 // This class implements this index. It serves 2 purposes:
64 // <ol>
65 // <li> It keeps a block of row numbers giving the last row number
66 // stored in each data bucket.
67 // <br>Note that each bucket does not need to contain the same number
68 // of rows, because rows might be deleted from it.
69 // When all rows are deleted from a bucket, the bucket is removed
70 // from the index and added to the free bucket list.
71 // <li> When a column is deleted, the bucket will have a hole.
72 // SSMIndex maintains a map to know the size and offset of each hole.
73 // Adjacent holes are combined.
74 // When a new column is added <linkto class=SSMBase>SSMBase</linkto>
75 // will scan the SSMIndex objects to find the hole fitting best.
76 // </ol>
77 // </synopsis>
78 
79 // <todo asof="$DATE:$">
80 //# A List of bugs, limitations, extensions or planned refinements.
81 // <li> recreate should recreate the itsLastRow && itsBucketNr as well
82 // (moving them to the front and rearrange the freespace as one
83 // concatenated block)
84 // </todo>
85 
86 class SSMIndex
87 {
88 public:
89  // Create the object with the given number of rows per bucket.
90  // Note that the default is needed to create the object for existing
91  // tables.
92  explicit SSMIndex (SSMBase* aPtrSSM, uInt rowsPerBucket=0);
93 
94  ~SSMIndex();
95 
96  // Read the bucket index from the AipsIO object.
97  void get (AipsIO& anOs);
98 
99  // Write the bucket index into the AipsIO object.
100  void put (AipsIO& anOs) const;
101 
102  // Recreate the object in case all rows are deleted from the table.
103  void recreate();
104 
105  // Return all the bucketnrs used in this index.
106  Vector<uInt> getBuckets() const;
107 
108  // Return the nr of buckets used.
109  uInt getNrBuckets() const;
110 
111  // Set nr of columns use this index.
112  void setNrColumns (Int aNrColumns, uInt aSizeUsed);
113 
114  // Add some rows.
115  void addRow (uInt aNrRows);
116 
117  // Show Statistics of index.
118  void showStatistics (ostream& anOs) const;
119 
120  // A column is removed.
121  // Set the free space at offset for a field with the given nr of bits.
122  // It returns the nr of columns still used in this index.
123  Int removeColumn (Int anOffset, uInt nbits);
124 
125  // Try to find free space for a field with a given length (best fit).
126  // -1 is returned if no fit is found.
127  // Otherwise it returns the nr of bytes left unused.
128  Int getFree (Int& anOffset, uInt nbits) const;
129 
130  // reuse the space at offset for a field with the given nr of bits.
131  // This is used when column has been added to this bucket.
132  void addColumn (Int anOffset, uInt nbits);
133 
134  // Delete the given row.
135  Int deleteRow (uInt 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 (uInt aRowNumber, uInt& aBucketNr, uInt& aStartRow,
144  uInt& anEndRow, const String& colName) const;
145 
146 private:
147  // Get the index of the bucket containing the given row.
148  uInt getIndex (uInt 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
Block< uInt > itsLastRow
Definition: SSMIndex.h:158
int Int
Definition: aipstype.h:50
The bucket index for a group of columns in the Standard Storage Manager.
Definition: SSMIndex.h:86
SSMIndex(SSMBase *aPtrSSM, uInt rowsPerBucket=0)
Create the object with the given number of rows per bucket.
Int removeColumn(Int anOffset, uInt nbits)
A column is removed.
Int getFree(Int &anOffset, uInt nbits) const
Try to find free space for a field with a given length (best fit).
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
uInt getNrBuckets() const
Return the nr of buckets used.
uInt getRowsPerBucket() const
Get the number of rows that fits in ach bucket.
Definition: SSMIndex.h:176
Base class of the Standard Storage Manager.
Definition: SSMBase.h:158
void setNrColumns(Int aNrColumns, uInt aSizeUsed)
Set nr of columns use this index.
void find(uInt aRowNumber, uInt &aBucketNr, uInt &aStartRow, uInt &anEndRow, const String &colName) const
Find the bucket containing the given row.
uInt getIndex(uInt aRowNr, const String &colName) const
Get the index of the bucket containing the given row.
Int deleteRow(uInt aRowNumber)
Delete the given row.
void showStatistics(ostream &anOs) const
Show Statistics of index.
Vector< uInt > getBuckets() const
Return all the bucketnrs used in this index.
void addColumn(Int anOffset, uInt nbits)
reuse the space at offset for a field with the given nr of bits.
Block< uInt > itsBucketNumber
Definition: SSMIndex.h:163
void addRow(uInt aNrRows)
Add some rows.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void recreate()
Recreate the object in case all rows are deleted from the table.
std::map< Int, Int > itsFreeSpace
Definition: SSMIndex.h:166
SSMBase * itsSSMPtr
Definition: SSMIndex.h:152
void put(AipsIO &anOs) const
Write the bucket index into the AipsIO object.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42