Skip to content

Instantly share code, notes, and snippets.

@erdomke
erdomke / SigFigFormatProvider.cs
Last active March 16, 2017 00:22
Formats a number to a specific number of significant digits
using System;
using System.Globalization;
public static class FormatExtensions
{
public static string ToPrecision(this int value, int digits, string format = "")
{
return SigFigFormatProvider.Instance.Format("s" + digits.ToString() + format, value, null);
}
public static string ToPrecision(this double value, int digits, string format = "")
@erdomke
erdomke / TstDictionary.cs
Created October 5, 2016 19:04
C# Ternary Search Tree Dictionary
// Ternary Search Tree Implementation for C#
//
// Rewritten by Eric Domke
//
// Code adapted from implementation by Jonathan de Halleux
// at http://www.codeproject.com/Articles/5819/Ternary-Search-Tree-Dictionary-in-C-Faster-String
//
// Rewrite focused on
// - removing fields from the TstDictionaryEntry class to reduce memory usage
// - decreasing the number of nodes to reduce memory usage (used some of the