|
1 | 1 | # WBTrees |
| 2 | +[](LICENSE) |
| 3 | +[](https://www.nuget.org/packages/WBTrees/) |
| 4 | +[](https://www.nuget.org/packages/WBTrees/) |
| 5 | + |
2 | 6 | Provides a basic implementation of weight-balanced binary trees. |
| 7 | + |
| 8 | +The WBTrees library contains classes as follows: |
| 9 | +- A list by a weight-balanced binary tree, with all `O(log n)` basic operations |
| 10 | + - `WBList<T>` |
| 11 | +- A set and a map by weight-balanced binary search trees, which can be accessed by index in `O(log n)` time |
| 12 | + - `WBSet<T>` |
| 13 | + - `WBMultiSet<T>` |
| 14 | + - `WBMap<TKey, TValue>` |
| 15 | + - `WBMultiMap<TKey, TValue>` |
| 16 | + |
| 17 | +All these trees are constructed from `Node<T>` objects. |
| 18 | + |
| 19 | +See [Wiki](https://github.com/sakapon/WBTrees/wiki) for more information. |
| 20 | +This library is written in C#. |
| 21 | +You are welcome to port this to other languages. |
| 22 | + |
| 23 | +## Features |
| 24 | + |
| 25 | +### A List by a Weight-Balanced Binary Tree |
| 26 | +Provides the `WBList<T>` class as a list with all `O(log n)` basic operations. |
| 27 | +You can also use a `WBList<T>` as a (high-grade) double-ended queue (deque). |
| 28 | + |
| 29 | +The following table compares time complexities of [`System.Collections.Generic.List<T>`](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) and `WBList<T>`: |
| 30 | +| Operation | `List<T>` | `WBList<T>` | |
| 31 | +|:--|:-:|:-:| |
| 32 | +| Get by Index | `O(1)` | `O(log n)` | |
| 33 | +| Set by Index | `O(1)` | `O(log n)` | |
| 34 | +| Remove by Index | `O(n)` | `O(log n)` | |
| 35 | +| Insert by Index | `O(n)` | `O(log n)` | |
| 36 | +| Prepend | `O(n)` | `O(log n)` | |
| 37 | +| Add | `O(1)` | `O(log n)` | |
| 38 | +| Get All | `O(n)` | `O(n)` | |
| 39 | + |
| 40 | +### A Set and a Map by Weight-Balanced Binary Search Trees |
| 41 | +Provides the `WBSet<T>`, `WBMultiSet<T>`, `WBMap<TKey, TValue>` and `WBMultiMap<TKey, TValue>` classes, which can be accessed by index in `O(log n)` time. All these classes are derived from the `WBTreeBase<T>` class. |
| 42 | +You can also use a `WBMultiSet<T>` or a `WBMultiMap<TKey, TValue>` as a priority queue with stable sorting or a double-ended priority queue. |
| 43 | + |
| 44 | +The following table compares time complexities of [`System.Collections.Generic.SortedSet<T>`](https://docs.microsoft.com/dotnet/api/system.collections.generic.sortedset-1) and `WBSet<T>`: |
| 45 | +| Operation | `SortedSet<T>` | `WBSet<T>` | |
| 46 | +|:--|:-:|:-:| |
| 47 | +| Get by Item | `O(log n)` | `O(log n)` | |
| 48 | +| Remove by Item | `O(log n)` | `O(log n)` | |
| 49 | +| Add | `O(log n)` | `O(log n)` | |
| 50 | +| Get by Index | `O(n)` | `O(log n)` | |
| 51 | +| Remove by Index | `O(n)` | `O(log n)` | |
| 52 | +| Get Index by Item | `O(n)` | `O(log n)` | |
| 53 | +| Get All | `O(n)` | `O(n)` | |
| 54 | + |
| 55 | +## Algorithm |
| 56 | +Both `WBList<T>` and `WBTreeBase<T>` are weight-balanced binary trees (not necessarily searchable by items). |
| 57 | +The `Node<T>` class contains the `Count` property that contributes to both self-balancing and fast access by index (order). |
| 58 | + |
| 59 | +## Target Frameworks |
| 60 | +- .NET 5 |
| 61 | +- .NET Standard 2.0 |
| 62 | + - [.NET Core 2.0, .NET Framework 4.6.1, etc.](https://docs.microsoft.com/dotnet/standard/net-standard) |
| 63 | + |
| 64 | +## Setup |
| 65 | +The WBTrees library is published to [NuGet Gallery](https://www.nuget.org/packages/WBTrees/). |
| 66 | +Install the NuGet package via Visual Studio, etc. |
| 67 | + |
| 68 | +You can also [download a single source file here](downloads) for competitive programming, etc. |
| 69 | + |
| 70 | +## Usage |
| 71 | +See [Usage on Wiki](https://github.com/sakapon/WBTrees/wiki/Usage) for coding. |
| 72 | + |
| 73 | +## Release Notes |
| 74 | +- **v1.0.4** The first release. |
0 commit comments