Skip to content

Instantly share code, notes, and snippets.

@zeux
zeux / fsc-example.fs
Created January 19, 2012 06:39
Patch for tuple allocation elimination for implicitly-returned formal arguments
module Test
open System.Collections.Generic
open SlimDX.DXGI
open SlimDX.Direct3D11
let test2 (d: IDictionary<int, string>) key =
// tuple is allocated here, unless the patch is applied
let r, v = d.TryGetValue(key)
if r then v else ""
@zeux
zeux / permute.fs
Created February 10, 2012 00:15
array permutations
let permute (a: 'a array) =
let swap a i j = Array.permute (fun idx -> if idx = i then j else if idx = j then i else idx) a
let rec p a i = seq {
if i >= Array.length a then yield a
else for j=i to a.Length-1 do yield! p (swap a i j) (i + 1) }
p a 0
@zeux
zeux / pugixml.cpp
Created March 8, 2012 06:28
pugixml header mode
/**
* pugixml parser - version 1.0
* --------------------------------------------------------
* Copyright (C) 2006-2010, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* Report bugs and download new versions at http://pugixml.org/
*
* This library is distributed under the MIT License. See notice at the end
* of this file.
*
* This work is based on the pugxml parser, which is:
@zeux
zeux / pugixml.diff
Created March 8, 2012 06:41
pugixml header mode
13a14,16
> #ifndef SOURCE_PUGIXML_CPP
> #define SOURCE_PUGIXML_CPP
>
39a43
> # pragma warning(push)
48a53
> # pragma warning(push)
55a61
> # pragma option push
@zeux
zeux / mru.cpp
Created April 12, 2012 08:53
MRU without linked lists
#include <cstdio>
#include <cassert>
#include <vector>
#include <string>
#include <unordered_set>
class Mru
{
public:
Mru(size_t size): _size(size), _limit(size * 2)
@zeux
zeux / mru.cpp
Created April 12, 2012 09:19
MRU without linked lists and hash maps
#include <cstdio>
#include <cassert>
#include <vector>
#include <string>
class Mru
{
public:
Mru(size_t size): _size(size), _limit(size * size)
{
@zeux
zeux / mru.cpp
Created April 12, 2012 10:16
MRU NIH
#include <new>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
class Mru
{
public:
Mru(size_t size): _size(0), _capacity(size), _buckets(nullptr), _bucketCount(size * 2), _first(nullptr), _last(nullptr)
@zeux
zeux / lmpack.fsx
Created April 12, 2012 21:53
Lightmap packing
type LM = LM of int * int
let lmgs =
[
[
LM (128, 512)
LM (512, 512)
LM (128, 512)
LM (256, 256)
LM (64, 64)
@zeux
zeux / msvc10optbug.cpp
Created April 16, 2012 19:29
MSVC10 optimization bug
// cl 16.00.40219.01 for 80x86
// Compile with /O2:
// pData - slcControlFlags = 48
// Assertion failed: (pData - slcControlFlags) == sizeof(slcControlFlags), file msvc10optbug.cpp, line 46
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
const size_t kSlcSizeWithoutBoneArray = 96;
@zeux
zeux / diaenum.cs
Created April 22, 2012 22:33
IDiaEnumInjectedSources
public interface IDiaEnumInjectedSources
{
int count;
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType =
"System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")]
IEnumerator GetEnumerator();
IDiaInjectedSource Item(uint index);
void Next(uint celt, out IDiaInjectedSource rgelt, out uint pceltFetched);