MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ConsumeTop

Function ConsumeTop

tensorflow/core/lib/gtl/priority_queue_util.h:29–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27// Supports movable types.
28template <typename T, typename Container, typename Comparator>
29T ConsumeTop(std::priority_queue<T, Container, Comparator>* q) {
30 // std::priority_queue is required to implement pop() as if it
31 // called:
32 // std::pop_heap()
33 // c.pop_back()
34 // unfortunately, it does not provide access to the removed element.
35 // If the element is move only (such as a unique_ptr), there is no way to
36 // reclaim it in the standard API. std::priority_queue does, however, expose
37 // the underlying container as a protected member, so we use that access
38 // to extract the desired element between those two calls.
39 using Q = std::priority_queue<T, Container, Comparator>;
40 struct Expose : Q {
41 using Q::c;
42 using Q::comp;
43 };
44 auto& c = q->*&Expose::c;
45 auto& comp = q->*&Expose::comp;
46 std::pop_heap(c.begin(), c.end(), comp);
47 auto r = std::move(c.back());
48 c.pop_back();
49 return r;
50}
51
52} // namespace gtl
53} // namespace tensorflow

Callers 1

DequeueLockedMethod · 0.85

Calls 4

pop_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected