Sunlighter.FrayedKnot 2.0.0

dotnet add package Sunlighter.FrayedKnot --version 2.0.0
                    
NuGet\Install-Package Sunlighter.FrayedKnot -Version 2.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="Sunlighter.FrayedKnot" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sunlighter.FrayedKnot" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Sunlighter.FrayedKnot" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sunlighter.FrayedKnot --version 2.0.0
                    
#r "nuget: Sunlighter.FrayedKnot, 2.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.
#:package Sunlighter.FrayedKnot@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sunlighter.FrayedKnot&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Sunlighter.FrayedKnot&version=2.0.0
                    
Install as a Cake Tool

FrayedKnot

An implementation of a Rope data structure for large string manipulation.

This library is available on NuGet.org as Sunlighter.FrayedKnot.

Purpose and Features

This library presents a class called Rope. It's designed for quick manipulation of relatively large volumes of text, especially when such manipulation consists of splitting and concatenation, which the Rope can do in logarithmic time. It uses char as its character type.

Ropes are immutable and based internally on balanced trees. The leaves of the tree contain short strings, rather than individual characters.

This particular implementation is also indexed on newlines. The implementation considers "\r" or "\n" or "\r\n" as a newline. Every node in the tree knows how many newlines are under it, making it possible to quickly find a line by its line number.

Ropes are equatable and comparable (internally using System.StringComparison.Ordinal). This is provided by an implementation of ITypeTraits<Rope> which works with the Sunlighter.TypeTraitsLib library. The type traits also provide binary serialization, consistent with the traits for other types.

Note: It used to be necessary to use Builder.Instance.AddTypeTraits to register the rope’s type traits with the Type Traits library’s builder, but since version 1.0.4, Sunlighter.TypeTraitsLib 1.1.2 is now used, and the Rope class has a ProvidesOwnTypeTraits attribute, and registration is no longer necessary.

There are utility functions in a static RopeUtility class to read a Rope from a System.IO.TextReader or a file, or to write a rope to a System.IO.TextWriter or a file.

Serialization Formats

In version 2.0.0 a new serialization format was introduced and was made the default, but the old serialization format is still available (in case you have binaries in the old format). The static property Rope.SerializationMode can be set to either RopeSerializationMode.Nodes (the new format) or RopeSerializationMode.Blocks (the old format).

The block format simply divides the rope into blocks of 16k characters (the last block may be shorter). Duplication is spelled out.

The nodes format saves the nodes as they are stored in memory. The nodes format has the advantage that, if you have two or more ropes that share nodes (or even if you have a single rope that shares nodes internally, as might be produced if you produce a Rope by concatenating copies of the same smaller Rope), the sharing is honored in the serialized file. This makes it efficient to store “undo” histories, for example.

Note, however, that the shared nodes have to be detected in the same serialization call (e.g., SerializeToBytes), which usually means you have to create the type traits for some complex data structure containing ropes, such as ImmutableList<Rope> or the like. There is no memory between serialization calls.

Rope Annotation Lists

Sometimes it is helpful to keep data associated with positions in the rope. If data is inserted into the middle of the rope, the associated data must be kept with its text, even though the position of that text has changed.

For that purpose, in version 2.0.0 an immutable RopeAnnotationList<T> type was introduced. It keeps items of type T at given positions, and it is possible to insert or delete space, causing items to be moved.

It is possible to keep a Rope synchronized with an instance of RopeAnnotationList<T> and thereby have data associated with points in the Rope. (This must be done manually.)

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0 106 1/6/2026
1.0.5 411 11/20/2025
1.0.4 209 5/27/2025
1.0.3 298 5/15/2025
1.0.2 188 5/5/2025
1.0.1 227 4/20/2025
1.0.0 252 4/18/2025