Skip to content

Commit

Permalink
Update README for TreapSet
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Aug 28, 2024
1 parent b921ecd commit eff92f6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ A package implementing a [persistent](https://en.wikipedia.org/wiki/Persistent_d

both in `O(log(N))` time.

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.
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. This allow copies to be `O(1)` in time and space.

## TreapSet

`TreapSet<T>` (build on top of `Treap<T>`) implements `Set<T>`. It resembles `SplayTreeSet<T>` in behavior, keeping elements ordered, but is differs in performance of:
- `take`
- `skip`
- `elementAt`

which are all `O(log(N))` (given `select` and `rank`) and `toSet` which is `O(1)` and hence much faster than all the 3 standard sets (`LinkedHashSet` (default), `HashSet` and `SplayTreeSet`).

As a rule of thumb the mutating operations `add`, `remove` are roughly twice as slow as for `SplaySetTree` (which is already a lot slower than `HashSet` and `LinkedHashSet` in this regard). This is mostly due to the cost of the _path copying_ done to make `Treap<T>` immutable. A full benchmark suite can be found in `benchmark/main.dart` comparing various set operations on the three standard sets and `TreapSet`.

## Example

Expand Down

0 comments on commit eff92f6

Please sign in to comment.