xref: /386bsd/usr/include/nonstd/gnu/g++/gen/CHMap.hP (revision a2142627)
1// This may look like C code, but it is really -*- C++ -*-
2/*
3Copyright (C) 1988 Free Software Foundation
4    written by Doug Lea (dl@rocky.oswego.edu)
5
6This file is part of GNU CC.
7
8GNU CC is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY.  No author or distributor
10accepts responsibility to anyone for the consequences of using it
11or for whether it serves any particular purpose or works at all,
12unless he says so in writing.  Refer to the GNU CC General Public
13License for full details.
14
15Everyone is granted permission to copy, modify and redistribute
16GNU CC, but only under the conditions described in the
17GNU CC General Public License.   A copy of this license is
18supposed to have been given to you along with GNU CC so you
19can know your rights and responsibilities.  It should be in a
20file named COPYING.  Among other things, the copyright notice
21and this notice must be preserved on all copies.
22*/
23
24
25#ifndef _<T><C>CHMap_h
26#ifdef __GNUG__
27#pragma once
28#pragma interface
29#endif
30#define _<T><C>CHMap_h 1
31
32#include "<T>.<C>.Map.h"
33
34#ifndef _<T><C>CHNode_h
35#define _<T><C>CHNode_h 1
36
37struct <T><C>CHNode
38{
39  <T><C>CHNode*      tl;
40  <T>                hd;
41  <C>                cont;
42                     <T><C>CHNode();
43                     <T><C>CHNode(<T&> h, <C&> c, <T><C>CHNode* t = 0);
44                     ~<T><C>CHNode();
45};
46
47#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
48
49inline <T><C>CHNode::<T><C>CHNode() {}
50
51inline <T><C>CHNode::<T><C>CHNode(<T&> h, <C&> c, <T><C>CHNode* t)
52     : hd(h), cont(c), tl(t) {}
53
54inline <T><C>CHNode::~<T><C>CHNode() {}
55
56
57#endif
58
59typedef <T><C>CHNode* <T><C>CHNodePtr;
60
61#endif
62
63
64class <T><C>CHMap : public <T><C>Map
65{
66protected:
67  <T><C>CHNode** tab;
68  unsigned int   size;
69
70public:
71                <T><C>CHMap(<C&> dflt,unsigned int sz=DEFAULT_INITIAL_CAPACITY);
72                <T><C>CHMap(<T><C>CHMap& a);
73                ~<T><C>CHMap();
74
75  <C>&          operator [] (<T&> key);
76
77  void          del(<T&> key);
78
79  Pix           first();
80  void          next(Pix& i);
81  <T>&          key(Pix i);
82  <C>&          contents(Pix i);
83
84  Pix           seek(<T&> key);
85  int           contains(<T&> key);
86
87  void          clear();
88  int           OK();
89};
90
91#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
92
93inline <T><C>CHMap::~<T><C>CHMap()
94{
95  clear();
96  delete tab;
97}
98
99inline int <T><C>CHMap::contains(<T&> key)
100{
101  return seek(key) != 0;
102}
103
104inline <T>& <T><C>CHMap::key(Pix p)
105{
106  if (p == 0) error("null Pix");
107  return ((<T><C>CHNode*)p)->hd;
108}
109
110inline <C>& <T><C>CHMap::contents(Pix p)
111{
112  if (p == 0) error("null Pix");
113  return ((<T><C>CHNode*)p)->cont;
114}
115
116
117#endif
118#endif
119