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>XPPQ_h | |
21 | #ifdef __GNUG__ | |
22 | #pragma interface | |
23 | #endif | |
24 | #define _<T>XPPQ_h 1 | |
25 | ||
26 | #include "<T>.PQ.h" | |
27 | #include "<T>.XPlex.h" | |
28 | ||
29 | class <T>XPPQ : public <T>PQ | |
30 | { | |
31 | protected: | |
32 | <T>XPlex p; | |
33 | ||
34 | public: | |
35 | <T>XPPQ(int chunksize = DEFAULT_INITIAL_CAPACITY); | |
36 | <T>XPPQ(const <T>XPPQ&); | |
37 | ||
38 | Pix enq(<T&> item); | |
39 | <T> deq(); | |
40 | ||
41 | <T>& front(); | |
42 | void del_front(); | |
43 | ||
44 | int contains(<T&> item); | |
45 | ||
46 | void clear(); | |
47 | ||
48 | Pix first(); | |
49 | void next(Pix& i); | |
50 | <T>& operator () (Pix i); | |
51 | void del(Pix i); | |
52 | int owns(Pix i); | |
53 | Pix seek(<T&> item); | |
54 | ||
55 | int OK(); // rep invariant | |
56 | }; | |
57 | ||
58 | inline <T>XPPQ::<T>XPPQ(int chunksize) | |
59 | : p(1, chunksize) { count = 0; } | |
60 | ||
61 | inline <T>XPPQ::<T>XPPQ(const <T>XPPQ& s) : p(s.p) { count = s.count; } | |
62 | ||
63 | inline Pix <T>XPPQ::first() | |
64 | { | |
65 | return p.first(); | |
66 | } | |
67 | ||
68 | inline void <T>XPPQ::next(Pix & idx) | |
69 | { | |
70 | p.next(idx); | |
71 | } | |
72 | ||
73 | inline <T>& <T>XPPQ::operator ()(Pix idx) | |
74 | { | |
75 | return p(idx); | |
76 | } | |
77 | ||
78 | inline <T>& <T>XPPQ::front () | |
79 | { | |
80 | return p.low_element(); | |
81 | } | |
82 | ||
83 | inline <T> <T>XPPQ::deq () | |
84 | { | |
85 | <T> x = p.low_element(); | |
86 | del_front(); | |
87 | return x; | |
88 | } | |
89 | ||
90 | inline void <T>XPPQ::clear() | |
91 | { | |
92 | count = 0; p.clear(); | |
93 | } | |
94 | ||
95 | inline int <T>XPPQ::contains (<T&> item) | |
96 | { | |
97 | return seek(item) != 0; | |
98 | } | |
99 | ||
100 | inline int <T>XPPQ::owns (Pix idx) | |
101 | { | |
102 | return p.owns(idx); | |
103 | } | |
104 | ||
105 | #endif |