Commit | Line | Data |
---|---|---|
b98528ef WJLGJ |
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 GNU CC. | |
7 | ||
8 | GNU CC is distributed in the hope that it will be useful, | |
9 | but WITHOUT ANY WARRANTY. No author or distributor | |
10 | accepts responsibility to anyone for the consequences of using it | |
11 | or for whether it serves any particular purpose or works at all, | |
12 | unless he says so in writing. Refer to the GNU CC General Public | |
13 | License for full details. | |
14 | ||
15 | Everyone is granted permission to copy, modify and redistribute | |
16 | GNU CC, but only under the conditions described in the | |
17 | GNU CC General Public License. A copy of this license is | |
18 | supposed to have been given to you along with GNU CC so you | |
19 | can know your rights and responsibilities. It should be in a | |
20 | file named COPYING. Among other things, the copyright notice | |
21 | and this notice must be preserved on all copies. | |
22 | */ | |
23 | ||
24 | #ifdef __GNUG__ | |
25 | #pragma implementation | |
26 | #endif | |
27 | #include "<T>.XPBag.h" | |
28 | ||
29 | int <T>XPBag::OK() | |
30 | { | |
31 | int v = p.OK(); | |
32 | v &= count == p.length(); | |
33 | if (!v) error("invariant failure"); | |
34 | return v; | |
35 | } | |
36 | ||
37 | Pix <T>XPBag::seek(<T&> item, Pix i) | |
38 | { | |
39 | if (i == 0) i = p.first(); else next(i); | |
40 | for (; i != 0; p.next(i)) if (<T>EQ(p(i), item)) return i; | |
41 | return 0; | |
42 | } | |
43 | ||
44 | int <T>XPBag::nof(<T&> item) | |
45 | { | |
46 | int n = 0; | |
47 | for (int i = p.low(); i < p.fence(); p.next(i)) if (<T>EQ(p[i], item)) ++n; | |
48 | return n; | |
49 | } | |
50 | ||
51 | void <T>XPBag::del(<T&> item) | |
52 | { | |
53 | for (int i = p.low(); i < p.fence(); p.next(i)) | |
54 | { | |
55 | if (<T>EQ(p[i], item)) | |
56 | { | |
57 | --count; | |
58 | p[i] = p.low_element(); | |
59 | p.del_low(); | |
60 | return; | |
61 | } | |
62 | } | |
63 | } | |
64 | ||
65 | void <T>XPBag::remove(<T&> item) | |
66 | { | |
67 | for (int i = p.low(); i < p.fence(); p.next(i)) | |
68 | { | |
69 | if (<T>EQ(p[i], item)) | |
70 | { | |
71 | --count; | |
72 | p[i] = p.low_element(); | |
73 | p.del_low(); | |
74 | } | |
75 | } | |
76 | } | |
77 |