Skip to content

Instantly share code, notes, and snippets.

View r-lyeh-archived's full-sized avatar

r-lyeh-archived

View GitHub Profile
@r-lyeh-archived
r-lyeh-archived / tags.hpp
Created August 24, 2015 09:48
tags server with trigrams
// Tags server with trigrams
// r-lyeh, public domain
// [ref] https://swtch.com/~rsc/regexp/regexp4.html
// [ref] http://mattwarren.org/2015/08/19/the-stack-overflow-tag-engine-part-2/
#pragma once
#include <iostream>
#include <cassert>
#include <algorithm>
@r-lyeh-archived
r-lyeh-archived / circ.hpp
Created August 21, 2015 11:39
circular buffer
// very simple circular buffer
// - rlyeh, public domain
#include <vector>
template<typename T, unsigned N>
struct circ {
static_assert( ((N != 0) && !(N & (N - 1))), "\n\n"
"N should be power of two because:\n"
@r-lyeh-archived
r-lyeh-archived / track.hpp
Created July 31, 2015 08:46
Manager to track and record all live instances of any trackable class
/* Manager to track and record all live instances of any trackable class,
* thru trackable<class>::begin()/end() iterators.
* Copyright (c) 2011-2015 Mario 'rlyeh' Rodriguez.
* zlib/libpng licensed.
* Usage:
*
* Always derive from trackable<T> first.
*
@r-lyeh-archived
r-lyeh-archived / pcode.c
Last active February 23, 2022 00:01
pcode interpreter
/*
P-code for PL/0 machine
[ref] https://en.wikipedia.org/wiki/P-code_machine
[ref] http://blackmesatech.com/2011/12/pl0/pl0.xhtml
The PL/0 virtual machine was originally specified by Nicklaus Wirth in his book
Algorithms + Data Structures = Programs; it's used as the target machine for a
PL/0 compiler.
// :)
// http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20
@r-lyeh-archived
r-lyeh-archived / gc.cpp
Last active March 8, 2023 11:59
C++ Garbage Collection
/*/
C++ Garbage Collection Library
==============================
This is a library to manage memory in C++ programs using a garbage
collector. It uses a mark and sweep algorithm.
All objects that are to be managed by the collector should be derived
from GCObject:
/*
Delta Compression by Glenn Fiedler.
This source code is placed in the public domain.
http://gafferongames.com/2015/03/14/the-networked-physics-data-compression-challenge/
*/
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
@r-lyeh-archived
r-lyeh-archived / distance.cc
Created June 30, 2015 15:20
point-to-point distance algorithms survey
// point-to-point distance algorithms survey
// - rlyeh, public domain.
// possible output {
// manhattan_distance: 0.608632s. (result: 6)
// octagonal_distance: 0.651783s. (result: 3.52249)
// baptista_distance: 1.10458s. (result: 4.79492)
// baptista_distance_b: 1.09981s. (result: 4.64063)
// euclidean_distance: 1.25s. (result: 4.47214)
// euclidean_distance_fast: 1.03207s. (result: 4.5)
@r-lyeh-archived
r-lyeh-archived / intern.cpp
Created June 26, 2015 11:56
c++ string interning
// l@loup-vaillant.fr
#pragma once
#include <vector>
#include <string>
#include <stdlib.h>
class Intern {
public:
@r-lyeh-archived
r-lyeh-archived / spinlock.hpp
Last active August 29, 2015 14:23
spinlock c++03/c++11
// spinlock c++03/c++11. based on code by Panagiotis Christopoulos Charitos
// - rlyeh ~~ public domain
#pragma once
#if __cplusplus >= 201103L
// c++11 version
#include <atomic>
class SpinLock