Skip to content

Commit 5295da8

Browse files
committed
Readmes updated
1 parent 193854f commit 5295da8

7 files changed

Lines changed: 121 additions & 123 deletions

File tree

container/README.md

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,34 @@
1-
## A collection of algorithms and augmentations for STL-compatible containers
1+
# Container utilities
22

3-
### algorithms.hpp
3+
Algorithms, adapters, and containers for STL-compatible code.
44

5-
Defines two functions in `ContainerAlgorithms` namespace that are constructed upon the standard algorithms:
6-
* `void erase_all_occurrences(ContainerType& container, const ArgumentType& item)` deletes every occurrence of the `item` in `container` using the remove-erase idiom.
7-
* `void void erase_if(ContainerType& container, std::function<bool(const ItemType&)>` deletes every occurrence of the `item` in `container` using the remove-erase idiom.
5+
## Facilities
86

9-
### flat_map.hpp
7+
| Header | Facility |
8+
|---|---|
9+
| `algorithms.hpp` | `ContainerAlgorithms::erase_if()` applies the remove/erase idiom to sequence containers. |
10+
| `flat_map.hpp` | Vector-backed sorted `flat_map` and `flat_set` with heterogeneous lookup, random-access iteration, ordinary insertion/erasure, sorted-range merging, and batched unsorted insertion. |
11+
| `iterator_helpers.hpp` | `const_forward_iterator_wrapper` retains both an iterator and its parent container, allowing validity and end checks; factories provide wrapped `cbegin`/`cend`. |
12+
| `multi_index.hpp` | `MultiIndexSet` owns values uniquely by one member and maintains a non-unique secondary-member index with exact and range lookup. |
13+
| `multimap_helpers.hpp` | `multimap_value_iterator` adapts a multimap iterator to expose only its mapped value while retaining access to the native iterator. |
14+
| `ordered_containers.hpp` | `ordered_container` adds explicit sorting, lower-bound lookup, and unique sorted insertion to sequence containers. |
15+
| `set_operations.hpp` | Common-prefix, deduplication, difference, three-way diff, and order-insensitive equality algorithms. |
16+
| `std_container_helpers.hpp` | Begin/end pair macros, transparent `std::set`, and helpers selecting `push_back`/`insert` or member/linear lookup according to container capabilities. |
17+
| `tracking_allocator.hpp` | Standard allocator wrapper that reports the bytes currently allocated through that allocator instance. |
18+
| `vector2d.hpp` | Rectangular `vector<vector<T>>` helper with two-dimensional resize, row fill, width, and height. |
1019

11-
Defines `flat_map` and `flat_set`, sorted associative containers backed by vectors. `flat_map` keeps keys and mapped
12-
values in separate vectors and exposes pair-like proxy iterators with `first`/`second` and `key()`/`value()` access.
13-
Both containers support ordinary insertion, merging from a sorted range, and batched unsorted appends followed
14-
by tail sorting and merging. Existing entries and the first newly inserted entry win duplicate keys. Key equality uses
15-
`operator==` when the compared types provide it, otherwise comparator equivalence. When both operations are available,
16-
they must define the same equivalence. Batch entries are added with `append_unsorted()`; ordered operations and
17-
iteration must not be used between `begin_batch()` and `end_batch()`.
18-
Map dereference returns its proxy by value, so `auto entry` and `const auto& entry` work in range loops but `auto& entry`
19-
does not. Read-only standard algorithms and construction of ordinary pair containers are supported; algorithms that
20-
reorder entries are intentionally ill-formed because keys are immutable.
20+
## Flat associative containers
2121

22-
### iterator_helpers.hpp
22+
`flat_map` stores keys and mapped values in separate vectors and exposes pair-like proxy iterators with `first`/`second` and `key()`/`value()` access. Map dereference returns its proxy by value: `auto entry` and `const auto& entry` work in range loops, but `auto& entry` does not. Keys remain immutable, so read-only standard algorithms and construction of ordinary pair containers work while algorithms that reorder entries are intentionally ill-formed.
2323

24-
Defines two classes `const_forward_iterator_wrapper` and `forward_iterator_wrapper` that encapsulate an std (or std-compatible) iterator together with a reference to the container this iterator points to. This allows using these iterators as any other normal iterator while also being able to get the parent container from them.
24+
Both flat containers support ordinary insertion, merging a sorted range, `append_sorted_unique()`, and batched unsorted appends. Between `begin_batch()` and `end_batch()`, ordered operations and iteration are invalid. Finalization sorts only the appended tail and merges it with the existing prefix. Existing entries win conflicts with a batch, and the first batch entry wins duplicates within that batch.
2525

26-
### ordered_containers.hpp
26+
Key equality uses `operator==` when the compared types provide it and comparator equivalence otherwise. When both are available, they must describe the same equivalence relation.
2727

28-
Defines `ordered_container` class that wraps an STL-compatible container. It is intended for use with containers that aren't sorted by nature (e. g. vector or list as opposed to map or set), and provides three extra methods: `sort()`, `find(value)` and `insert_into_sorted(value)`. The `find` and `insert_into_sorted` methods require that container is sorted, and for such a container they provide optimized implementation using `std::lower_bound`. The `insert_into_sorted` method returns `std::pair<iterator, bool>` similar to the standard ordered containers.
28+
## Set operations
2929

30-
### set_operations.hpp
31-
32-
Defines a number of algorithms on containers in `SetOperations` namespace:
33-
* `OrderedSetType longestCommonStart(SupersetType<OrderedSetType> const & superset)` takes a set of ordered containers and returns the longest common starting sequence of items between all of these ordered containers.
34-
Example 1: `longestCommonStart(std::vector{std::vector<int>{1, 2, 3, 4, 5}, std::vector<int>{1, 2, 3, 10, 20}})` -> `std::vector{1, 2}`
35-
Example 2: `longestCommonStart(std::vector{std::string("Hello"), std::string("Heat"), std::string("Home")})` -> `std::string("H")`
36-
* `template <class ContainerType> ContainerType uniqueElements(const ContainerType& c)` returns only the unique items from `c`. This function is stable (item order is preserved). Has no-op overloads for `set` and `map` which may only contain unique items by definition.
37-
* `setTheoreticDifference` takes two containers `a` and `b` and an optional comparator, and returns a container of all the elements from `a` that are not in `b`.
38-
Example: `setTheoreticDifference<std::list>(std::vector<int> {1, 2, 3}, std::deque<int> {3, 1})` -> `std::list<int> {2}`
39-
It is assumed that the containers are unordered because for ordered containers `std::set_difference` can be called directly.
40-
* `calculateDiff` takes two containers `a` and `b` and an optional template argument specifying the output container type. It returns the following structure:
41-
```template <class OutputContainerType>
42-
struct Diff
43-
{
44-
OutputContainerType common_elements;
45-
OutputContainerType elements_from_a_not_in_b;
46-
OutputContainerType elements_from_b_not_in_a;
47-
};
48-
49-
### std_container_helpers.hpp
50-
51-
Defines two functions that behave differently depending on what container they're called with:
52-
* `void add_item(Container& container, const ItemType& item)` calls `push_back(item)` for containers that have push_back (ordered containers), and `insert(item)` for other (unordered) containers.
53-
* `auto container_aware_find(Container& container, const ItemType& item)` calls `container.find(item)` for containers that have a member function `find`, calls `std::find` otherwise.
54-
55-
### string_helpers.hpp
56-
57-
Defines `bool operator==(const std::string str, const char ch)` and `bool operator==(const char ch, const std::string str)` for comparing a string with to a single character.
30+
- `longestCommonStart()` returns the longest shared prefix of a container of ordered containers: `std::vector<std::string>{"Hello", "Heat", "Home"}` produces `"H"`.
31+
- `uniqueElements<ItemOrder>()` removes duplicates, optionally retaining the first or last occurrence order. The `std::set` overload is a no-op reference return.
32+
- `setTheoreticDifference<OutputContainer>()` sorts copies of two unordered inputs and returns the elements present only in the first.
33+
- `calculateDiff()` returns `common_elements`, `elements_from_a_not_in_b`, and `elements_from_b_not_in_a`.
34+
- `is_equal_sets()` compares compatible containers without regard to order; it sorts non-`std::set` inputs in place.

hash/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Hash utilities
2+
3+
Compile-time and runtime non-cryptographic hashing helpers. These functions are suitable for hash tables, identifiers, partitioning, and checks against accidental changes; they are not authentication or password-hashing primitives.
4+
5+
| Header | Facility |
6+
|---|---|
7+
| `hash_consteval.hpp` | `murmur3_32_consteval()` computes seedable MurmurHash3 x86-32 for a `std::string_view` during constant evaluation. Byte assembly is explicitly little-endian, so results are stable across host architectures. |
8+
| `mixers.h` | `mix_moremur()` avalanches one 64-bit integer, useful for finalizing or decorrelating an already assembled key. |
9+
| `wheathash.hpp` | `wheathash64()` hashes a byte range with a fixed or caller-supplied seed; `wheathash32()` truncates it to 32 bits, and `wheathash64v()` hashes an object's in-memory representation. |
10+
11+
`wheathash64v()` includes padding and uses the host object representation. Its result may therefore vary with compiler, ABI, byte order, or uninitialized padding; use the byte-range overload with an explicitly serialized representation when hashes must persist or cross process/platform boundaries.

math/README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
## A collection of arithmetic convenience functions
1+
# Math utilities
22

3-
### math.hpp
3+
`math.hpp` provides small arithmetic templates in namespace `Math`.
44

5-
Defines a number of template functions for mathematical and arithmetical operations in the `Math` namespace.
6-
7-
* `round` and `floor` functions that accept a second parameter - the number of digits after the decimal point to round or floor to.
8-
* `round`, `floor` and `ceil` functions that accept an extra template parameter for the output type which can be integer or floating-point.
9-
* `abs` function suitable both for integer and floating-point values. For integer values, it takes in to account that the opposite value for `std::numeric_limits<T>::min()` is not representable in the same type, so it truncates it to `::max()`.
10-
* `clamp(T min, T value, T max)` function template.
11-
* `signum` function template (returns -1 for negative value, 0 for zero and 1 for positive).
12-
* `squared` function template that accepts an output type that can be larger than the inputtype to fit the result reliably.
13-
* `bool isInRange(const T value, const T lowerBound, const T upperBound)` function template.
14-
* `arithmeticMean`, `geometricMean`: function templates that take a parameter pack and return the mean value of the values in the pack. Can be used to conveniently calculate the mean of 3-4-5 values.
5+
| Facility | Description |
6+
|---|---|
7+
| `round`, `floor`, `ceil` | Decimal-place rounding/flooring and typed numeric conversions for integral and floating-point inputs. |
8+
| `abs` | Integral and floating absolute value; the unrepresentable magnitude of the signed minimum is saturated to the type's maximum. |
9+
| `clamp`, `signum`, `squared`, `isInRange` | Bounds, sign, optionally widened square, and inclusive range helpers. |
10+
| `arithmeticMean`, `geometricMean` | Mean of a short value parameter pack, returned as the explicitly selected result type. |
11+
| `pow2` | Computes powers of two for positive exponents. |
12+
| `reduce` | Maps a 32-bit value into `[0, range)` using the high half of a multiply. |
13+
| `FastMod32` | Precomputes a non-zero divisor's reciprocal data so repeated 32-bit modulo operations avoid division. |

parameter_pack/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
## Helper templates for accessing and manipulating template parameter packs
1+
# Parameter-pack utilities
22

3-
### parameter_pack_helpers.hpp
3+
`parameter_pack_helpers.hpp` provides compile-time type lookup and iteration in namespace `pack`, plus the `type_pack` facade.
44

5-
* `template <typename T, typename... Args> constexpr size_t index_for_type_v` defines the index (position) of *type* T in the `Args...` pack. Results in compilation error if the type is not found.
5+
| Facility | Description |
6+
|---|---|
7+
| `type_by_index<I, Args...>` | Type at index `I`. |
8+
| `index_for_type<T, Args...>()` | Optional compile-time index of the first `T`; `index_for_type_v` is the strict form that fails compilation when absent. |
9+
| `has_type_v<T, Args...>`, `type_count<T, Args...>()` | Tests for a type and counts its occurrences. |
10+
| `first_type<Args...>` | First type in a pack. |
11+
| `value_by_index<I>(args...)` | Value at index `I`, selected during constant evaluation. |
12+
| `for_value(f, args...)` | Calls `f(value)` for every value in order. |
13+
| `for_type<Args...>(f)` | Calls `f.template operator()<T>()` once for every type. |
14+
| `type_pack<Args...>` | Exposes pack size and indexed types, finds type indices, appends types, constructs another variadic template, or converts the pack to `std::tuple`. |
615

7-
* `template <size_t index, typename... Args> using type_by_index` defines the *type* at `index` in `Args...`.
16+
```cpp
17+
pack::for_value([](const auto& value) { std::cout << value << '\n'; }, 0, -1.0f, "text");
818

9-
* `template <size_t index, typename... Args> constexpr auto value_by_index(Args&&... args) noexcept` returns the *value* at position `index` from `args`.
10-
11-
* `template <typename Functor, class... Args> void apply(Functor&& f, Args&&... args)` iterates the pack `args` and calls functor `f` with each *value* in the pack.
12-
<br>Example: `apply([](auto&& value){std::cout << value << std::endl;}, 0, -1.0f, "text");`
13-
14-
* `template <typename... Args, typename Functor> void for_type(Functor&& f)` calls functor `f` for each *type* in the argument pack. The type is passed using `type_wrapper` helper template defined in `utils/template_magic.hpp`.
15-
<br>Example: `for_type<int, float, std::string> ([](auto&& t){ using Type = typename decltype(t)::type; });`
19+
pack::for_type<int, float, std::string>([]<typename T> {
20+
static_assert(sizeof(T) > 0);
21+
});
22+
```

random/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
## Helper class for wrapping generator and distribution inside a single class.
1+
# Random-number utilities
22

3-
### randomnumbergenerator.h
3+
`randomnumbergenerator.h` combines a standard random engine and distribution behind a small integral interface.
44

5-
I find it annoying to have to explicitly declare both the generator and the distribution, so I wrapped it up in a class. Templated on value type, distribution type and generator type; has reasonable default distribution `std::uniform_int_distribution` and generator `std::mt19937_64`.
6-
5+
| Facility | Description |
6+
|---|---|
7+
| `RandomNumberGenerator<IntType, DistributionT, GeneratorT>` | Owns one generator and distribution and returns the next value through `rand()`. Defaults to `std::mt19937_64`, `std::uniform_int_distribution`, the full `IntType` range, and deterministic seed `0`. |
8+
| `RNG<IntType, minValue, maxValue, ...>` | Static `next()` facade backed by one thread-local generator per specialization. Each thread starts from seed `0`. |
9+
| `RandomChar` | `RNG<int16_t, 33, 126>` specialization for printable ASCII code points. |
10+
11+
Supply a varying seed to `RandomNumberGenerator` when reproducible output is not desired. `RNG` intentionally exposes no reseeding API.

tuple/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
## Helper templates for working specifically with std::tuple
1+
# Tuple utilities
22

3-
### tuple_helpers.hpp
3+
`tuple_helpers.hpp` provides compile-time inspection and value iteration in namespace `tuple`.
44

5-
Defines namespace `tuple`, containing the following templates:
6-
* `constexpr size_t tuple_size_v_omnivorous` is analogous to `std::tuple_size_v` but accepts types with any cv and ref qualifiers.
7-
* `indexForType` returns the index of type `T` in the given tuple; results in compilation error if type not present.
8-
* `visit` implements runtime indexing of a tuple - calls a functor the value at specified index (that need not be known at compile time) as the functor's argument. The argument can be a non-const reference for a non-const tuple, so it can mutate the tuple's items.
9-
* `for_each` calls a functor with each value from the tuple. Supports both `const` and non-`const` tuples. The argument can be a non-const reference for a non-const tuple, so it can mutate the tuple's items.
5+
| Facility | Description |
6+
|---|---|
7+
| `tuple_size_v_omnivorous<Tuple>` | `std::tuple_size_v` after removing reference qualifiers, accepting const and reference forms. |
8+
| `indexForType<T>(tuple)` | Compile-time index of `T`; fails compilation when the type is absent. |
9+
| `size(tuple)` | Compile-time tuple element count. |
10+
| `for_each(tuple, f)` | Calls `f` with every element in order, preserving tuple and element cv/ref qualifiers so a mutable tuple can be modified. |
11+
12+
```cpp
13+
std::tuple values{1, 2.0};
14+
tuple::for_each(values, []<typename T>(T& value) { value += value; });
15+
```

0 commit comments

Comments
 (0)