/src/aspell/common/block_slist.hpp
Line | Count | Source |
1 | | // This file is part of The New Aspell |
2 | | // Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license |
3 | | // version 2.0 or 2.1. You should have received a copy of the LGPL |
4 | | // license along with this library if you did not you can find |
5 | | // it at http://www.gnu.org/. |
6 | | |
7 | | #ifndef autil__block_slist_hh |
8 | | #define autil__block_slist_hh |
9 | | |
10 | | // BlockSList provided a pool of nodes which can be used for singly |
11 | | // linked lists. Nodes are allocated in large chunks instead of |
12 | | // one at a time which means that getting a new node is very fast. |
13 | | // Nodes returned are not initialized in any way. A placement new |
14 | | // must be used to construct the data member and the destructor |
15 | | // must explicitly be called. |
16 | | |
17 | | namespace acommon { |
18 | | |
19 | | template <typename T> |
20 | | class BlockSList { |
21 | | |
22 | | public: |
23 | | |
24 | | struct Node { |
25 | | Node * next; |
26 | | T data; |
27 | | }; |
28 | | |
29 | | private: |
30 | | |
31 | | void * first_block; |
32 | | Node * first_available; |
33 | | |
34 | | BlockSList(const BlockSList &); |
35 | | BlockSList & operator= (const BlockSList &); |
36 | | |
37 | | public: |
38 | | |
39 | | BlockSList() |
40 | | // Default constructor. |
41 | | // add_block must be called before any nodes are available |
42 | 28.5k | : first_block(0), first_available(0) {}; acommon::BlockSList<acommon::StringPair>::BlockSList() Line | Count | Source | 42 | 12.6k | : first_block(0), first_available(0) {}; |
acommon::BlockSList<aspeller::Conds const*>::BlockSList() Line | Count | Source | 42 | 718 | : first_block(0), first_available(0) {}; |
acommon::BlockSList<char const*>::BlockSList() Line | Count | Source | 42 | 13.0k | : first_block(0), first_available(0) {}; |
acommon::BlockSList<std::__1::pair<char const* const, acommon::Vector<char const*> > >::BlockSList() Line | Count | Source | 42 | 2.13k | : first_block(0), first_available(0) {}; |
|
43 | | |
44 | | Node * new_node() |
45 | | // return a new_node if one is available or null otherwise |
46 | | // Note: the node's data member is NOT initialized in any way. |
47 | 1.37M | { |
48 | 1.37M | Node * n = first_available; |
49 | 1.37M | if (n != 0) |
50 | 1.36M | first_available = first_available->next; |
51 | 1.37M | return n; |
52 | 1.37M | } acommon::BlockSList<acommon::StringPair>::new_node() Line | Count | Source | 47 | 676k | { | 48 | 676k | Node * n = first_available; | 49 | 676k | if (n != 0) | 50 | 676k | first_available = first_available->next; | 51 | 676k | return n; | 52 | 676k | } |
acommon::BlockSList<aspeller::Conds const*>::new_node() Line | Count | Source | 47 | 15.3k | { | 48 | 15.3k | Node * n = first_available; | 49 | 15.3k | if (n != 0) | 50 | 15.2k | first_available = first_available->next; | 51 | 15.3k | return n; | 52 | 15.3k | } |
acommon::BlockSList<char const*>::new_node() Line | Count | Source | 47 | 682k | { | 48 | 682k | Node * n = first_available; | 49 | 682k | if (n != 0) | 50 | 674k | first_available = first_available->next; | 51 | 682k | return n; | 52 | 682k | } |
Unexecuted instantiation: acommon::BlockSList<std::__1::pair<char const* const, acommon::Vector<char const*> > >::new_node() |
53 | | |
54 | | void remove_node(Node * n) |
55 | | // marks the node as available |
56 | | // Note: the node's data member destructor is NOT called |
57 | 295 | { |
58 | 295 | n->next = first_available; |
59 | 295 | first_available = n; |
60 | 295 | } |
61 | | |
62 | | void add_block(unsigned int num); |
63 | | // allocate enough memory for an additional num nodes |
64 | | |
65 | | void clear(); |
66 | | // free all memory. add_block must then be called before any nodes |
67 | | // are available |
68 | | // Note: the node's data member destructor is NOT called |
69 | | |
70 | | |
71 | 28.4k | ~BlockSList() {clear();} acommon::BlockSList<acommon::StringPair>::~BlockSList() Line | Count | Source | 71 | 12.5k | ~BlockSList() {clear();} |
acommon::BlockSList<aspeller::Conds const*>::~BlockSList() Line | Count | Source | 71 | 718 | ~BlockSList() {clear();} |
acommon::BlockSList<char const*>::~BlockSList() Line | Count | Source | 71 | 13.0k | ~BlockSList() {clear();} |
acommon::BlockSList<std::__1::pair<char const* const, acommon::Vector<char const*> > >::~BlockSList() Line | Count | Source | 71 | 2.13k | ~BlockSList() {clear();} |
|
72 | | |
73 | | }; |
74 | | |
75 | | } |
76 | | #endif |