13 #ifndef STXXL_COMMON_ADDRESSABLE_QUEUES_HEADER
14 #define STXXL_COMMON_ADDRESSABLE_QUEUES_HEADER
27 template <
typename KeyType>
32 typedef std::map<KeyType, container_iterator>
meta_type;
49 {
return vals.empty(); }
56 std::pair<handle, bool>
insert(
const KeyType& e)
59 std::pair<handle, bool> r = meta.insert(std::make_pair(e, ei));
63 vals.erase(r.first->second);
77 vals.erase(mi->second);
86 vals.erase(i->second);
92 const KeyType &
top()
const
93 {
return vals.front(); }
100 const KeyType e = top();
111 template <
typename KeyType,
typename PriorityType,
class Cmp = std::less<PriorityType> >
116 bool operator () (
const std::pair<PriorityType, KeyType>& left,
117 const std::pair<PriorityType, KeyType>& right)
const
120 return c(left.first, right.first) ||
121 ((! c(right.first, left.first)) && left.second < right.second);
127 typedef std::map<KeyType, container_iterator>
meta_type;
144 {
return vals.empty(); }
150 std::pair<handle, bool>
insert(
const KeyType& e,
const PriorityType o)
152 std::pair<container_iterator, bool> s = vals.insert(std::make_pair(o, e));
153 std::pair<handle, bool> r = meta.insert(std::make_pair(e, s.first));
154 if (! r.second && s.second)
157 vals.erase(r.first->second);
158 r.first->second = s.first;
169 if (mi == meta.end())
171 vals.erase(mi->second);
180 vals.erase(i->second);
186 const KeyType &
top()
const
187 {
return vals.begin()->second; }
194 const KeyType e = top();
196 vals.erase(vals.begin());
203 #endif // !STXXL_COMMON_ADDRESSABLE_QUEUES_HEADER
container_type::iterator container_iterator
std::pair< handle, bool > insert(const KeyType &e)
Insert new element. If the element is already in, it is moved to the back.
An internal priority queue that allows removing elements addressed with (a copy of) themselves...
container_type::iterator container_iterator
std::pair< handle, bool > insert(const KeyType &e, const PriorityType o)
Insert new element. If the element is already in, it's priority is updated.
const KeyType & top() const
Access top (= min) element in the queue.
bool erase(const KeyType &e)
Erase element from the queue.
const KeyType & top() const
Access top element in the queue.
addressable_fifo_queue()
Create an empty queue.
meta_type::iterator meta_iterator
std::map< KeyType, container_iterator > meta_type
std::list< KeyType > container_type
meta_iterator handle
Type of handle to an entry. For use with insert and remove.
bool empty() const
Check if queue is empty.
#define STXXL_BEGIN_NAMESPACE
meta_iterator handle
Type of handle to an entry. For use with insert and remove.
meta_type::iterator meta_iterator
addressable_priority_queue()
Create an empty queue.
bool erase(const KeyType &e)
Erase element from the queue.
~addressable_priority_queue()
KeyType pop()
Remove top (= min) element from the queue.
void erase(handle i)
Erase element from the queue.
~addressable_fifo_queue()
void erase(handle i)
Erase element from the queue.
An internal fifo queue that allows removing elements addressed with (a copy of) themselves.
bool empty() const
Check if queue is empty.
std::set< std::pair< PriorityType, KeyType >, cmp > container_type
KeyType pop()
Remove top element from the queue.
std::map< KeyType, container_iterator > meta_type
#define STXXL_END_NAMESPACE