1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
25
* Basic storage structures.
30
#ifndef __CSSTORAGE_H__
31
#define __CSSTORAGE_H__
40
class CSHashTable : public CSObject {
42
CSHashTable(): iSize(0), iTable(NULL) { }
43
virtual ~CSHashTable();
45
void setSize(uint32_t size);
49
/* Value must be given referenced. */
50
void add(CSObject *item);
52
/* Value is returned NOT referenced. */
53
CSObject *find(CSObject *key);
55
bool remove(CSObject *key);
63
#define SC_SORT_LIST_INC_SIZE 20
65
class CSSortedList : public CSObject {
67
CSSortedList(): iListSize(0), iInUse(0), iList(NULL) { }
68
virtual ~CSSortedList() { clear(); }
72
/* Value must be given referenced. */
73
void add(CSObject *item);
75
/* Value is returned NOT referenced. */
76
CSObject *find(CSObject *key);
78
CSObject *itemAt(uint32_t idx);
80
CSObject *takeItemAt(uint32_t idx); // Takes item off of list.
82
void remove(CSObject *key);
84
uint32_t getSize() { return iInUse; }
94
CSObject *search(CSObject *key, uint32_t& idx);
97
class CSSyncSortedList : public CSSortedList, public CSSync {
99
CSSyncSortedList(): CSSortedList(), CSSync() { }
102
class CSLinkedItem : public CSRefObject {
104
CSLinkedItem(): CSRefObject(), iNextLink(NULL), iPrevLink(NULL) { }
105
virtual ~CSLinkedItem() { }
107
virtual CSObject *getNextLink() { return iNextLink; }
108
virtual CSObject *getPrevLink() { return iPrevLink; }
109
virtual void setNextLink(CSObject *link) { iNextLink = link; }
110
virtual void setPrevLink(CSObject *link) { iPrevLink = link; }
118
* Items are linked so that following the previous pointers
119
* you move from front to back.
120
* Following the next pointers you move from back to front.
122
class CSLinkedList : public CSObject {
124
CSLinkedList(): iSize(0), iListFront(NULL), iListBack(NULL) { }
125
virtual ~CSLinkedList() { clear(); }
129
uint32_t getSize() { return iSize; }
131
/* Value must be given referenced. */
132
void addFront(CSObject *item);
133
void addBack(CSObject *item);
135
bool remove(CSObject *item);
137
/* Value is returned referenced. */
138
CSObject *removeBack();
140
/* Value is returned NOT referenced. */
143
/* Value is returned NOT referenced. */
144
CSObject *getFront();
146
/* Value is returned referenced. */
147
CSObject *removeFront();
150
CSObject *iListFront;
154
class CSSyncLinkedList : public CSLinkedList, public CSSync {
156
CSSyncLinkedList(): CSLinkedList(), CSSync() { }
159
class CSVector : public CSObject {
161
CSVector(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
162
virtual ~CSVector() { free(); }
169
* Remove and object from the vector, and
170
* The object is rfemoved from the list.
171
* return a reference.
173
CSObject *take(uint32_t idx);
176
* Remove an object from the vector.
178
void remove(uint32_t idx);
181
* Get a reference to an object in the vector.
182
* A reference to the object remains on the list.
183
* Value returned is NOT referenced!
185
CSObject *get(uint32_t idx);
187
/* Set a specific index: */
188
void set(uint32_t idx, CSObject *);
191
* Add an object to the end of the vector.
192
* Value must be referenced.
194
void add(CSObject *);
196
uint32_t size() { return iUsage; }
206
class CSSyncVector : public CSVector, public CSSync {
208
CSSyncVector(uint32_t growSize): CSVector(growSize), CSSync() { }
211
typedef struct CSSpareArrayItem {
214
} CSSpareArrayItemRec, *CSSpareArrayItemPtr;
216
class CSSparseArray : public CSObject {
218
CSSparseArray(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
219
CSSparseArray(): iGrowSize(10), iMaxSize(0), iUsage(0), iArray(NULL) { }
220
virtual ~CSSparseArray() { free(); }
226
CSObject *take(uint32_t sparse_idx);
228
void remove(uint32_t sparse_idx);
232
CSObject *itemAt(uint32_t idx);
234
CSObject *get(uint32_t sparse_idx);
236
uint32_t getIndex(uint32_t sparse_idx);
238
void set(uint32_t sparse_idx, CSObject *);
240
uint32_t size() { return iUsage; }
242
uint32_t minIndex() {
245
return iArray[0].sa_index;
248
uint32_t maxIndex() {
251
return iArray[iUsage-1].sa_index;
262
CSSpareArrayItemPtr iArray;
264
CSObject *search(uint32_t idx, uint32_t& pos);
267
class CSSyncSparseArray : public CSSparseArray, public CSSync {
269
CSSyncSparseArray(uint32_t growSize): CSSparseArray(growSize), CSSync() { }
272
class CSOrderKey : public CSObject {
274
virtual int compareKey(CSOrderKey *key) = 0;
275
int compareKey(CSObject *key) {return CSObject::compareKey(key);}
278
typedef struct CSOrderedListItem {
281
} CSOrderedListItemRec, *CSOrderedListItemPtr;
283
class CSOrderedList : public CSObject {
285
CSOrderedList(): iListSize(0), iInUse(0), iList(NULL) { }
286
virtual ~CSOrderedList() { clear(); }
290
/* Value must be given referenced. */
291
void add(CSOrderKey *key, CSObject *item);
293
/* Value is returned NOT referenced. */
294
CSObject *find(CSOrderKey *key);
296
/* Value is returned NOT referenced. */
297
CSObject *itemAt(uint32_t idx);
299
void remove(CSOrderKey *key);
306
CSOrderedListItemPtr iList;
308
CSOrderedListItemPtr search(CSOrderKey *key, uint32_t *idx);
311
class CSSyncOrderedList : public CSOrderedList, public CSSync {
313
CSSyncOrderedList(): CSOrderedList(), CSSync() { }
318
typedef struct CSQueueItem {
321
} CSQueueItemRec, *CSQueueItemPtr;
323
class CSQueue : public CSObject {
325
CSQueue(): iQueueSize(0), iHighWater(0), iFront(NULL), iBack(NULL), iFree(NULL) { }
326
virtual ~CSQueue() { clear(); }
330
/* Value must be given referenced. */
331
void add(CSObject *item);
333
/* Returns a referenced value, on a FIFO basis. */
340
CSQueueItemPtr iFront;
341
CSQueueItemPtr iBack;
342
CSQueueItemPtr iFree;