~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSStorage.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
 
2
 *
 
3
 * PrimeBase Media Stream for MySQL
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Original author: Paul McCullagh (H&G2JCtL)
 
20
 * Continued development: Barry Leslie
 
21
 *
 
22
 * 2007-06-15
 
23
 *
 
24
 * CORE SYSTEM STORAGE
 
25
 * Basic storage structures.
 
26
 *
 
27
 */
 
28
 
 
29
#ifndef __CSSTORAGE_H__
 
30
#define __CSSTORAGE_H__
 
31
 
 
32
#include <stdio.h>
 
33
 
 
34
#include "CSDefs.h"
 
35
#include "CSString.h"
 
36
 
 
37
class CSHashTable;
 
38
 
 
39
class CSHashTable : public CSObject {
 
40
public:
 
41
        CSHashTable(): iSize(0), iTable(NULL) { }
 
42
        virtual ~CSHashTable();
 
43
 
 
44
        void setSize(uint32_t size);
 
45
 
 
46
        void clear();
 
47
 
 
48
        /* Value must be given referenced. */
 
49
        void add(CSObject *item);
 
50
 
 
51
        /* Value is returned NOT referenced. */
 
52
        CSObject *find(CSObject *key);
 
53
        
 
54
        void remove(CSObject *key);
 
55
 
 
56
private:
 
57
        uint32_t iSize;
 
58
 
 
59
        CSObject **iTable;
 
60
};
 
61
 
 
62
#define SC_SORT_LIST_INC_SIZE           20
 
63
 
 
64
class CSSortedList : public CSObject {
 
65
public:
 
66
        CSSortedList(): iListSize(0), iInUse(0), iList(NULL) { }
 
67
        virtual ~CSSortedList() { clear(); }
 
68
 
 
69
        void clear();
 
70
 
 
71
        /* Value must be given referenced. */
 
72
        void add(CSObject *item);
 
73
        
 
74
        /* Value is returned NOT referenced. */
 
75
        CSObject *find(CSObject *key);
 
76
 
 
77
        CSObject *itemAt(uint32_t idx);
 
78
        
 
79
        CSObject *takeItemAt(uint32_t idx); // Takes item off of list.
 
80
        
 
81
        void remove(CSObject *key);
 
82
        
 
83
        uint32_t getSize() { return iInUse; }
 
84
 
 
85
 
 
86
private:
 
87
        uint32_t iListSize;
 
88
 
 
89
        uint32_t iInUse;
 
90
 
 
91
        CSObject **iList;
 
92
 
 
93
        CSObject *search(CSObject *key, uint32_t& idx);
 
94
};
 
95
 
 
96
class CSSyncSortedList : public CSSortedList, public CSSync {
 
97
public:
 
98
        CSSyncSortedList(): CSSortedList(), CSSync() { }
 
99
};
 
100
 
 
101
class CSLinkedItem : public CSRefObject {
 
102
public:
 
103
        CSLinkedItem(): CSRefObject() { }
 
104
        virtual ~CSLinkedItem() { }
 
105
 
 
106
        virtual CSObject *getNextLink() { return iNextLink; }
 
107
        virtual CSObject *getPrevLink() { return iPrevLink; }
 
108
        virtual void setNextLink(CSObject *link) { iNextLink = link; }
 
109
        virtual void setPrevLink(CSObject *link) { iPrevLink = link; }
 
110
 
 
111
private:
 
112
        CSObject                *iNextLink;
 
113
        CSObject                *iPrevLink;
 
114
};
 
115
 
 
116
/*
 
117
 * Items are linked so that following the previous pointers
 
118
 * you move from front to back.
 
119
 * Following the next pointers you move from back to front.
 
120
 */
 
121
class CSLinkedList : public CSObject {
 
122
public:
 
123
        CSLinkedList(): iSize(0), iListFront(NULL), iListBack(NULL) { }
 
124
        virtual ~CSLinkedList() { clear(); }
 
125
 
 
126
        void clear();
 
127
        
 
128
        uint32_t getSize() { return iSize; }
 
129
 
 
130
        /* Value must be given referenced. */
 
131
        void addFront(CSObject *item);
 
132
 
 
133
        bool remove(CSObject *item);
 
134
 
 
135
        /* Value is returned referenced. */
 
136
        CSObject *removeBack();
 
137
 
 
138
        /* Value is returned NOT referenced. */
 
139
        CSObject *getBack();
 
140
 
 
141
        /* Value is returned NOT referenced. */
 
142
        CSObject *getFront();
 
143
 
 
144
        /* Value is returned referenced. */
 
145
        CSObject *removeFront();
 
146
private:
 
147
        uint32_t iSize;
 
148
        CSObject *iListFront;
 
149
        CSObject *iListBack;
 
150
};
 
151
 
 
152
class CSVector : public CSObject {
 
153
public:
 
154
        CSVector(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
 
155
        virtual ~CSVector() { free(); }
 
156
 
 
157
        void free();
 
158
 
 
159
        void clear();
 
160
 
 
161
        /*
 
162
         * Remove and object from the vector, and
 
163
         * The object is rfemoved from the list.
 
164
         * return a reference.
 
165
         */
 
166
        CSObject *take(uint32_t idx);
 
167
 
 
168
        /*
 
169
         * Remove an object from the vector.
 
170
         */
 
171
        void remove(uint32_t idx);
 
172
 
 
173
        /*
 
174
         * Get a reference to an object in the vector.
 
175
         * A reference to the object remains on the list.
 
176
         * Value returned is NOT referenced!
 
177
         */
 
178
        CSObject *get(uint32_t idx);
 
179
 
 
180
        /* Set a specific index: */
 
181
        void set(uint32_t idx, CSObject *);
 
182
 
 
183
        /*
 
184
         * Add an object to the end of the vector.
 
185
         * Value must be referenced.
 
186
         */
 
187
        void add(CSObject *);
 
188
 
 
189
        uint32_t size() { return iUsage; }
 
190
 
 
191
private:
 
192
        uint32_t iGrowSize;
 
193
        uint32_t iMaxSize;
 
194
        uint32_t iUsage;
 
195
 
 
196
        CSObject **iArray;
 
197
};
 
198
 
 
199
class CSSyncVector : public CSVector, public CSSync {
 
200
public:
 
201
        CSSyncVector(uint32_t growSize): CSVector(growSize), CSSync() { }
 
202
};
 
203
 
 
204
typedef struct CSSpareArrayItem {
 
205
        uint32_t                sa_index;
 
206
        CSObject        *sa_object;
 
207
} CSSpareArrayItemRec, *CSSpareArrayItemPtr;
 
208
 
 
209
class CSSparseArray : public CSObject {
 
210
public:
 
211
        CSSparseArray(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
 
212
        CSSparseArray(): iGrowSize(10), iMaxSize(0), iUsage(0), iArray(NULL) { }
 
213
        virtual ~CSSparseArray() { free(); }
 
214
 
 
215
        void free();
 
216
 
 
217
        void clear();
 
218
 
 
219
        CSObject *take(uint32_t idx);
 
220
 
 
221
        void remove(uint32_t idx);
 
222
 
 
223
        void removeFirst();
 
224
 
 
225
        CSObject *itemAt(uint32_t idx);
 
226
 
 
227
        CSObject *get(uint32_t idx);
 
228
        
 
229
        uint32_t getIndex(uint32_t idx);
 
230
        
 
231
        void set(uint32_t idx, CSObject *);
 
232
 
 
233
        uint32_t size() { return iUsage; }
 
234
 
 
235
        uint32_t minIndex() {
 
236
                if (iUsage == 0)
 
237
                        return 0;
 
238
                return iArray[0].sa_index;
 
239
        }
 
240
 
 
241
        uint32_t maxIndex() {
 
242
                if (iUsage == 0)
 
243
                        return 0;
 
244
                return iArray[iUsage-1].sa_index;
 
245
        }
 
246
 
 
247
        CSObject *first();
 
248
 
 
249
        CSObject *last();
 
250
 
 
251
private:
 
252
        uint32_t                                iGrowSize;
 
253
        uint32_t                                iMaxSize;
 
254
        uint32_t                                iUsage;
 
255
        CSSpareArrayItemPtr     iArray;
 
256
 
 
257
        CSObject *search(uint32_t idx, uint32_t& pos);
 
258
};
 
259
 
 
260
class CSSyncSparseArray : public CSSparseArray, public CSSync {
 
261
public:
 
262
        CSSyncSparseArray(uint32_t growSize): CSSparseArray(growSize), CSSync() { }
 
263
};
 
264
 
 
265
class CSOrderKey : public CSObject {
 
266
public:
 
267
        virtual int compareKey(CSOrderKey *key) = 0;
 
268
        int compareKey(CSObject *key) {return CSObject::compareKey(key);}
 
269
};
 
270
 
 
271
typedef struct CSOrderedListItem {
 
272
        CSOrderKey      *li_key;
 
273
        CSObject        *li_item;
 
274
} CSOrderedListItemRec, *CSOrderedListItemPtr;
 
275
 
 
276
class CSOrderedList : public CSObject {
 
277
public:
 
278
        CSOrderedList(): iListSize(0), iInUse(0), iList(NULL) { }
 
279
        virtual ~CSOrderedList() { clear(); }
 
280
 
 
281
        void clear();
 
282
 
 
283
        /* Value must be given referenced. */
 
284
        void add(CSOrderKey *key, CSObject *item);
 
285
        
 
286
        /* Value is returned NOT referenced. */
 
287
        CSObject *find(CSOrderKey *key);
 
288
        
 
289
        /* Value is returned NOT referenced. */
 
290
        CSObject *itemAt(uint32_t idx);
 
291
        
 
292
        void remove(CSOrderKey *key);
 
293
 
 
294
private:
 
295
        uint32_t iListSize;
 
296
 
 
297
        uint32_t iInUse;
 
298
 
 
299
        CSOrderedListItemPtr iList;
 
300
 
 
301
        CSOrderedListItemPtr search(CSOrderKey *key, uint32_t *idx);
 
302
};
 
303
 
 
304
class CSSyncOrderedList : public CSOrderedList, public CSSync {
 
305
public:
 
306
        CSSyncOrderedList(): CSOrderedList(), CSSync() { }
 
307
};
 
308
 
 
309
class CSQueue;
 
310
 
 
311
typedef struct CSQueueItem {
 
312
        CSObject                        *qi_object;
 
313
        CSQueue                         *qi_next;
 
314
} CSQueueItemRec, *CSQueueItemPtr;
 
315
 
 
316
class CSQueue : public CSObject {
 
317
public:
 
318
        CSQueue(): iQueueSize(0), iHighWater(0), iFront(NULL), iBack(NULL), iFree(NULL) { }
 
319
        virtual ~CSQueue() { clear(); }
 
320
 
 
321
        void clear();
 
322
 
 
323
        /* Value must be given referenced. */
 
324
        void add(CSObject *item);
 
325
 
 
326
        /* Returns a referenced value, on a FIFO basis. */
 
327
        CSObject *remove();
 
328
 
 
329
private:
 
330
        uint32_t iQueueSize;
 
331
        uint32_t iHighWater;
 
332
 
 
333
        CSQueueItemPtr  iFront;
 
334
        CSQueueItemPtr  iBack;
 
335
        CSQueueItemPtr  iFree;
 
336
};
 
337
 
 
338
#endif