SnippySnippets
A repository for random, useful or interesting code snippets & experiments
ColoredOutput
Small utility that enables colored output on Windows consoles that might not support it natively & offers a convenient enum class for basic color representation. This allows for type safety, modularization, extensibility & avoids printing garbage when colored output is not supported.
parallel_sort.h
Sorts by splitting the input into pieces, sorting the pieces individually (and simultaneously, in parallel) and and then also merging in parallel. Relies on std::sort
and std::inplace_merge
and only manages and organizes the multithreaded work. See impl::merge_threads()
for details.
.hs, .h)
Reservoir sampling (Implementations of two algorithms for the classic problem of reservoir sampling: randomly choosing a fixed (typically, small) number k
of values from a stream of unknown size n
in O(k) space so that every value has the same probability of being sampled. This invariant holds at every point in time, regardless of the number of processed values from the stream (i.e. in the reservoir). The two algorithms are: the naive, O(n) one; and an O(k*log(n/k)) one, which is optimal for the task.
Graph, TopoSort
Topological sorting (based on depth-first search), implemented in Haskell using the State monad (and Vector-s for a small performance gain).
VectorTest
Some experiments with mutable vectors in Haskell
Cutting Stock Pattern Generator
An exercise in C++20 coroutines for lazily generating all possible patterns for the cutting stock problem one by one, from synchronous coroutines (a recursive & non-recursive one). This is generally a good approach for such problems, where a lot of permutations/combinations have to be generated, the generation is stateful (often the next combination is generated from the previous one), but we don't need to store all of them in memory at once. Uses the generators from cppcoro
as helper utilities.