Skip to content

Instantly share code, notes, and snippets.

@kaja47
kaja47 / RadixQuicksort.scala
Created April 4, 2016 22:01
Three-way radix quicksort
import java.util.Arrays
// Three-way radix quicksort aka Multi-key quicksort
//
// Fast Algorithms for Sorting and Searching Strings
// http://www.cs.princeton.edu/~rs/strings/paper.pdf
object RadixQuicksort {
def sort(arr: Array[String]) =
@kaja47
kaja47 / burst.scala
Created April 2, 2016 23:22
quick and dirty sketch of burstsort
import java.util.Arrays
// BurstSort
// Cache-Conscious Sorting of Large Sets of Strings with Dynamic Tries
// http://goanna.cs.rmit.edu.au/~jz/fulltext/alenex03.pdf
class BurstLeaf(initSize: Int) {
var size: Int = 0
@kaja47
kaja47 / jacc.c
Created October 5, 2015 21:28
jaccard similarity using AVX2 SIMD
#include <stdio.h>
#include <immintrin.h>
#include <stdint.h>
int intersectionSize(int* a, const int alen, int* b, const int blen) {
int ai = 0, bi = 0, size = 0;
while (ai < alen && bi < blen) {
int av = a[ai];
int bv = b[bi];
size += ((av == bv) ? 1 : 0);
// size = (1 << 25), time = 800 ms
// size = (1 << 25) - 1999, time = 400 ms ???
// size = (1 << 24), time = 700 ms
val size = 1 << 25
val randos = new util.Random()
val arr = Array.fill(size)(randos.nextInt)
java.util.Arrays.sort(arr)
@kaja47
kaja47 / StringIntDictionary.scala
Created August 10, 2015 03:08
StringIntDictionary
/** Idiosyncratic dictionary mapping strings to ints specialized for english
* words and other short alphanumeric strings. Long strigns are packed into
* one continuous char array, short alphanumeric strings are inlined into the
* structure that normally points into the array of long strings. This has the
* effect that strings shorter than 9 characters need only 12 bytes per mapping
* and lookup causes only one cache miss.
*
* Warning: Might contains subtle and not-so-soubtle errors.
*/
class StringIntDictionary {
@kaja47
kaja47 / 1nn.c
Last active August 29, 2015 14:26
nearest neighbor
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <immintrin.h>
#include "sys/param.h"
@kaja47
kaja47 / lol.php
Last active August 29, 2015 14:23
PHP polymorphic inline caches
<?php
class A {
public $somePropertyWithReasonablyLongName = 1;
}
class B {
public $somePropertyWithReasonablyLongName = 1;
}
@kaja47
kaja47 / sepukku.scala
Created May 5, 2015 16:31
sudoku solver
val boardStr = """
53 7 |
6 195 |
98 6 |
8 6 3|
4 8 3 1|
7 2 6|
6 28 |
419 5|
8 79|
@kaja47
kaja47 / gist:fd426c8c21ddb07bb617
Last active August 29, 2015 14:17
PHP puzzler
$size = 512*1024;
$keys = range(1, $size);
//shuffle($keys);
$arr = [];
foreach ($keys as $k) {
$arr[$k] = $k;
}
$s = microtime(1);
try {
throw new Exception("E2")
} catch {
case ex: Exception if ex.getMessage == "E1" =>
println("caught E1")
case ex: Exception if ex.getMessage == "E2" =>
println("caught E2")
}