Skip to content

NikolajLeischner/csharp-binary-heap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a priority queue intended to be used within path-finding algorithms. I created it for a Unity-based RTS game where Unity's builtin navigation did not fit my needs.

For queues not larger than approximately 2^15 - 2^16 elements an optimised binary heap is still at least as fast as more complex priority queue data structures. In the context of path-finding in a video game, should this priority queue show up as a performance bottleneck, the most promosing optimisations would be:

  • prune your graph,
  • reduce the number of path queries.

Implementing Dijkstra or A* without decreaseKey

Textbooks often show SPATH algorithms based upon a priority queue which also allows decreasing the key of the queue's entries.

  • You can use a hash set that stores visited node indices for this. If your graph is not too big, and nodes are identified by an integer id in the range from 0 to N (as they should), you can also just use an array of bools.
  • After dequeueing a node, check if it has already been visited. If yes, then skip it and dequeue the next node. If no, perform the next step of the algorithm, and mark the node as visited.

Acknowledgement

This is mostly just a port of the C++ binary heap implementation found here: http://algo2.iti.kit.edu/sanders/programs/

The old but gold implementation tricks taken from there are:

  • Use sentinel values instead of boundary checks.
  • Assign everything you access in a method to a local variable to make the compiler's life as simple as possible.

References

Releases

No releases published

Packages

No packages published

Languages