-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsorted-set.min.js
1 lines (1 loc) · 9.41 KB
/
sorted-set.min.js
1
!function(){define("SortedSet/AbstractSortedSet",[],function(){var t;return t=function(){function t(t){if(null==(null!=t?t.strategy:void 0))throw"Must pass options.strategy, a strategy";if(null==(null!=t?t.comparator:void 0))throw"Must pass options.comparator, a comparator";this.priv=new t.strategy(t)}return t.prototype.insert=function(t){return this.priv.insert(t),this},t.prototype.remove=function(t){return this.priv.remove(t),this},t.prototype.contains=function(t){return this.priv.contains(t)},t.prototype.toArray=function(){return this.priv.toArray()},t.prototype.forEach=function(t,r){return this.priv.forEachImpl(t,this,r),this},t.prototype.map=function(t,r){var e;return e=[],this.forEach(function(n,o,i){return e.push(t.call(r,n,o,i))}),e},t.prototype.filter=function(t,r){var e;return e=[],this.forEach(function(n,o,i){return t.call(r,n,o,i)?e.push(n):void 0}),e},t.prototype.every=function(t,r){var e;return e=!0,this.forEach(function(n,o,i){return e&&!t.call(r,n,o,i)?e=!1:void 0}),e},t.prototype.some=function(t,r){var e;return e=!1,this.forEach(function(n,o,i){return!e&&t.call(r,n,o,i)?e=!0:void 0}),e},t.prototype.findIterator=function(t){return this.priv.findIterator(t)},t.prototype.beginIterator=function(){return this.priv.beginIterator()},t.prototype.endIterator=function(){return this.priv.endIterator()},t}()})}.call(this),function(){define("SortedSet/ArrayStrategy",[],function(){var t,r,e;return r=function(t,e){var n;return n=t.data,{hasNext:function(){return e<n.length},hasPrevious:function(){return e>0},value:function(){return e<n.length?n[e]:null},setValue:function(r){if(!t.options.allowSetValue)throw"Must set options.allowSetValue";if(!this.hasNext())throw"Cannot set value at end of set";return n[e]=r},next:function(){return e>=n.length?null:new r(t,e+1)},previous:function(){return 0>=e?null:new r(t,e-1)}}},e=function(t,r,e){var n,o,i;for(o=0,n=t.length;n>o;)i=o+n>>>1,e(t[i],r)<0?o=i+1:n=i;return o},t=function(){function t(t){this.options=t,this.comparator=this.options.comparator,this.data=[]}return t.prototype.toArray=function(){return this.data},t.prototype.insert=function(t){var r;if(r=e(this.data,t,this.comparator),this.data[r]===t)throw"Value already in set";return this.data.splice(r,0,t)},t.prototype.remove=function(t){var r;if(r=e(this.data,t,this.comparator),this.data[r]!==t)throw"Value not in set";return this.data.splice(r,1)},t.prototype.contains=function(t){return-1!==this.data.indexOf(t)},t.prototype.forEachImpl=function(t,r,e){var n,o,i,u,l;for(l=this.data,n=i=0,u=l.length;u>i;n=++i)o=l[n],t.call(e,o,n,r);return void 0},t.prototype.findIterator=function(t){var n;return n=e(this.data,t,this.comparator),new r(this,n)},t.prototype.beginIterator=function(){return new r(this,0)},t.prototype.endIterator=function(){return new r(this,this.data.length)},t}()})}.call(this),function(){define("SortedSet/BinaryTreeIterator",[],function(){var t,r,e;return r=function(t,r){for(var e;null!==r[t];)e=r,r=r[t],r._iteratorParentNode=e;return r},e=function(t,e){var n,o;if(null!==e[t])n=e,e=e[t],e._iteratorParentNode=n,o="left"===t?"right":"left",e=r(o,e);else{for(;null!==(n=e._iteratorParentNode)&&n[t]===e;)e=n;e=n}return e},t=function(){function t(t,r){this.tree=t,this.node=r}return t.prototype.next=function(){var r;return null===this.node?null:(r=e("right",this.node),new t(this.tree,r))},t.prototype.previous=function(){var n;return null===this.node?null===this.tree.root?null:(this.tree.root._iteratorParentNode=null,n=r("right",this.tree.root),new t(this.tree,n)):(n=e("left",this.node),null===n?null:new t(this.tree,n))},t.prototype.hasNext=function(){return null!==this.node},t.prototype.hasPrevious=function(){return null!==this.previous()},t.prototype.value=function(){return null===this.node?null:this.node.value},t.prototype.setValue=function(t){if(!this.tree.options.allowSetValue)throw"Must set options.allowSetValue";if(!this.hasNext())throw"Cannot set value at end of set";return this.node.value=t},t}(),t.find=function(r,e,n){var o,i,u,l;for(l=r.root,null!=l&&(l._iteratorParentNode=null),u=l,i=null;null!==u&&(o=n(e,u.value),0!==o);)if(0>o){if(null===u.left)break;i=u,u.left._iteratorParentNode=u,u=u.left}else{if(null===u.right){u=i;break}u.right._iteratorParentNode=u,u=u.right}return new t(r,u)},t.left=function(e){var n;return null===e.root?new t(e,null):(e.root._iteratorParentNode=null,n=r("left",e.root),new t(e,n))},t.right=function(r){return new t(r,null)},t})}.call(this),function(){define("SortedSet/AbstractBinaryTreeStrategy",["./BinaryTreeIterator"],function(t){var r,e;return e=function(t,r){return null!==t&&(e(t.left,r),r(t.value),e(t.right,r)),void 0},r=function(){function r(){}return r.prototype.toArray=function(){var t;return t=[],e(this.root,function(r){return t.push(r)}),t},r.prototype.forEachImpl=function(t,r,n){var o;return o=0,e(this.root,function(e){return t.call(n,e,o,r),o+=1}),void 0},r.prototype.contains=function(t){var r,e,n;for(e=this.comparator,n=this.root;null!==n&&(r=e(t,n.value),0!==r);)n=0>r?n.left:n.right;return null!==n&&n.value===t},r.prototype.findIterator=function(r){return t.find(this,r,this.comparator)},r.prototype.beginIterator=function(){return t.left(this)},r.prototype.endIterator=function(){return t.right(this)},r}()})}.call(this),function(){var t={}.hasOwnProperty,r=function(r,e){function n(){this.constructor=r}for(var o in e)t.call(e,o)&&(r[o]=e[o]);return n.prototype=e.prototype,r.prototype=new n,r.__super__=e.prototype,r};define("SortedSet/BinaryTreeStrategy",["./AbstractBinaryTreeStrategy"],function(t){var e,n,o,i;return n=function(){function t(t){this.value=t,this.left=null,this.right=null}return t}(),i=function(t,r){for(;null!==t[r];)t=t[r];return t},o=function(t,r,e){var n,u;if(null===t)throw"Value not in set";return n=e(r,t.value),0>n?t.left=o(t.left,r,e):n>0?t.right=o(t.right,r,e):null===t.left&&null===t.right?t=null:null===t.right?t=t.left:null===t.left?t=t.right:(u=i(t.right,"left"),t.value=u.value,t.right=o(t.right,u.value,e)),t},e=function(t){function e(t){this.options=t,this.comparator=this.options.comparator,this.root=null}return r(e,t),e.prototype.insert=function(t){var r,e,o,i;if(e=this.comparator,null!=this.root){for(i=this.root;;){if(r=e(t,i.value),0===r)throw"Value already in set";if(o=0>r?"left":"right",null===i[o])break;i=i[o]}return i[o]=new n(t)}return this.root=new n(t)},e.prototype.remove=function(t){return this.root=o(this.root,t,this.comparator)},e}(t)})}.call(this),function(){var t={}.hasOwnProperty,r=function(r,e){function n(){this.constructor=r}for(var o in e)t.call(e,o)&&(r[o]=e[o]);return n.prototype=e.prototype,r.prototype=new n,r.__super__=e.prototype,r};define("SortedSet/RedBlackTreeStrategy",["./AbstractBinaryTreeStrategy"],function(t){var e,n,o,i,u,l,a,f,s,h,c,p;return e=function(){function t(t){this.value=t,this.left=null,this.right=null,this.isRed=!0}return t}(),c=function(t){var r;return r=t.right,t.right=r.left,r.left=t,r.isRed=t.isRed,t.isRed=!0,r},p=function(t){var r;return r=t.left,t.left=r.right,r.right=t,r.isRed=t.isRed,t.isRed=!0,r},o=function(t){return t.isRed=!t.isRed,t.left.isRed=!t.left.isRed,t.right.isRed=!t.right.isRed,void 0},a=function(t){return o(t),null!==t.right&&null!==t.right.left&&t.right.left.isRed&&(t.right=p(t.right),t=c(t),o(t)),t},f=function(t){return o(t),null!==t.left&&null!==t.left.left&&t.left.left.isRed&&(t=p(t),o(t)),t},l=function(t,r,n){if(null===t)return new e(r);if(t.value===r)throw"Value already in set";return n(r,t.value)<0?t.left=l(t.left,r,n):t.right=l(t.right,r,n),null===t.right||!t.right.isRed||null!==t.left&&t.left.isRed||(t=c(t)),null!==t.left&&t.left.isRed&&null!==t.left.left&&t.left.left.isRed&&(t=p(t)),null!==t.left&&t.left.isRed&&null!==t.right&&t.right.isRed&&o(t),t},i=function(t){for(;null!==t.left;)t=t.left;return t},u=function(t){return null!==t.right&&t.right.isRed&&(t=c(t)),null!==t.left&&t.left.isRed&&null!==t.left.left&&t.left.left.isRed&&(t=p(t)),null!==t.left&&t.left.isRed&&null!==t.right&&t.right.isRed&&o(t),t},h=function(t){return null===t.left?null:(t.left.isRed||null!==t.left.left&&t.left.left.isRed||(t=a(t)),t.left=h(t.left),u(t))},s=function(t,r,e){if(null===t)throw"Value not in set";if(t.value!==r&&e(r,t.value)<0){if(null===t.left)throw"Value not in set";t.left.isRed||null!==t.left.left&&t.left.left.isRed||(t=a(t)),t.left=s(t.left,r,e)}else{if(null!==t.left&&t.left.isRed&&(t=p(t)),null===t.right){if(r===t.value)return null;throw"Value not in set"}t.right.isRed||null!==t.right.left&&t.right.left.isRed||(t=f(t)),r===t.value?(t.value=i(t.right).value,t.right=h(t.right)):t.right=s(t.right,r,e)}return null!==t&&(t=u(t)),t},n=function(t){function e(t){this.options=t,this.comparator=this.options.comparator,this.root=null}return r(e,t),e.prototype.insert=function(t){return this.root=l(this.root,t,this.comparator),this.root.isRed=!1,void 0},e.prototype.remove=function(t){return this.root=s(this.root,t,this.comparator),null!==this.root&&(this.root.isRed=!1),void 0},e}(t)})}.call(this),function(){var t={}.hasOwnProperty,r=function(r,e){function n(){this.constructor=r}for(var o in e)t.call(e,o)&&(r[o]=e[o]);return n.prototype=e.prototype,r.prototype=new n,r.__super__=e.prototype,r};define("SortedSet",["./SortedSet/AbstractSortedSet","./SortedSet/ArrayStrategy","./SortedSet/BinaryTreeStrategy","./SortedSet/RedBlackTreeStrategy"],function(t,e,n,o){var i;return i=function(t){function e(t){t||(t={}),t.strategy||(t.strategy=o),t.comparator||(t.comparator=function(t,r){return(t||0)-(r||0)}),e.__super__.constructor.call(this,t)}return r(e,t),e}(t),i.ArrayStrategy=e,i.BinaryTreeStrategy=n,i.RedBlackTreeStrategy=o,i})}.call(this);