Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <iomanip>
#include <chrono>
// Use it with | sort -n | grep -P 'CLK[01]'
namespace
{
void displayDuration(const std::chrono::nanoseconds duration)
{
#ifndef __VISITOR_HPP__
#define __VISITOR_HPP__
template<typename... Types>
struct Visitor;
template<typename... Visitors>
struct Visitable;
template<typename T>
@matovitch
matovitch / pickset.hpp
Last active April 6, 2022 17:33
container with O(1) insertion, deletion, and pick random
#include <vector>
#include <random>
#include <cstddef>
#include <functional>
#include <unordered_set>
template <typename T, typename H = std::hash<T> >
struct Hasher
{
std::size_t operator()(const T* const pt) const
#include <iostream>
#include <cstdint>
#include <vector>
#include <queue>
#include <list>
template <class SizeType, uint8_t MIN_LOG_INDEX, uint8_t BALANCE_LOG_RATIO, class Type>
struct TIndexedList
{
using Iterator = typename std::list<Type>::iterator;
What is math concretely?
From the outside, it resembles a group of people talking to each other. The theme of the discussion loosely depends on what was said before and no one really knows how it all started.
You can join in if you want but you will need to speak some dialect first. An implicit algorithm is used such that the people can agree on the validity of what is being said.
Some people have started to translate the discussion from the original set of evolving dialects into programming languages. In this new setting, the implicit algorithm can be made explicit and the translation checked mechanically. If no mistake is found in the algorithm or in the translation, we can be confident that what was said is indeed valid.
Given such an explicit algorithm and a complete enough record of the discussion, we could store a full verified translation. But this translation would be fairly redundant and we could try to compress it. Doing so, we would see that the bytes with the highest compression ratio would ma
{
"node": "Program",
"functions": [
{
"node": "Function",
"name": {
"node": "Identifier",
"lexeme": {
"node": "Lexeme",
"index": 42
#include <iostream>
#include <vector>
namespace node
{
enum class Kind
{
PROGRAM,
#include <iostream>
namespace type_flag
{
template <class TypeFlag, class Type>
using THas = std::enable_if_t<std::is_base_of_v <TypeFlag, std::decay_t<Type>>, int>;
template <class TypeFlag, class Type>
using THasNot = std::enable_if_t<std::negation_v<std::is_base_of<TypeFlag, std::decay_t<Type>>>, int>;
@matovitch
matovitch / btf.cpp
Last active November 8, 2019 13:08
#include <algorithm>
#include <iostream>
#include <cstdint>
#include <vector>
#include <array>
constexpr int log2(int x)
{
return x < 2 ? x : 1 + log2(x >> 1);
}
#include <iostream>
#include <cstdint>
#include <vector>
namespace tree
{
template <class Type>
struct TNode
{