Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency cleanup #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
all: dist/rbtree.min.js dist/bintree.min.js

dist/rbtree.js: lib/rbtree.js lib/treebase.js
./node_modules/.bin/reunion --ns RBTree $< > $@
./node_modules/.bin/browserify -s RBTree $< > $@

dist/bintree.js: lib/bintree.js lib/treebase.js
./node_modules/.bin/reunion --ns BinTree $< > $@
./node_modules/.bin/browserify -s BinTree $< > $@

dist/bintree.min.js: dist/bintree.js
curl --data-urlencode "js_code@$<" \
-d "output_info=compiled_code&compilation_level=SIMPLE_OPTIMIZATIONS" \
http://closure-compiler.appspot.com/compile \
> $@
./node_modules/.bin/uglifyjs $< -c -m -o $@

dist/rbtree.min.js: dist/rbtree.js
curl --data-urlencode "js_code@$<" \
-d "output_info=compiled_code&compilation_level=SIMPLE_OPTIMIZATIONS" \
http://closure-compiler.appspot.com/compile \
> $@
./node_modules/.bin/uglifyjs $< -c -m -o $@


239 changes: 114 additions & 125 deletions dist/bintree.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,113 @@
BinTree = (function(window) {
var global = window;
var require = function(name) {
var fn = require.m[name];
if (fn.mod) {
return fn.mod.exports;
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BinTree = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

var TreeBase = require('./treebase');

function Node(data) {
this.data = data;
this.left = null;
this.right = null;
}

Node.prototype.get_child = function(dir) {
return dir ? this.right : this.left;
};

Node.prototype.set_child = function(dir, val) {
if(dir) {
this.right = val;
}
else {
this.left = val;
}
};

function BinTree(comparator) {
this._root = null;
this._comparator = comparator;
this.size = 0;
}

BinTree.prototype = new TreeBase();

// returns true if inserted, false if duplicate
BinTree.prototype.insert = function(data) {
if(this._root === null) {
// empty tree
this._root = new Node(data);
this.size++;
return true;
}

var mod = fn.mod = { exports: {} };
fn(mod, mod.exports);
return mod.exports;
var dir = 0;

// setup
var p = null; // parent
var node = this._root;

// search down
while(true) {
if(node === null) {
// insert new node at the bottom
node = new Node(data);
p.set_child(dir, node);
this.size++;
return true;
}

// stop if found
if(this._comparator(node.data, data) === 0) {
return false;
}

dir = this._comparator(node.data, data) < 0;

// update helpers
p = node;
node = node.get_child(dir);
}
};

require.m = {};
require.m['./treebase'] = function(module, exports) {
// returns true if removed, false if not found
BinTree.prototype.remove = function(data) {
if(this._root === null) {
return false;
}

var head = new Node(undefined); // fake tree root
var node = head;
node.right = this._root;
var p = null; // parent
var found = null; // found item
var dir = 1;

while(node.get_child(dir) !== null) {
p = node;
node = node.get_child(dir);
var cmp = this._comparator(data, node.data);
dir = cmp > 0;

if(cmp === 0) {
found = node;
}
}

if(found !== null) {
found.data = node.data;
p.set_child(p.right === node, node.get_child(node.left === null));

this._root = head.right;
this.size--;
return true;
}
else {
return false;
}
};

module.exports = BinTree;


},{"./treebase":2}],2:[function(require,module,exports){

function TreeBase() {}

Expand Down Expand Up @@ -138,15 +233,19 @@ TreeBase.prototype.iterator = function() {
TreeBase.prototype.each = function(cb) {
var it=this.iterator(), data;
while((data = it.next()) !== null) {
cb(data);
if(cb(data) === false) {
return;
}
}
};

// calls cb on each node's data, in reverse order
TreeBase.prototype.reach = function(cb) {
var it=this.iterator(), data;
while((data = it.prev()) !== null) {
cb(data);
if(cb(data) === false) {
return;
}
}
};

Expand Down Expand Up @@ -244,116 +343,6 @@ Iterator.prototype._maxNode = function(start) {

module.exports = TreeBase;

};
require.m['__main__'] = function(module, exports) {

var TreeBase = require('./treebase');

function Node(data) {
this.data = data;
this.left = null;
this.right = null;
}

Node.prototype.get_child = function(dir) {
return dir ? this.right : this.left;
};

Node.prototype.set_child = function(dir, val) {
if(dir) {
this.right = val;
}
else {
this.left = val;
}
};

function BinTree(comparator) {
this._root = null;
this._comparator = comparator;
this.size = 0;
}

BinTree.prototype = new TreeBase();

// returns true if inserted, false if duplicate
BinTree.prototype.insert = function(data) {
if(this._root === null) {
// empty tree
this._root = new Node(data);
this.size++;
return true;
}

var dir = 0;

// setup
var p = null; // parent
var node = this._root;

// search down
while(true) {
if(node === null) {
// insert new node at the bottom
node = new Node(data);
p.set_child(dir, node);
ret = true;
this.size++;
return true;
}

// stop if found
if(this._comparator(node.data, data) === 0) {
return false;
}

dir = this._comparator(node.data, data) < 0;

// update helpers
p = node;
node = node.get_child(dir);
}
};

// returns true if removed, false if not found
BinTree.prototype.remove = function(data) {
if(this._root === null) {
return false;
}

var head = new Node(undefined); // fake tree root
var node = head;
node.right = this._root;
var p = null; // parent
var found = null; // found item
var dir = 1;

while(node.get_child(dir) !== null) {
p = node;
node = node.get_child(dir);
var cmp = this._comparator(data, node.data);
dir = cmp > 0;

if(cmp === 0) {
found = node;
}
}

if(found !== null) {
found.data = node.data;
p.set_child(p.right === node, node.get_child(node.left === null));

this._root = head.right;
this.size--;
return true;
}
else {
return false;
}
};

module.exports = BinTree;

};
return require('__main__');
})(window);
},{}]},{},[1])(1)
});
9 changes: 1 addition & 8 deletions dist/bintree.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.