13 #ifndef STXXL_COMMON_ADDRESSABLE_QUEUES_HEADER
14 #define STXXL_COMMON_ADDRESSABLE_QUEUES_HEADER
26 template <
typename KeyType>
31 typedef std::map<KeyType, container_iter_t>
meta_t;
48 {
return vals.empty(); }
53 std::pair<handle, bool>
insert(
const KeyType& e)
56 std::pair<handle, bool> r = meta.insert(std::make_pair(e, ei));
60 vals.erase(r.first->second);
74 vals.erase(mi->second);
83 vals.erase(i->second);
89 const KeyType &
top()
const
90 {
return vals.front(); }
97 const KeyType e = top();
107 template <
typename KeyType,
typename PriorityType,
class Cmp = std::less<PriorityType> >
112 bool operator () (
const std::pair<PriorityType, KeyType>& left,
113 const std::pair<PriorityType, KeyType>& right)
const
116 return c(left.first, right.first) ||
117 ((! c(right.first, left.first)) && left.second < right.second);
121 typedef std::set<std::pair<PriorityType, KeyType>, cmp>
container_t;
123 typedef std::map<KeyType, container_iter_t>
meta_t;
140 {
return vals.empty(); }
146 std::pair<handle, bool>
insert(
const KeyType& e,
const PriorityType o)
148 std::pair<container_iter_t, bool> s = vals.insert(std::make_pair(o, e));
149 std::pair<handle, bool> r = meta.insert(std::make_pair(e, s.first));
150 if (! r.second && s.second)
153 vals.erase(r.first->second);
154 r.first->second = s.first;
165 if (mi == meta.end())
167 vals.erase(mi->second);
176 vals.erase(i->second);
182 const KeyType &
top()
const
183 {
return vals.begin()->second; }
190 const KeyType e = top();
192 vals.erase(vals.begin());
199 #endif // !STXXL_COMMON_ADDRESSABLE_QUEUES_HEADER
container_t::iterator container_iter_t
std::pair< handle, bool > insert(const KeyType &e)
Insert new element. If the element is already in, it is moved to the back.
meta_iter_t handle
Type of handle to an entry. For use with insert and remove.
An internal priority queue that allows removing elements addressed with (a copy of) themselves...
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.
std::map< KeyType, container_iter_t > meta_t
addressable_fifo_queue()
Create an empty queue.
meta_iter_t handle
Type of handle to an entry. For use with insert and remove.
bool empty() const
Check if queue is empty.
container_t::iterator container_iter_t
#define STXXL_BEGIN_NAMESPACE
meta_t::iterator meta_iter_t
std::list< KeyType > container_t
addressable_priority_queue()
Create an empty queue.
bool erase(const KeyType &e)
Erase element from the queue.
std::map< KeyType, container_iter_t > meta_t
~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.
KeyType pop()
Remove top element from the queue.
std::set< std::pair< PriorityType, KeyType >, cmp > container_t
#define STXXL_END_NAMESPACE
meta_t::iterator meta_iter_t