ktsu.Containers 1.0.8-pre.1

ktsu.Containers

A high-performance collection library for .NET providing specialized container implementations with focus on performance, memory efficiency, and developer experience.

🚀 Features

  • OrderedCollection: Maintains elements in sorted order with efficient binary search operations
  • OrderedSet: Unique elements maintained in sorted order with full ISet support
  • RingBuffer: Fixed-size circular buffer optimized for streaming data scenarios
  • Comprehensive Benchmarking: World-class performance validation against .NET collections

📦 Collections

OrderedCollection

A collection that maintains elements in sorted order with efficient insertion and search operations.

Key Features:

  • O(log n) insertion maintaining sort order
  • O(log n) search operations via binary search
  • Multiple constructors with capacity and comparer support
  • Implements ICollection, IReadOnlyCollection, IReadOnlyList

Best Use Cases:

  • Incremental sorted data building
  • Frequent search operations on ordered data
  • Scenarios requiring both order and random access

OrderedSet

A set implementation that maintains unique elements in sorted order.

Key Features:

  • O(log n) Add/Remove/Contains operations
  • Full ISet interface support (Union, Intersection, Except, etc.)
  • Sorted enumeration without additional sorting cost
  • Memory-efficient list-based implementation

Best Use Cases:

  • Unique sorted collections
  • Set operations with maintained order
  • Mathematical set operations with sorted results

RingBuffer

A fixed-size circular buffer optimized for continuous data streams.

Key Features:

  • O(1) insertion and access operations
  • Automatic wrapping when capacity is reached
  • Index-based access to buffer elements
  • Resizing and resampling capabilities
  • Power-of-two sizing for optimal performance

Best Use Cases:

  • Streaming data processing
  • Fixed-size caches
  • Sliding window algorithms
  • Audio/signal processing buffers

🏆 Performance & Benchmarking

We've implemented a comprehensive benchmarking system using BenchmarkDotNet that validates our implementations against standard .NET collections.

Benchmark Categories

🎯 Container-Specific Benchmarks

  • OrderedCollection vs List + Sort vs SortedList
  • OrderedSet vs HashSet vs SortedSet
  • RingBuffer vs Queue vs List with size limiting

📊 Standard Collection Baselines

Performance baselines for all major .NET collections:

  • List, HashSet, SortedSet
  • Dictionary<TKey,TValue>, SortedDictionary<TKey,TValue>
  • Queue, Stack
  • ConcurrentDictionary<TKey,TValue>, ConcurrentQueue

🔄 Cross-Collection Comparisons

Direct comparisons for common scenarios:

  • Building ordered collections (incremental vs bulk)
  • Set operations across different implementations
  • Memory efficiency patterns
  • Real-world usage workflows

📈 Performance Analysis

Advanced scenarios including:

  • Scalability testing (1K to 100K+ elements)
  • Edge cases and worst-case scenarios
  • Memory pressure analysis
  • Specialized use cases (sliding windows, priority queues)

Running Benchmarks

Quick Start

# Fast development feedback
.\scripts\run-benchmarks.ps1 -Target Quick

# Compare specific containers
.\scripts\run-benchmarks.ps1 -Target OrderedSet -Export Html

# Cross-collection analysis
.\scripts\run-benchmarks.ps1 -Target CrossComparison -Export All

# Full benchmark suite
.\scripts\run-benchmarks.ps1 -Target All -Export Html

Available Targets

Target Description
Quick Fast subset for development feedback
OrderedCollection OrderedCollection vs alternatives
OrderedSet OrderedSet vs alternatives
RingBuffer RingBuffer vs alternatives
Standard Built-in .NET collection baselines
CrossComparison Direct cross-collection comparisons
PerformanceAnalysis Scalability and edge case analysis
All Complete benchmark suite

Command Line Options

# Manual benchmark execution
dotnet run --project Containers.Benchmarks --configuration Release

# Filtered benchmarks
dotnet run --project Containers.Benchmarks --configuration Release -- --filter "*Add*"

# Export results
dotnet run --project Containers.Benchmarks --configuration Release -- --exporters html,csv,json

📋 Installation

<PackageReference Include="ktsu.Containers" Version="1.0.0" />

🔧 Usage Examples

OrderedCollection

// Create and populate
var collection = new OrderedCollection<int>();
collection.Add(3);
collection.Add(1);
collection.Add(2);
// Collection automatically maintains order: [1, 2, 3]

// Efficient search
bool contains = collection.Contains(2); // O(log n) binary search

// Access by index
int first = collection[0]; // 1

OrderedSet

// Create with initial data
var set = new OrderedSet<int> { 3, 1, 4, 1, 5 };
// Set contains unique elements in order: [1, 3, 4, 5]

// Set operations
var other = new OrderedSet<int> { 4, 5, 6 };
set.UnionWith(other); // [1, 3, 4, 5, 6]

RingBuffer

// Create fixed-size buffer
var buffer = new RingBuffer<int>(3);
buffer.PushBack(1);
buffer.PushBack(2);
buffer.PushBack(3);
buffer.PushBack(4); // Overwrites first element
// Buffer contains: [2, 3, 4]

// Index access
int latest = buffer[buffer.Count - 1]; // 4 (most recent)

🛠️ Development

Building

dotnet build

Testing

dotnet test

Benchmarking

# Quick performance check
.\scripts\run-benchmarks.ps1 -Target Quick

# Comprehensive analysis
.\scripts\run-benchmarks.ps1 -Target All -Export Html

📊 Performance Characteristics

OrderedCollection

  • Excellent for: Incremental sorted insertions, frequent searches
  • ⚠️ Consider alternatives for: Large bulk operations (List + Sort may be faster)
  • 🎯 Sweet spot: 100-10,000 elements with mixed insert/search operations

OrderedSet

  • Excellent for: Unique sorted collections, set operations with order
  • ⚠️ Consider alternatives for: Pure membership testing (HashSet is faster)
  • 🎯 Sweet spot: Mathematical set operations requiring sorted results

RingBuffer

  • Excellent for: Streaming data, fixed-size caches, sliding windows
  • ⚠️ Consider alternatives for: Dynamic growth requirements
  • 🎯 Sweet spot: Continuous data streams with occasional random access

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add comprehensive tests
  5. Run benchmarks to validate performance
  6. Submit a pull request

Adding New Containers

When adding new containers:

  1. Implement the container in Containers/
  2. Add comprehensive tests in Containers.Test/
  3. Create benchmark comparisons in Containers.Benchmarks/
  4. Update documentation

📝 License

Licensed under the MIT License. See LICENSE.md for details.

🏗️ Architecture

The library is built with performance and reliability in mind:

  • Zero-allocation operations where possible
  • Power-of-two sizing for optimal memory access patterns
  • Binary search algorithms for O(log n) performance
  • Comprehensive test coverage ensuring reliability
  • Benchmark-driven development validating performance claims

🎯 Design Principles

  1. Performance First: Every operation is optimized for speed and memory efficiency
  2. Standard Compliance: Full compatibility with .NET collection interfaces
  3. Predictable Behavior: Clear performance characteristics and edge case handling
  4. Developer Experience: Intuitive APIs with comprehensive documentation
  5. Validation: Extensive testing and benchmarking ensures reliability

This library provides high-performance alternatives to standard .NET collections while maintaining familiar APIs and adding specialized functionality for common use cases.

Showing the top 20 packages that depend on ktsu.Containers.

Packages Downloads
Containers.Benchmarks
Package Description
21

## v1.0.8-pre.1 (prerelease) Changes since v1.0.7: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.7 (patch) Changes since v1.0.6: - "Claude Code Review workflow" ([@matt-edmondson](https://github.com/matt-edmondson)) - "Claude PR Assistant workflow" ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.7-pre.1 (prerelease) Incremental prerelease update. ## v1.0.6 (patch) Changes since v1.0.5: - Fix multi-targeting build errors and add framework polyfills ([@matt-edmondson](https://github.com/matt-edmondson)) - Update project configuration and dependencies ([@matt-edmondson](https://github.com/matt-edmondson)) - Enhance project configuration and workflows ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.5 (patch) Changes since v1.0.4: - Add script to automate winget manifest updates ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.4 (patch) Changes since v1.0.3: - Update project configuration and dependencies ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.3 (patch) Changes since v1.0.2: - Enhance ktsu.Containers with new benchmarks and tests ([@matt-edmondson](https://github.com/matt-edmondson)) - Fix IDE0052 errors by removing unused private members in derived cursor rules ([@matt-edmondson](https://github.com/matt-edmondson)) - Add new collection types and update documentation ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor RingBuffer to improve efficiency and documentation ([@matt-edmondson](https://github.com/matt-edmondson)) - Add OrderedMap and its benchmarks to ktsu.Containers ([@matt-edmondson](https://github.com/matt-edmondson)) - Fix compilation errors in ContiguousSetBenchmarks and improve collection initialization ([@matt-edmondson](https://github.com/matt-edmondson)) - Fix compilation errors and improve tests in collection classes ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor collection classes to use properties for Count ([@matt-edmondson](https://github.com/matt-edmondson)) - Implement equality logic and XML documentation for ContiguousMap.Entry ([@matt-edmondson](https://github.com/matt-edmondson)) - Add OrderedSet and benchmarking framework for ktsu.Containers ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.2 (patch) Changes since v1.0.1: - Add configuration files and implement new features ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.2-pre.2 (prerelease) Changes since v1.0.2-pre.1: - Sync .gitattributes ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .mailmap ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .runsettings ([@ktsu[bot]](https://github.com/ktsu[bot])) - Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.2-pre.1 (prerelease) Incremental prerelease update. ## v1.0.1 (patch) Changes since v1.0.0: - Add Clear method to RingBuffer and update documentation ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.0 (major) - Remove locking to simplify, I can make a concurrent one if I need that ([@matt-edmondson](https://github.com/matt-edmondson)) - Code chaneg to force a build ([@matt-edmondson](https://github.com/matt-edmondson)) - Improve tag handling in Get-VersionInfoFromGit function ([@matt-edmondson](https://github.com/matt-edmondson)) - Reset licence file ([@matt-edmondson](https://github.com/matt-edmondson)) - Initial Commit ([@matt-edmondson](https://github.com/matt-edmondson)) - Update SDK versions and enhance documentation tags ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor locking mechanism in RingBuffer class ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor PSBuild.psm1 to improve array handling ([@matt-edmondson](https://github.com/matt-edmondson)) - Enhance documentation and update project files ([@matt-edmondson](https://github.com/matt-edmondson)) - Rename from collections to containers, and implement standard interfaces ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor tag handling and error management in PSBuild.psm1 ([@matt-edmondson](https://github.com/matt-edmondson)) - Enhance versioning logic in PSBuild.psm1 ([@matt-edmondson](https://github.com/matt-edmondson)) - Add tests and constructors for RingBuffer functionality ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor RingBuffer class and add unit tests ([@matt-edmondson](https://github.com/matt-edmondson)) - Rename library from ktsu.Collections to ktsu.Containers ([@matt-edmondson](https://github.com/matt-edmondson))

.NET 5.0

  • No dependencies.

.NET 6.0

  • No dependencies.

.NET 7.0

  • No dependencies.

.NET 8.0

  • No dependencies.

.NET 9.0

  • No dependencies.

.NET Standard 2.0

.NET Standard 2.1

Version Downloads Last updated
1.0.8-pre.3 18 11/24/2025
1.0.8-pre.2 14 11/23/2025
1.0.8-pre.1 14 11/23/2025
1.0.7 15 11/23/2025
1.0.7-pre.1 13 11/23/2025
1.0.6 14 11/23/2025