Skip to content

Commit

Permalink
Update comments and descriptions. (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
acodcha committed Oct 20, 2023
1 parent b266930 commit d00f310
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Various utilities that extend the C++ Standard Library.

### Constant Expression Square Root

Constant expression (`constexpr`) square root solver. Note that `std::sqrt` is not a constant expression. Returns the same result as `std::sqrt` to within one unit in the last place.
Constant expression (`constexpr`) square root function. Note that the C++ Standard Library's square root function (`std::sqrt`) is not a constant expression. Returns the same result as the C++ Standard Library's implementation to within one unit in the last place (1 ULP).

```C++
constexpr double square_root_of_two = utility::constexpr_sqrt(2.0);
Expand All @@ -32,24 +32,24 @@ If you wish to use this implementation in your project, copy the [constexpr_sqrt

### Updatable Priority Queue

Simple C++ priority queue that allows updating the priority of its elements.
Simple C++ priority queue where the priorities of elements can be updated. Each element consist of a value and a priority; multiple values can have the same priority, but values must be unique.

```C++
utility::updatable_priority_queue<std::string, double> name_and_score;

name_and_score.insert("Alice", 10.0);
name_and_score.insert("Bob", 15.0);
name_and_score.insert("Claire", 5.0);
std::cout << name_and_score.head_value() << std::endl; // Claire
std::cout << name_and_score.front_value() << std::endl; // Claire

name_and_score.update("Claire", 20.0);
std::cout << name_and_score.head_value() << std::endl; // Alice
std::cout << name_and_score.front_value() << std::endl; // Alice

name_and_score.remove_head();
std::cout << name_and_score.head_value() << std::endl; // Bob
name_and_score.erase_front();
std::cout << name_and_score.front_value() << std::endl; // Bob
```

The C++ Standard Library's priority queue (`std::priority_queue`) does not support updating the priority of its elements. However, certain use cases such as Dijkstra's algorithm require this operation. This project implements a priority queue that supports updating the priority of its elements and achieves the same asymptotic time complexity and asymptotic space complexity as the C++ Standard Library's implementation.
The C++ Standard Library's priority queue (`std::priority_queue`) does not support updating the priority of its elements; certain use cases such as Dijkstra's algorithm require this operation. This project implements a priority queue that supports updating the priority of its elements and achieves the same asymptotic time complexity and asymptotic space complexity as the C++ Standard Library's implementation to within a constant factor.

If you wish to use this implementation in your project, copy the [updatable_priority_queue.hpp](include/cpp-utilities/updatable_priority_queue.hpp) header file to your source code repository and include it in your C++ source code files with `#include "updatable_priority_queue.hpp"`.

Expand Down
17 changes: 9 additions & 8 deletions include/cpp-utilities/updatable_priority_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
// Namespace that encompasses all of the C++ Utilities library's content.
namespace utility {

// Simple priority queue that allows updating the priority of its elements.
// Each element consist of a value and a priority. Multiple values can have the
// same priority. However, values must be unique.
// Simple C++ priority queue where the priorities of elements can be updated.
// Each element consist of a value and a priority; multiple values can have the
// same priority, but values must be unique.
//
// By default, elements in the queue are ordered in increasing order of priority
// given by std::less<Priority>, such that the element with the lowest priority
// is at the front of the queue. This can be changed by providing a different
// By default, elements in the queue are ordered by increasing priority given by
// std::less<Priority> such that the element with the lowest priority is at the
// front of the queue. This can be changed by providing a different
// PriorityComparator.
//
// If multiple elements in the queue have the same priority, by default they are
// ordered in increasing value given by std::less<Value>. This can be changed by
// providing a different ValueComparator.
// ordered by increasing value given by std::less<Value> such that the lowest
// value appears first. This can be changed by providing a different
// ValueComparator.
template <class Value, class Priority,
class PriorityComparator = std::less<Priority>,
class ValueComparator = std::less<Value>>
Expand Down

0 comments on commit d00f310

Please sign in to comment.