-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
## 1.0.0 | ||
## 0.1.0 | ||
|
||
- Initial version. | ||
- Initial version. Public interface still subject to change. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,19 @@ | ||
A library implementing a persistent treap data structure for Dart developers. | ||
# Treap | ||
|
||
## Usage | ||
|
||
A simple usage example: | ||
[![main](https://github.com/nielsenko/treap/actions/workflows/dart.yml/badge.svg?branch=main)](https://github.com/nielsenko/treap/actions/workflows/dart.yml) | ||
[![codecov](https://codecov.io/gh/nielsenko/treap/branch/master/graph/badge.svg?token=JI1PHY21A5)](https://codecov.io/gh/nielsenko/treap) | ||
|
||
```dart | ||
import 'package:test/test.dart'; | ||
import 'package:treap/treap.dart'; | ||
A package implementing a [persistent](https://en.wikipedia.org/wiki/Persistent_data_structure) (immutable) [order statistic tree](https://en.wikipedia.org/wiki/Order_statistic_tree) by means of the [treap](https://en.wikipedia.org/wiki/Treap) data structure (a kind of [cartesian tree](https://en.wikipedia.org/wiki/Cartesian_tree)). Apart from the regular set operations, it allows for: | ||
|
||
main() { | ||
group('Treap', () { | ||
test('set algebra', () { | ||
final rnd = Random(42); | ||
const max = 1000; | ||
final x = {for (int i = 0; i < max; ++i) rnd.nextInt(max)}; | ||
final y = {for (int i = 0; i < max; ++i) rnd.nextInt(max)}; | ||
- `select(i)` – find the `i`-th smallest element. | ||
- `rank(x)` – find the rank of element `x`, i.e. the number of elements smaller than `x`. | ||
|
||
final tx = Treap<num>.build(x); | ||
final ty = Treap<num>.build(y); | ||
both in `O(log(N))` time. | ||
|
||
expect((tx | ty).values, x.union(y)); | ||
expect((tx & ty).values, x.intersection(y)); | ||
expect((tx - ty).values, x.difference(y)); | ||
}); | ||
}); | ||
} | ||
``` | ||
This particular implementation is made fully persistent by means of path copying. That is, any operation that would otherwise mutate the treap, instead produces a new treap, and does so using only `O(log(N))` extra space. | ||
|
||
For something more significant see the [todo](example/) flutter app | ||
## Example | ||
|
||
## Status | ||
A toy [todo](example/) flutter app, that illustrates how to use persistent treaps to efficiently handle undo/redo and animate a list view. | ||
|
||
[![main](https://github.com/nielsenko/treap/actions/workflows/dart.yml/badge.svg?branch=main)](https://github.com/nielsenko/treap/actions/workflows/dart.yml) | ||
[![codecov](https://codecov.io/gh/nielsenko/treap/branch/master/graph/badge.svg?token=JI1PHY21A5)](https://codecov.io/gh/nielsenko/treap) | ||
If your browser supports WasmGC (such as Chrome 119+, or Firefox 120+), you can try out the app [here](https://byolimit.github.io) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/// An implementation of the [Treap] | ||
/// data structure for [Dart](https://dart.dev) | ||
library treap; | ||
|
||
export 'src/treap_base.dart'; |
Oops, something went wrong.