Skip to content

Instantly share code, notes, and snippets.

@nshibano
nshibano / MeasuredTreeList.cs
Last active June 28, 2017 19:37
Immutable tree list implemented in C#. This is join operation based AVL tree. So that it supports fast bulk operations such as GetRange, AddRange, PushRange, RemoveRange, InsertRange and Concat. Plus, it has 'measure' field in nodes to store user-defined, bottom-up updated sub-tree property such as min, max, count, sum or stddev, or tuple of them.
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain.We make this dedication for the benefit
@nshibano
nshibano / CountLeadingZeros.fs
Last active July 17, 2017 09:58
Count leading zeros of uint32 in F#
let inline leading_zeros_of_ls4b_of_uint32 x =
match x with
| 0b0000u -> 4
| 0b0001u -> 3
| 0b0010u -> 2
| 0b0011u -> 2
| 0b0100u -> 1
| 0b0101u -> 1
| 0b0110u -> 1
| 0b0111u -> 1
@nshibano
nshibano / IReadOnlyListExtensions.fs
Last active July 18, 2017 09:22
IReadOnlyList extensions
open System
open System.Collections.Generic
[<AutoOpen>]
module Extensions =
type IReadOnlyList<'T> with
static member Append(a : IReadOnlyList<'T>, b : IReadOnlyList<'T>) =
{ new IReadOnlyList<'T> with
member this.Count = a.Count + b.Count
member this.Item with get i = if i < a.Count then a.[i] else b.[i - a.Count]
using System.Text;
namespace StringEscape
{
public static class StringEscape
{
public static string Escape(string input)
{
var sb = new StringBuilder();
//sb.Append("\"");