xref: /386bsd/usr/src/lib/libg++/g++-include/gen/CHBag.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>CHBag_h
26#ifdef __GNUG__
27#pragma once
28#pragma interface
29#endif
30#define _<T>CHBag_h 1
31
32#include "<T>.Bag.h"
33
34
35#ifndef _<T>CHNode_h
36#define _<T>CHNode_h 1
37
38struct <T>CHNode
39{
40  <T>CHNode*         tl;
41  <T>                hd;
42                     <T>CHNode();
43                     <T>CHNode(<T&> h, <T>CHNode* t = 0);
44                     ~<T>CHNode();
45};
46
47#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
48
49inline <T>CHNode::<T>CHNode() {}
50
51inline <T>CHNode::<T>CHNode(<T&> h, <T>CHNode* t) :hd(h), tl(t) {}
52
53inline <T>CHNode::~<T>CHNode() {}
54
55#endif
56
57typedef <T>CHNode* <T>CHNodePtr;
58
59#endif
60
61
62class <T>CHBag : public <T>Bag
63{
64protected:
65  <T>CHNode**   tab;
66  unsigned int  size;
67
68public:
69                <T>CHBag(unsigned int sz = DEFAULT_INITIAL_CAPACITY);
70                <T>CHBag(<T>CHBag& a);
71                ~<T>CHBag();
72
73  Pix           add(<T&> item);
74  void          del(<T&> item);
75  void          remove(<T&>item);
76  int           nof(<T&> item);
77  int           contains(<T&> item);
78
79  void          clear();
80
81  Pix           first();
82  void          next(Pix& i);
83  <T>&          operator () (Pix i);
84  Pix           seek(<T&> item, Pix from = 0);
85
86  int           OK();
87};
88
89#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
90
91inline <T>CHBag::~<T>CHBag()
92{
93  clear();
94  delete tab;
95}
96
97inline int <T>CHBag::contains(<T&> key)
98{
99  return seek(key) != 0;
100}
101
102inline <T>& <T>CHBag::operator () (Pix i)
103{
104  if (i == 0) error("null Pix");
105  return ((<T>CHNode*)i)->hd;
106}
107
108
109#endif
110#endif
111