1 #ifndef theplu_yat_utility_sorted_buffer_ 2 #define theplu_yat_utility_sorted_buffer_ 43 template<
typename T,
typename OutputIterator,
44 typename Comp =
typename std::less<T>>
59 : out_(out), compare_(comp) {}
77 std::pop_heap(buffer_.begin(), buffer_.end(), compare_);
78 *out_ = std::move(buffer_.back());
80 YAT_ASSERT(buffer_.size()<2 || !compare_(buffer_[0], buffer_[1]));
89 std::sort_heap(buffer_.begin(), buffer_.end(), compare_);
90 std::copy(buffer_.rbegin(), buffer_.rend(), out_);
100 while (!buffer_.empty() && compare_(t,
top()))
110 buffer_.push_back(t);
111 std::push_heap(buffer_.begin(), buffer_.end(), compare_);
112 YAT_ASSERT(!buffer_.empty());
113 YAT_ASSERT(buffer_.size()<2 || !compare_(buffer_[0], buffer_[1]));
122 buffer_.push_back(std::move(t));
123 std::push_heap(buffer_.begin(), buffer_.end(), compare_);
124 YAT_ASSERT(!buffer_.empty());
125 YAT_ASSERT(buffer_.size()<2 || !compare_(buffer_[0], buffer_[1]));
134 YAT_ASSERT(buffer_.size());
135 return buffer_.front();
145 Compare(
void) =
default;
146 Compare(
const Comp& comp)
148 bool operator()(
const T& lhs,
const T& rhs)
const 149 {
return comp_(rhs, lhs); }
155 std::vector<T> buffer_;
Definition: SortedBuffer.h:45
void push(const T &t)
Definition: SortedBuffer.h:108
The Department of Theoretical Physics namespace as we define it.
const T & top(void) const
Definition: SortedBuffer.h:132
void flush_all(void)
Definition: SortedBuffer.h:87
void push(T &&t)
Definition: SortedBuffer.h:120
virtual ~SortedBuffer(void)
Destructor.
Definition: SortedBuffer.h:66
SortedBuffer(OutputIterator out)
Definition: SortedBuffer.h:51
void flush(void)
Definition: SortedBuffer.h:75
void flush(const T &t)
Definition: SortedBuffer.h:98
SortedBuffer(OutputIterator out, const Comp &comp)
Definition: SortedBuffer.h:58