This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [ref] http://en.wikipedia.org/wiki/Splay_tree | |
#include <functional> | |
#ifndef SPLAY_TREE | |
#define SPLAY_TREE | |
template< typename T, typename Comp = std::less< T > > | |
class splay_tree { | |
private: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "License": Public Domain | |
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like. | |
#ifndef PORTABLE_ENDIAN_H__ | |
#define PORTABLE_ENDIAN_H__ | |
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) | |
# define __WINDOWS__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple every() function | |
// - rlyeh. mit licensed | |
// @todo: during, in, when, | |
#pragma once | |
#include <map> | |
#ifdef EVERY_USE_OMP | |
#include <omp.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// when/unless go/unless keywords | |
// - rlyeh | |
#include <functional> | |
#include <iostream> | |
#define when(...) for( std::function<void()> fn; !fn && (__VA_ARGS__ +0); fn() ) fn = [&] | |
#define unless(...) , !(__VA_ARGS__) ? fn : fn = [&] | |
#define go when(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scheme Interpreter in 90 lines of C++ (not counting lines after the first 90). | |
// Inspired by Peter Norvig's Lis.py. | |
// Made by Anthony C. Hay in 2010. See http://howtowriteaprogram.blogspot.co.uk/ | |
// This is free and unencumbered public domain software, see http://unlicense.org/ | |
// This code is known to have faults. E.g. it leaks memory. Use at your own risk. | |
#include <iostream> | |
#include <sstream> | |
#include <string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rem 'cos I always forget how to do it | |
boostrap.bat | |
.\bjam2 runtime-link=static --with-serialization --toolset=msvc-11 && :: vs2012 | |
.\bjam2 runtime-link=static --with-serialization --toolset=msvc-12.0 && :: vs2013, also: architecture=x86 address-model=64 | |
rem also, extracting a lib: | |
bjam tools\bcp | |
dist\bin\bcp.exe algorithm/string.hpp [outdir] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a few color space conversions in c++11, original code by mjijackson.com | |
// - rlyeh, public domain licensed. | |
#include <tuple> | |
#include <algorithm> | |
#include <stdint.h> | |
std::tuple<float,float,float> rgb2hsv(float r, float g, float b) { // ranges: input[0..255], output[0..1] | |
r = r/255, g = g/255, b = b/255; | |
float max = std::max(std::max(r, g), b), min = std::min(std::min(r, g), b), d = max - min; | |
float h, s = max > 0 ? d / max : 0, v = max; | |
if( max != min ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// downscale large textures | |
if (img.w > 512 || img.h > 512) { | |
// calculate factor shrink | |
float factor = std::max(img.w, img.h) / 512; | |
// downscale | |
for (unsigned y = 0, h = img.h / factor; y < h; ++y) { | |
for (unsigned x = 0, w = img.w / factor; x < w; ++x) { | |
img[x + y * w] = img[x * factor + y * factor * img.w]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credits? | |
template<typename T> | |
T clamp(const T& value, const T& min, const T& max) { | |
return min < max | |
? (value < min ? min : value > max ? max : value) | |
: (value < max ? max : value > min ? min : value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credits? | |
static unsigned char reverse8(unsigned char v) { | |
return (v * 0x0202020202ULL & 0x010884422010ULL) % 1023; | |
} |
OlderNewer