Skip to content

Instantly share code, notes, and snippets.

View yhafri's full-sized avatar

Younès HAFRI yhafri

  • Switzerland
View GitHub Profile
@yhafri
yhafri / FastEditDistanceCandidates.cpp
Created June 21, 2020 09:41 — forked from markpapadakis/FastEditDistanceCandidates.cpp
From input string, identify all strings within a specific edit distance from it - based on deletions only.
// Compile list of tokens based on deletions, and respecting max edit distance
// Original implementation would concatenate left/right string segments using memcpy() etc, but that didn't seem right
// The idea is, to instead partition S into 1+ segments and build hash from them, no need for memory copies etc.
// This is almost x8 times faster compared to that - but it's still in the 10s of microseconds range.
//
// ( for a 31 characters long string, with max edit distance = 2, it takes 24 microseconds, including the cost for computing the FNV rolling hash )
#include <switch.h>
#include <switch_print.h>
#include <ansifmt.h>
static uint8_t DigitsCount(uint64_t v)
{
for (uint8_t res{1}; ;res+=4, v/=10000U)
{
if (likely(v < 10)) return res;
if (likely(v < 100)) return res + 1;
if (likely(v < 1000)) return res + 2;
if (likely(v < 10000)) return res + 3;
}
}
@yhafri
yhafri / simpleStacklessCorosActors.cpp
Created June 21, 2020 09:43 — forked from markpapadakis/simpleStacklessCorosActors.cpp
A very simple (first take) implementation of stack-less coroutines/actors
// https://gist.github.com/markpapadakis/8dba5c480c13b12a056e (example)
// https://medium.com/@markpapadakis/high-performance-services-using-coroutines-ac8e9f54d727
#include <switch.h>
#include <switch_print.h>
#include <switch_ll.h>
#include <switch_bitops.h>
#include <md5.h>
#include <text.h>
#include <network.h>
@yhafri
yhafri / minipool.hpp
Created June 29, 2020 06:08 — forked from rofirrim/minipool.hpp
Very simple memory pool
#ifndef MINIPOOL_H
#define MINIPOOL_H
#include <cassert>
#include <cstddef>
#include <memory>
#include <new>
#include <utility>
/*