Skip to content

Commit

Permalink
Add .length. Change to Gulp+Browserify
Browse files Browse the repository at this point in the history
[closes #2]
  • Loading branch information
adamhooper committed Aug 28, 2014
1 parent 5399581 commit 78e582a
Show file tree
Hide file tree
Showing 60 changed files with 1,648 additions and 4,089 deletions.
71 changes: 0 additions & 71 deletions Gruntfile.coffee

This file was deleted.

26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,16 @@ will be very slow with large sets.
Installing
==========

Download `sorted-set.js`. Alternatively, install through Bower:
`bower install js-sorted-set`
You can `npm install js-sorted-set` or `bower install js-sorted-set`.
Alternatively, just download `sorted-set.js` from this directory.

Include it through [RequireJS](http://requirejs.org/).
Include it through [RequireJS](http://requirejs.org/) or
[Browserify](http://browserify.org). Or, to pollute your global scope, insert
this in your HTML:

Then write code like this:

require([ 'vendor/sorted-set' ], function(SortedSet) {
var set = new SortedSet({ comparator: function(a, b) { return b - a; });
set.insert(5);
set.insert(3);
set.insert(2);
set.remove(3);
var yes = set.contains(2);
console.log(set.map(function(x) { return x * 2; })); // returns [ 20, 4 ]
});
<script src="priority-queue.js"></script>

If you don't like RequireJS, you can download the standalone version,
`sorted-set.no-require.js`, and write:
Then write code like this:

var set = new SortedSet({ comparator: function(a, b) { return b - a; });
set.insert(5);
Expand All @@ -63,6 +54,7 @@ The SortedSet API:
| Create | `var set = new SortedSet();` |
| Insert | `set.insert(value);` |
| Remove | `set.remove(value);` |
| Length | `set.length;` |
| Test | `set.contains(value);` | Returns `true` or `false` |
| Iterate | `set.forEach(doSomething);` | Plus `set.map()` and other [iterative methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.6#Array_extras), returning `Array`s and scalars |

Expand All @@ -79,6 +71,7 @@ Here's the full SortedSet iterator API:

| Operation | Syntax (js-sorted-set) | Notes |
| --------- | ---------------------- | ----- |
| Length | `var len = set.length;` |
| Find | `var iterator = set.findIterator(value);` | `iterator` points to the left of `value`. If `value` is not in `set`, `iterator` points to the left of the first item _greater than_ `value`. If `value` is greater than the final item in `set`, `iterator` points to the right of the final item. |
| Begin | `var iterator = set.beginIterator();` | If `set` is empty, this is equivalent to `var iterator = set.endIterator();` |
| End | `var iterator = set.endIterator();` | Points past the end of `set`; there is never a value here |
Expand Down Expand Up @@ -164,6 +157,7 @@ You'll see running times like this:
| Operation | Array | Binary tree | Red-black tree |
| --------- | ----- | ----------- | -------------- |
| Create | O(1) | O(1) | O(1) |
| Length | O(1) | O(1) | O(1) |
| Insert | O(n) (often slow) | O(n) (often slow) | O(lg n) (fast) |
| Remove | O(n) (often slow) | O(n) (often slow) | O(lg n) (fast) |
| Iterate | O(n) (fast) | O(n) (slowest) | O(n) (slower than Array) |
Expand Down
10 changes: 5 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "js-sorted-set",
"version": "0.0.7",
"version": "0.1.0",
"main": "sorted-set.js",
"ignore": [
"**/.*",
"node_modules",
"coffee",
"spec",
"spec-coffee",
"Gruntfile.js",
"src",
"test",
"gulpfile.js",
"gulpfile.coffee",
"package.json"
]
}
23 changes: 0 additions & 23 deletions coffee/SortedSet.coffee

This file was deleted.

41 changes: 0 additions & 41 deletions coffee/SortedSet/AbstractBinaryTreeStrategy.coffee

This file was deleted.

82 changes: 0 additions & 82 deletions coffee/SortedSet/AbstractSortedSet.coffee

This file was deleted.

67 changes: 0 additions & 67 deletions coffee/SortedSet/ArrayStrategy.coffee

This file was deleted.

Loading

0 comments on commit 78e582a

Please sign in to comment.