Skip to content

Commit

Permalink
Add README and LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Jul 27, 2012
1 parent 19bcbdf commit aed15d9
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,21 @@

Copyright 2012 Kristopher Michael Kowal. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

75 changes: 75 additions & 0 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,75 @@

A binary splay tree is a balanced binary tree that rotates the most
frequently used items toward the root such that they can be accessed the
most quickly. This CommonJS package includes a `SplaySet` and
`SplayMap` in `splay-set` and `splay-map` modules.

Additionally, this implementation applies the insight that any Map can
be implemented in terms of a Set provided that you can override
functions that operate on the values within that set. All of the splay
tree reference implementations opted to implement a map interface
instead.

Both `SplaySet` and `SplayMap` implement a `log` function which can
produce NPM-style visualizations of the internal state of the splay
tree.

```
> set.log(SplaySet.ascii)
.-+ -3
| '-- -2
.-+ -1
+ 0
| .-- 1
'-+ 2
'-- 3
```

```
> set.log(SplaySet.unicodeRound)
╭━┳ -3
┃ ╰━━ -2
╭━┻ -1
╋ 0
┃ ╭━┳ 1
┃ ┃ ╰━━ 2
╰━┻ 3
```

## References

- a SplayTree impementation buried in Fedor Indutny’s super-secret
[Callgrind](https://github.com/indutny/callgrind.js). This
implementation uses parent references.
- a SplayTree implementation adapted by [Paolo
Fragomeni](https://github.com/hij1nx/forest) from the V8 project and
based on the top-down splaying algorithm from "Self-adjusting Binary
Search Trees" by Sleator and Tarjan. This does not use or require
parent references, so I favored it over Fedor Indutny’s style.
- the interface of ECMAScript harmony [simple maps and
sets](http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets)
- a SplayTree implementation from [JavaScript data
structures](derrickburns/Javascript-Data-Structures) mainted by
Derrick Burns that supports change-resilient iterators and a
comprehensive set of introspection functions.

## Future work

- tests
- docs
- incorporate all array-like methods
- incorporate iterability
- incorporate comprehensive introspection functions for slicing ranges
- hash string map and set, using underlying object
- relax unique content constraint on splay trees to implement splay
list and splay multi-map
- LRU cache sets and maps
- ARC cache sets and maps
- linked list types
- trie set and map
- immutable set and map structures using hash tries
- heap
- binary heap
- observable variants of all collection types
- alternative module systems song and dance

0 comments on commit aed15d9

Please sign in to comment.