Commit | Line | Data |
---|---|---|
e87b4ac1 PR |
1 | // This may look like C code, but it is really -*- C++ -*- |
2 | /* | |
3 | Copyright (C) 1988 Free Software Foundation | |
4 | written by Doug Lea (dl@rocky.oswego.edu) | |
5 | ||
6 | This file is part of the GNU C++ Library. This library is free | |
7 | software; you can redistribute it and/or modify it under the terms of | |
8 | the GNU Library General Public License as published by the Free | |
9 | Software Foundation; either version 2 of the License, or (at your | |
10 | option) any later version. This library is distributed in the hope | |
11 | that it will be useful, but WITHOUT ANY WARRANTY; without even the | |
12 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
13 | PURPOSE. See the GNU Library General Public License for more details. | |
14 | You should have received a copy of the GNU Library General Public | |
15 | License along with this library; if not, write to the Free Software | |
16 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 | */ | |
18 | ||
19 | ||
20 | #ifndef _<T><C>CHMap_h | |
21 | #ifdef __GNUG__ | |
22 | #pragma interface | |
23 | #endif | |
24 | #define _<T><C>CHMap_h 1 | |
25 | ||
26 | #include "<T>.<C>.Map.h" | |
27 | ||
28 | #ifndef _<T><C>CHNode_h | |
29 | #define _<T><C>CHNode_h 1 | |
30 | ||
31 | struct <T><C>CHNode | |
32 | { | |
33 | <T><C>CHNode* tl; | |
34 | <T> hd; | |
35 | <C> cont; | |
36 | <T><C>CHNode(); | |
37 | <T><C>CHNode(<T&> h, <C&> c, <T><C>CHNode* t = 0); | |
38 | ~<T><C>CHNode(); | |
39 | }; | |
40 | ||
41 | inline <T><C>CHNode::<T><C>CHNode() {} | |
42 | ||
43 | inline <T><C>CHNode::<T><C>CHNode(<T&> h, <C&> c, <T><C>CHNode* t) | |
44 | : hd(h), cont(c), tl(t) {} | |
45 | ||
46 | inline <T><C>CHNode::~<T><C>CHNode() {} | |
47 | ||
48 | typedef <T><C>CHNode* <T><C>CHNodePtr; | |
49 | ||
50 | #endif | |
51 | ||
52 | ||
53 | class <T><C>CHMap : public <T><C>Map | |
54 | { | |
55 | protected: | |
56 | <T><C>CHNode** tab; | |
57 | unsigned int size; | |
58 | ||
59 | public: | |
60 | <T><C>CHMap(<C&> dflt,unsigned int sz=DEFAULT_INITIAL_CAPACITY); | |
61 | <T><C>CHMap(<T><C>CHMap& a); | |
62 | ~<T><C>CHMap(); | |
63 | ||
64 | <C>& operator [] (<T&> key); | |
65 | ||
66 | void del(<T&> key); | |
67 | ||
68 | Pix first(); | |
69 | void next(Pix& i); | |
70 | <T>& key(Pix i); | |
71 | <C>& contents(Pix i); | |
72 | ||
73 | Pix seek(<T&> key); | |
74 | int contains(<T&> key); | |
75 | ||
76 | void clear(); | |
77 | int OK(); | |
78 | }; | |
79 | ||
80 | ||
81 | inline <T><C>CHMap::~<T><C>CHMap() | |
82 | { | |
83 | clear(); | |
84 | delete tab; | |
85 | } | |
86 | ||
87 | inline int <T><C>CHMap::contains(<T&> key) | |
88 | { | |
89 | return seek(key) != 0; | |
90 | } | |
91 | ||
92 | inline <T>& <T><C>CHMap::key(Pix p) | |
93 | { | |
94 | if (p == 0) error("null Pix"); | |
95 | return ((<T><C>CHNode*)p)->hd; | |
96 | } | |
97 | ||
98 | inline <C>& <T><C>CHMap::contents(Pix p) | |
99 | { | |
100 | if (p == 0) error("null Pix"); | |
101 | return ((<T><C>CHNode*)p)->cont; | |
102 | } | |
103 | ||
104 | #endif |