GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rollbear/prio_queue: C++14 cache friendly B-heap priority queue

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
LICENSE_1_0.txt
LICENSE_1_0.txt
 
 
README.md
README.md
 
 
perf_benchmark.cpp
perf_benchmark.cpp
 
 
prio_queue.hpp
prio_queue.hpp
 
 
self_test.cpp
self_test.cpp
 
 

Repository files navigation

prio_queue

This is the implementation of a cache friendly priority queue as a B-heap.

The workings and some performance observarions are available in a post on the blog playfulprogramming.

Usage differs slightly from std::priority_queue

The (simplified) signature is:

// in namespace rollbear
template <size_t miniheap_size, typename Prio, typename Value, class Compare = std::less<Prio>>
class prio_queue
{
public:
  prio_queue(Compare const& comp = Compare());
  
  using value type = Prio;
  using payload_type = Value;
  
  void                           push(Prio p, Value v);
  std::pair<Prio const&, Value&> top() const noexcept;
  void                           pop();
  void                           reschedule_top(Prio);
  bool                           empty() const noexcept;
  std::size_t                    size() const noexcept();
};

The reason for separate priority field and value data is that it offers much better performance than to have a priority queue over a struct/pair/tuple holding both and compare priority on it.

It is legal to set Value as void, in which case push() will accept only one parameter, and top() will return Prio const&, but generally performance will suffer when doing so.

miniheap_size is what you can tweak for optimum performance. How large to set it depends on the size of the Prio data type and the size of the cache lines. See the above mentioned blog post for guidance.

The real signatures for push() uses perfect forwarding.

reschedule_top() is synonymous to auto v = q.top(); q.pop(); q.push(v);, but is usually faster.

There is an additional allocator parameter.

If the Prio and Value types have noexcept move constructors and assignment, the strong exception guarantee holds, otherwise the weak exception guarantee.

Self test

The included self test program relies on two external frame works.

  • Catch!
    • a header only unit test frame work
  • trompeloeil
    • a header only mocking frame work

Performance benchmark

The included performance benchmark relies on one external frame work.

  • tachymeter
    • a header only C++14 micro benchmark frame work

About

C++14 cache friendly B-heap priority queue

Resources

Readme
BSL-1.0 license
Activity

Stars

112 stars

Watchers

3 watching

Forks

18 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.