blob: 4ca27e6ee849cbc99873909e883f99f72a9a114c [file] [log] [blame]
dburgess82c46ff2011-10-07 02:40:51 +00001/*
2* Copyright 2008 Free Software Foundation, Inc.
3*
4* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion.
5*
6* This software is distributed under the terms of the GNU Affero Public License.
7* See the COPYING file in the main directory for details.
8*
9* This use of this software may be subject to additional restrictions.
10* See the LEGAL file in the main directory for details.
11
12 This program is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Affero General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Affero General Public License for more details.
21
22 You should have received a copy of the GNU Affero General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25*/
26
27
28
29#ifndef LINKEDLISTS_H
30#define LINKEDLISTS_H
31
32#include <stdlib.h>
33
34
35
36/** This node class is used to build singly-linked lists. */
37class ListNode {
38
39 private:
40
41 ListNode* mNext;
42 void* mData;
43
44 public:
45
46 ListNode* next() { return mNext; }
47 void next(ListNode* wNext) { mNext=wNext; }
48
49 void* data() { return mData; }
50 void data(void* wData) { mData=wData; }
51};
52
53
54
55
56/** A fast FIFO for pointer-based storage. */
57class PointerFIFO {
58
59 private:
60
61 ListNode* mHead; ///< points to next item out
62 ListNode* mTail; ///< points to last item in
63 ListNode* mFreeList; ///< pool of previously-allocated nodes
64 unsigned mSize; ///< number of items in the FIFO
65
66 public:
67
68 PointerFIFO()
69 :mHead(NULL),mTail(NULL),mFreeList(NULL),
70 mSize(0)
71 {}
72
73 unsigned size() const { return mSize; }
74
75 /** Put an item into the FIFO. */
76 void put(void* val);
77
78 /**
79 Take an item from the FIFO.
80 Returns NULL for empty list.
81 */
82 void* get();
83
84
85 private:
86
87 /** Allocate a new node to extend the FIFO. */
88 ListNode *allocate();
89
90 /** Release a node to the free pool after removal from the FIFO. */
91 void release(ListNode* wNode);
92
93};
94
95
96
97
98
99#endif
100// vim: ts=4 sw=4