Skip to content

Instantly share code, notes, and snippets.

@zeux
zeux / fsc-example.fs
Created Jan 19, 2012
Patch for tuple allocation elimination for implicitly-returned formal arguments
View fsc-example.fs
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 Feb 10, 2012
array permutations
View permute.fs
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 Mar 8, 2012
pugixml header mode
View pugixml.cpp
/**
* 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 Mar 8, 2012
pugixml header mode
View pugixml.diff
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 Apr 12, 2012
MRU without linked lists
View mru.cpp
#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 Apr 12, 2012
MRU without linked lists and hash maps
View mru.cpp
#include <cstdio>
#include <cassert>
#include <vector>
#include <string>
class Mru
{
public:
Mru(size_t size): _size(size), _limit(size * size)
{
View mru.cpp
#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 Apr 12, 2012
Lightmap packing
View lmpack.fsx
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 Apr 16, 2012
MSVC10 optimization bug
View msvc10optbug.cpp
// 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 Apr 22, 2012
IDiaEnumInjectedSources
View diaenum.cs
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);