Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sakapon/wbtrees
Provides a basic implementation of weight-balanced binary trees.
https://github.com/sakapon/wbtrees
algorithms binary-search-tree data-structures self-balancing-binary-search-tree weight-balanced-tree
Last synced: about 6 hours ago
JSON representation
Provides a basic implementation of weight-balanced binary trees.
- Host: GitHub
- URL: https://github.com/sakapon/wbtrees
- Owner: sakapon
- License: mit
- Created: 2022-02-20T03:39:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-10T14:43:46.000Z (over 2 years ago)
- Last Synced: 2024-10-12T01:04:48.712Z (about 1 month ago)
- Topics: algorithms, binary-search-tree, data-structures, self-balancing-binary-search-tree, weight-balanced-tree
- Language: C#
- Homepage:
- Size: 247 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WBTrees
[![license](https://img.shields.io/github/license/sakapon/WBTrees.svg)](LICENSE)
[![NuGet](https://img.shields.io/nuget/v/WBTrees.svg)](https://www.nuget.org/packages/WBTrees/)
[![NuGet](https://img.shields.io/nuget/dt/WBTrees.svg)](https://www.nuget.org/packages/WBTrees/)Provides a basic implementation of weight-balanced binary trees.
The WBTrees library contains classes as follows:
- A list by a weight-balanced binary tree, with all `O(log n)` basic operations
- `WBList`
- A set and a map by weight-balanced binary search trees, which can be accessed by index in `O(log n)` time
- `WBSet`
- `WBMultiSet`
- `WBMap`
- `WBMultiMap`All these trees are constructed from `Node` objects.
See [Wiki](https://github.com/sakapon/WBTrees/wiki) for more information.
This library is written in C#.
You are welcome to port this to other languages.## Features
### A List by a Weight-Balanced Binary Tree
Provides the `WBList` class as a list with all `O(log n)` basic operations.
You can also use a `WBList` as a (high-grade) double-ended queue (deque).The following table compares time complexities of [`System.Collections.Generic.List`](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) and `WBList`:
| Operation | `List` | `WBList` |
|:--|:-:|:-:|
| Get by Index | `O(1)` | `O(log n)` |
| Set by Index | `O(1)` | `O(log n)` |
| Remove by Index | `O(n)` | `O(log n)` |
| Insert by Index | `O(n)` | `O(log n)` |
| Prepend | `O(n)` | `O(log n)` |
| Add | `O(1)` | `O(log n)` |
| Get All | `O(n)` | `O(n)` |### A Set and a Map by Weight-Balanced Binary Search Trees
Provides the `WBSet`, `WBMultiSet`, `WBMap` and `WBMultiMap` classes, which can be accessed by index in `O(log n)` time. All these classes are derived from the `WBTreeBase` class.
You can also use a `WBMultiSet` or a `WBMultiMap` as a priority queue with stable sorting or a double-ended priority queue.The following table compares time complexities of [`System.Collections.Generic.SortedSet`](https://docs.microsoft.com/dotnet/api/system.collections.generic.sortedset-1) and `WBSet`:
| Operation | `SortedSet` | `WBSet` |
|:--|:-:|:-:|
| Get by Item | `O(log n)` | `O(log n)` |
| Remove by Item | `O(log n)` | `O(log n)` |
| Add | `O(log n)` | `O(log n)` |
| Get by Index | `O(n)` | `O(log n)` |
| Remove by Index | `O(n)` | `O(log n)` |
| Get Index by Item | `O(n)` | `O(log n)` |
| Get All | `O(n)` | `O(n)` |## Algorithm
Both `WBList` and `WBTreeBase` are weight-balanced binary trees (not necessarily searchable by items).
The `Node` class contains the `Count` property that contributes to both self-balancing and fast access by index (order).## Target Frameworks
- .NET 5
- .NET Standard 2.0
- [.NET Core 2.0, .NET Framework 4.6.1, etc.](https://docs.microsoft.com/dotnet/standard/net-standard)## Setup
The WBTrees library is published to [NuGet Gallery](https://www.nuget.org/packages/WBTrees/).
Install the NuGet package via Visual Studio, etc.You can also [download a single source file here](downloads) for competitive programming, etc.
## Usage
See [Usage on Wiki](https://github.com/sakapon/WBTrees/wiki/Usage) for coding.## Release Notes
- **v1.0.4** The first release.