SplayTree 3.2.30
dotnet add package SplayTree --version 3.2.30
NuGet\Install-Package SplayTree -Version 3.2.30
<PackageReference Include="SplayTree" Version="3.2.30" />
<PackageVersion Include="SplayTree" Version="3.2.30" />
<PackageReference Include="SplayTree" />
paket add SplayTree --version 3.2.30
#r "nuget: SplayTree, 3.2.30"
#:package SplayTree@3.2.30
#addin nuget:?package=SplayTree&version=3.2.30
#tool nuget:?package=SplayTree&version=3.2.30

SplayTree port to F#
This fork is a careful port of w8r/splay-tree to F#. See FSharp/README.md for details on the port, tests and benchmarks.
To use this library in F# you may just copy this one file into your project: SplayTree.fs
or use it via NuGet:
API
The library lives in the SplayTree namespace. The two main types are Node<'Key,'Value> and Tree<'Key,'Value>.
Tree<'Key,'Value>([comparer]), wherecompareris an optional'Key -> 'Key -> intfunctiontree.Insert(key:'Key, [data:'Value]):Node- Insert item, allow duplicate keystree.Add(key:'Key, [data:'Value]):Node- Insert item if it is not presenttree.Remove(key:'Key)- Remove itemtree.Find(key:'Key):Node|null- Return node by its keytree.FindStatic(key:'Key):Node|null- Return node by its key (doesn't re-balance the tree)tree.At(index:int):Node|null- Return node by its index in sorted order of keystree.Contains(key:'Key):bool- Whether a node with the given key is in the treetree.ForEach(visitor:Node -> bool option):Tree- In-order traversaltree.Keys():'Key array- Returns the array of keys in ordertree.Values():'Value array- Returns the array of data fields in ordertree.Range(low:'Key, high:'Key, fn:Node -> bool option):Tree- Walks the range of keys in order. Stops if the visitor function returnsSome truetree.Pop():TreeItem<'Key,'Value> option- Removes and returns the smallest nodetree.Min():'Key option- Returns min keytree.Max():'Key option- Returns max keytree.MinNode():Node- Returns the node with smallest keytree.MaxNode():Node- Returns the node with highest keytree.Prev(node:Node):Node|null- Predecessor nodetree.Next(node:Node):Node|null- Successor nodetree.Update(key:'Key, newKey:'Key, [newData:'Value])- Change a key (and optionally its data) in the treetree.Load(keys:'Key array, [values:'Value array], [presort:bool]):Tree- Bulk-load items. It expects keys and values to be sorted, but ifpresortistrue, it will sort them using the comparer (in-place, your arrays will be altered)tree.Clear():Tree- Remove all nodestree.IsEmpty():bool- Whether the tree is emptytree.Split(key:'Key):SplitResult- Split tree around key into{ left; right }tree.ToString([printNode:Node -> string]):string- ASCII tree diagramtree.Size:int- Number of nodes in the treetree.Root:Node- Root node (nullable)
The tree also implements IEnumerable<Node<'Key,'Value>> so you can use for … in tree or pipe it into Seq functions.
Comparer
'Key -> 'Key -> int - Comparer function between two keys, it returns
0if the keys are equal< 0ifa < b> 0ifa > b
The default comparer uses System.Collections.Generic.Comparer<'Key>.Default.
Visitor
Node<'Key,'Value> -> bool option - Used by ForEach and Range. Return None to continue, Some true to stop iteration early.
Duplicate keys
Insert()method allows duplicate keys. This can be useful in certain applications (example: overlapping points in 2D).Add()method will not allow duplicate keys - if the key is already present in the tree, no new node is created.
Example
open SplayTree
let t = Tree<int, string>()
t.Insert(5) |> ignore
t.Insert(-10) |> ignore
t.Insert(0) |> ignore
t.Insert(33) |> ignore
t.Insert(2) |> ignore
printfn "%A" (t.Keys()) // [|-10; 0; 2; 5; 33|]
printfn "%d" t.Size // 5
printfn "%A" (t.Min()) // Some -10
printfn "%A" (t.Max()) // Some 33
t.Remove(0)
printfn "%d" t.Size // 4
Custom comparer (reverse sort)
let t = Tree<int, string>(fun a b -> compare b a)
t.Insert(5) |> ignore
t.Insert(-10) |> ignore
t.Insert(0) |> ignore
t.Insert(33) |> ignore
t.Insert(2) |> ignore
printfn "%A" (t.Keys()) // [|33; 5; 2; 0; -10|]
Bulk insert
let t = Tree<int, string>()
t.Load([|3; 2; -10; 20|], [|"C"; "B"; "A"; "D"|], true) |> ignore
printfn "%A" (t.Keys()) // [|-10; 2; 3; 20|]
printfn "%A" (t.Values()) // [|"A"; "B"; "C"; "D"|]
Tests
All test are ported too and pass.
see FSharp/Tests/README.md for details on building the Fable output and running the test suite on .NET and JS.
AI
ported from https://github.com/w8r/splay-tree on 2026-04-12 with Codex GPT-5.4 Extra High ... and a lot of manual improvements and fixes.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FSharp.Core (>= 6.0.7)
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 |
|---|---|---|
| 3.2.30 | 113 | 4/13/2026 |
### Changed
- First release of Port of version 3.0.3 to F#