bzr branch
http://bzr.ed.am/elec/propeller-clock
57
by edam
added ulibc |
1 |
/* Copyright (C) 2004 Garrett A. Kajmowicz |
2 |
This file is part of the uClibc++ Library. |
|
3 |
This library is free software; you can redistribute it and/or |
|
4 |
modify it under the terms of the GNU Lesser General Public |
|
5 |
License as published by the Free Software Foundation; either |
|
6 |
version 2.1 of the License, or (at your option) any later version. |
|
7 |
||
8 |
This library is distributed in the hope that it will be useful, |
|
9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 |
Lesser General Public License for more details. |
|
12 |
||
13 |
You should have received a copy of the GNU Lesser General Public |
|
14 |
License along with this library; if not, write to the Free Software |
|
15 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
*/ |
|
17 |
||
18 |
#include <basic_definitions> |
|
19 |
#include <deque> |
|
20 |
#include <vector> |
|
21 |
#include <functional> |
|
22 |
||
23 |
#ifndef __HEADER_STD_QUEUE |
|
24 |
#define __HEADER_STD_QUEUE 1 |
|
25 |
||
26 |
#pragma GCC visibility push(default) |
|
27 |
||
28 |
namespace std{ |
|
29 |
||
30 |
template <class T, class Container = deque<T> > class _UCXXEXPORT queue{ |
|
31 |
protected: |
|
32 |
Container c; |
|
33 |
public: |
|
34 |
typedef typename Container::value_type value_type; |
|
35 |
typedef typename Container::size_type size_type; |
|
36 |
typedef Container container_type; |
|
37 |
||
38 |
explicit queue(const Container& a = Container()) : c(a) { } |
|
39 |
||
40 |
bool empty() const { return c.empty(); } |
|
41 |
size_type size() const { return c.size(); } |
|
42 |
value_type& front() { return c.front(); } |
|
43 |
const value_type& front() const { return c.front(); } |
|
44 |
value_type& back() { return c.back(); } |
|
45 |
const value_type& back() const { return c.back(); } |
|
46 |
void push(const value_type& x) { c.push_back(x); } |
|
47 |
void pop() { c.pop_front(); } |
|
48 |
}; |
|
49 |
||
50 |
||
51 |
template <class T, class Container> _UCXXEXPORT bool |
|
52 |
operator==(const queue<T, Container>& x, const queue<T, Container>& y) |
|
53 |
{ |
|
54 |
return (x.c == y.c); |
|
55 |
} |
|
56 |
template <class T, class Container> _UCXXEXPORT bool |
|
57 |
operator< (const queue<T, Container>& x, const queue<T, Container>& y) |
|
58 |
{ |
|
59 |
return (x.c < y.c); |
|
60 |
} |
|
61 |
template <class T, class Container> _UCXXEXPORT bool |
|
62 |
operator!=(const queue<T, Container>& x, const queue<T, Container>& y) |
|
63 |
{ |
|
64 |
return (x.c != y.c); |
|
65 |
} |
|
66 |
template <class T, class Container> _UCXXEXPORT bool |
|
67 |
operator> (const queue<T, Container>& x, const queue<T, Container>& y) |
|
68 |
{ |
|
69 |
return (x.c > y.c); |
|
70 |
} |
|
71 |
template <class T, class Container> _UCXXEXPORT bool |
|
72 |
operator>=(const queue<T, Container>& x, const queue<T, Container>& y) |
|
73 |
{ |
|
74 |
return (x.c >= y.c); |
|
75 |
} |
|
76 |
template <class T, class Container> _UCXXEXPORT bool |
|
77 |
operator<=(const queue<T, Container>& x, const queue<T, Container>& y) |
|
78 |
{ |
|
79 |
return (x.c <= y.c); |
|
80 |
} |
|
81 |
||
82 |
||
83 |
template <class T, |
|
84 |
class Container = vector<T>, |
|
85 |
class Compare = less<typename Container::value_type> |
|
86 |
> class _UCXXEXPORT priority_queue { |
|
87 |
protected: |
|
88 |
Container c; |
|
89 |
Compare comp; |
|
90 |
public: |
|
91 |
typedef typename Container::value_type value_type; |
|
92 |
typedef typename Container::size_type size_type; |
|
93 |
typedef Container container_type; |
|
94 |
||
95 |
explicit priority_queue(const Compare& x = Compare(), const Container& a = Container()) |
|
96 |
: c(a), comp(x) { make_heap(c.begin(), c.end(), comp) ; } |
|
97 |
template <class InputIterator> priority_queue(InputIterator first, |
|
98 |
InputIterator last, |
|
99 |
const Compare& x = Compare(), |
|
100 |
const Container& y= Container()) |
|
101 |
: c(y), comp(c) |
|
102 |
{ |
|
103 |
c.insert(c.end(), first, last); |
|
104 |
make_heap(c.begin(), c.end(), comp); |
|
105 |
} |
|
106 |
||
107 |
bool empty() const { return c.empty(); } |
|
108 |
size_type size() const { return c.size(); } |
|
109 |
const value_type& top() const { return c.front(); } |
|
110 |
void push(const value_type& x){ |
|
111 |
c.push_back(x); |
|
112 |
push_heap(c.begin(), c.end(), comp); |
|
113 |
} |
|
114 |
void pop(){ |
|
115 |
pop_heap(c.begin(), c.end(), comp); |
|
116 |
c.pop_back(); |
|
117 |
} |
|
118 |
}; |
|
119 |
||
120 |
} |
|
121 |
||
122 |
#pragma GCC visibility pop |
|
123 |
||
124 |
#endif |
|
125 |
||
126 |