Skip to content

Instantly share code, notes, and snippets.

View jrade's full-sized avatar

Johan Råde jrade

View GitHub Profile
@jrade
jrade / SpscQueue.h
Last active May 25, 2024 05:43
Fast SPSC Queue implemented with C++20 atomics
// Copyright 2024 Johan Rade (johan.rade@gmail.com)
// Distributed under the MIT license (https://opensource.org/licenses/MIT)
// Single producer single consumer queue
// Fast and simple implementation using C++20 std::atomic<T>::wait() and std::atomic<T>::notify_one()
#pragma once
#include <atomic>
#include <new>
@jrade
jrade / StringDistances.h
Created May 25, 2024 04:19
Fast and memory efficient C++ implementations of the following string distances: LCS (Longest common subsequence), Levenshtein, Damerau-Levenshtein
// Copyright 2024 Johan Rade (johan.rade@gmail.com)
// Distributed under the MIT license (https://opensource.org/licenses/MIT)
inline size_t lcsDistance(const std::string& s, const std::string& t)
{
size_t m = s.size() + 1;
size_t n = t.size() + 1;
const char* p = s.data();
const char* q = t.data();
@jrade
jrade / FastExp.h
Last active July 13, 2024 16:07
Fast approximate exponential function
// Copyright 2021 Johan Rade (johan.rade@gmail.com)
// Distributed under the MIT license (https://opensource.org/licenses/MIT)
#ifndef FAST_EXP_H
#define FAST_EXP_H
#include <cstdint>
#include <cstring>