FlatlinerDOA.Rope 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FlatlinerDOA.Rope --version 1.0.0                
NuGet\Install-Package FlatlinerDOA.Rope -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FlatlinerDOA.Rope" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FlatlinerDOA.Rope --version 1.0.0                
#r "nuget: FlatlinerDOA.Rope, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FlatlinerDOA.Rope as a Cake Addin
#addin nuget:?package=FlatlinerDOA.Rope&version=1.0.0

// Install FlatlinerDOA.Rope as a Cake Tool
#tool nuget:?package=FlatlinerDOA.Rope&version=1.0.0                

Rope

Build Status License

NuGet downloads Size

C# implementation of a Rope<T> immutable data structure. See the paper Ropes: an Alternative to Strings: h.-j. boehm, r. atkinson and m. plass

A Rope is an immutable sequence built using a b-tree style data structure that is useful for efficiently applying and storing edits, most commonly used with strings, but any list or sequence can be efficiently edited using the Rope data structure.

Where a b-tree has every node in the tree storing a single entry, a rope contains arrays of elements and only subdivides on the edits. The data structure then decides at edit time whether it is optimal to rebalance the tree using the following heuristic: A rope of depth n is considered balanced if its length is at least Fn+2.

Note: This implementation of Rope<T> has a hard-coded upper-bound depth of 46 added to the heuristic from the paper. As this seemed to be optimal for my workloads, your mileage may vary.

Example Usage


// Converting to a Rope<char> doesn't allocate any strings (simply points to the original memory).
Rope<char> text = "My favourite text".ToRope();

// With Rope<T>, splits don't allocate any new strings either.
IEnumerable<Rope<char>> words = text.Split(' '); 

// Calling ToString() allocates a new string at the time of conversion.
Console.WriteLine(words.First().ToString()); 

// Warning: Concatenating a string to a Rope<char> converts to a string (allocating memory).
string text2 = text + " My second favourite text";

// Better: This makes a new rope out of the other two ropes, no string allocations.
Rope<char> text3 = text + " My second favourite text".ToRope();

Comparison with StringBuilder

A comparison could be drawn between a Rope and a StringBuilder as they use a very similar technique for efficient edits.

Feature Rope<T> StringBuilder
Efficient edits of strings (avoid double allocations)
Supports lists of any type
Immutable edits
Thread safe
Allocation free splitting
Zero copy concatenation of two strings
Allocation free insertion
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 91 7/28/2024
1.2.0 109 4/7/2024
1.1.1 99 4/2/2024
1.1.0 101 4/1/2024
1.0.0 98 3/30/2024