A small collection of C# utility methods and classes.
Intended for selective copy/paste rather than assembly reference.
The code here is set up as a few .NET Core projects with unit tests, so that it can be built and verified by running the test suite:
git clone https://github.com/ujr/csutils
cd csutils/src
dotnet restore
dotnet build
dotnet test
Utils
- BitUtils.cs - bit query and manipulation methods
- CappedQueue.cs - a queue (first-in-first-out) of limited capacity
- CircularBuffer.cs - like CappedQueue but with only Add() and ToArray()
- CubicBezier.cs - some operations with cubic Bezier curves
- Geodesy.cs - simple geodetic calculations like haversine distance
- ListUtils.cs - some
List<T>
methods but forIList<T>
- Pair.cs - an X,Y pair as an immutable struct with some operations
- Parsing.cs - parsing text strings (see also: Tokenizer)
- Point and Envelope - immutable (x,y) and (x0,y0,x1,y1)
- PointQuadtree.cs - a point quadtree (2D index structure)
- PriorityQueue.cs - base class for a heap-based priority queue
- ReadOnlySublist.cs - read-only view on a subrange of an
IList<T>
- Reservoir.cs - reservoir sampling (k random items from an
IEnumerable
) - RichTextBuilder.cs - writing to rich text format (RTF)
- Shuffle.cs - shuffling an
IList<T>
(rearrange in random order) - SparseBitSet.cs - fixed size bit set, suitable for sparse data
- StringUtils.cs - utilities for strings, some for rare use cases
- Tags.cs - utils and immutable type for tags
- Tokenizer.cs - separate a text into Name/Number/String/Operator tokens
- Variants.cs - expand variant notation, e.g.
ba[r|z]
to bar and baz - ZCurve.cs - interlacing two dimensions into Morton order
JSON
- JsonWriter.cs - simple API to write syntactically correct JSON
- JsonReader.cs - a low-level reader for JSON data
- JsonException.cs - used by JsonReader (but not by JsonWriter)
- Json.cs - minimalistic JSON serialization and hydratisation (dynamics)
CSV
- CsvWriter.cs - simple API to write CSV files
- CsvReader.cs - a low-level reader for CSV files
IR
- Inverted Index trials for Information Retrieval
- Boolean model, on-the-fly merging of postings lists
- README.md - notes, usage, glossary
- DocSetIterator.cs - enumerating and merging doc ID sets
- Query.cs - Boolean queries over index; query parser
CDB
A port of the Constant Database (CDB) to C#. A CDB is an on-disk associative array, mapping byte strings to byte strings, with maximum performance and minimum overhead. See CDB.md. The CDB code here is dedicated to the public domain (as is the original).
- Cdb.cs - static accessors: Get, Open, Make, Dump
- CdbFile.cs - reading a constant database
- CdbMake.cs - creating a constant database
Where available, read the XML comments in the code, and see the unit tests.
There are some general notes about tools and concepts, and details about some of the utility classes: