1
/* This file is part of the KDE project
2
Copyright (C) 2000 Torben Weis <weis@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
21
This class defines a pointer map to all cells, which makes access to them more performant
22
and additionally limits memory consumption.
24
In detail: The class defines 2 cluster, where the second cluster (LEVEL2) is a matrix for
25
single cells, while the first cluster (LEVEL1) is a matrix to handle the matrices of LEVEL2.
26
On initialization, one LEVEL1 matrix is generated only.
27
Each time, a cell stores something, this class checks if for the given column and row a
28
matrix of LEVEL2 is already initialized and in case not generates it on the fly.
29
This helps to reduce the memory usage to only consum one pointer matrix for LEVEL1 and all
30
matrices of LEVEL2 that are necessary.
32
LEVEL1 is defined as 128x128 matrix.
33
LEVEL2 is defined as 256x256 matrices.
34
Each direction then can have LEVEL1 * LEVEL2 = 128*256 = 2^15 different cells, which
35
is in total (2^15)^2 cells.
37
It can be changed easily to different sizes, but it should be more senseful to have a small LEVEL1,
38
as in most cases only one/two entries in LEVEL1 will be used.
40
There are 2 additional special classes to store pointers for column and row formats.
43
To reduce memory consumption, it should be possible to enhance the functionality by
44
another LEVEL0, which then keeps the LEVEL1 size smaller.
46
Maybe the LEVEL1 should only be generated when there is a need for more than 1 LEVEL2.
48
LEVEL1 maybe reallocated.
50
Another interesting possibility would be to differentiate between x size and y size. Currently both
51
are equal in both matrizes, but normally it will be the regular case, that you have more need for
52
a lot of rows than columns. Maybe something like LEVEL1=128/256 and LEVEL2=256/128 (x/y), still keeping
53
2^15 values/cells in each direction (benefit: you won't loose memory in empty columns).
1
56
#ifndef kspread_cluster_h
2
57
#define kspread_cluster_h
10
#define KSPREAD_CLUSTER_LEVEL1 100
11
#define KSPREAD_CLUSTER_LEVEL2 100
12
#define KSPREAD_CLUSTER_MAX (100*100)
65
#define KSPREAD_CLUSTER_LEVEL1 128
66
#define KSPREAD_CLUSTER_LEVEL2 256
67
#define KSPREAD_CLUSTER_MAX (128*256)
14
69
class KSpreadCluster
82
136
* Removes all elements from the column.
138
* @param presereDoM preserve the DependingOnMe lists of the cells if non-empty
84
void clearColumn( int col );
85
void clearRow( int row );
140
void clearColumn( int col, bool preserveDoM = false );
141
void clearRow( int row, bool preserveDoM = false );
144
* Retrieve the first used cell in a given column. Can be used in conjunction
145
* with getNextCellDown to loop through a column.
147
* @param col The column to get the first cell from
149
* @return Returns a pointer to the cell, or NULL if there are no used cells
152
KSpreadCell* getFirstCellColumn(int col) const;
155
* Retrieve the last used cell in a given column. Can be used in conjunction
156
* with getNextCellUp to loop through a column.
158
* @param col The column to get the cell from
160
* @return Returns a pointer to the cell, or NULL if there are no used cells
163
KSpreadCell* getLastCellColumn(int col) const;
166
* Retrieve the first used cell in a given row. Can be used in conjunction
167
* with getNextCellRight to loop through a row.
169
* @param row The row to get the first cell from
171
* @return Returns a pointer to the cell, or NULL if there are no used cells
174
KSpreadCell* getFirstCellRow(int row) const;
177
* Retrieve the last used cell in a given row. Can be used in conjunction
178
* with getNextCellLeft to loop through a row.
180
* @param row The row to get the last cell from
182
* @return Returns a pointer to the cell, or NULL if there are no used cells
185
KSpreadCell* getLastCellRow(int row) const;
188
* Retrieves the next used cell above the given col/row pair. The given
189
* col/row pair does not need to reference a used cell.
191
* @param col column to start looking through
192
* @param row the row above which to start looking.
194
* @return Returns the next used cell above this one, or NULL if there are none
196
KSpreadCell* getNextCellUp(int col, int row) const;
199
* Retrieves the next used cell below the given col/row pair. The given
200
* col/row pair does not need to reference a used cell.
202
* @param col column to start looking through
203
* @param row the row below which to start looking.
205
* @return Returns the next used cell below this one, or NULL if there are none
207
KSpreadCell* getNextCellDown(int col, int row) const;
210
* Retrieves the next used cell to the right of the given col/row pair.
211
* The given col/row pair does not need to reference a used cell.
213
* @param col the column after which should be searched
214
* @param row the row to search through
216
* @return Returns the next used cell to the right of this one, or NULL if
219
KSpreadCell* getNextCellRight(int col, int row) const;
222
* Retrieves the next used cell to the left of the given col/row pair.
223
* The given col/row pair does not need to reference a used cell.
225
* @param col the column before which should be searched
226
* @param row the row to search through
228
* @return Returns the next used cell to the left of this one, or NULL if
231
KSpreadCell* getNextCellLeft(int col, int row) const;
106
252
KSpreadColumnCluster();
107
253
~KSpreadColumnCluster();
109
const ColumnLayout* lookup( int col ) const;
110
ColumnLayout* lookup( int col );
255
const ColumnFormat* lookup( int col ) const;
256
ColumnFormat* lookup( int col );
114
void insertElement( ColumnLayout*, int col );
260
void insertElement( ColumnFormat*, int col );
115
261
void removeElement( int col );
117
263
bool insertColumn( int col );
134
280
KSpreadRowCluster();
135
281
~KSpreadRowCluster();
137
const RowLayout* lookup( int col ) const;
138
RowLayout* lookup( int col );
283
const RowFormat* lookup( int col ) const;
284
RowFormat* lookup( int col );
142
void insertElement( RowLayout*, int row );
288
void insertElement( RowFormat*, int row );
143
289
void removeElement( int row );
145
291
bool insertRow( int row );