2016-01-15 00:01:56 +01:00

3 lines
13 KiB
JavaScript

!function e(t,r,n){function i(l,o){if(!r[l]){if(!t[l]){var s="function"==typeof require&&require;if(!o&&s)return s(l,!0);if(a)return a(l,!0);var u=new Error("Cannot find module '"+l+"'");throw u.code="MODULE_NOT_FOUND",u}var f=r[l]={exports:{}};t[l][0].call(f.exports,function(e){var r=t[l][1][e];return i(r?r:e)},f,f.exports,e,t,r,n)}return r[l].exports}for(var a="function"==typeof require&&require,l=0;l<n.length;l++)i(n[l]);return i}({1:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function l(t){e("./RedBlackTree.js")(t);var r=function(e){function t(e){n(this,t);var r=i(this,Object.getPrototypeOf(t).call(this,e));return r.store=e,r.ss=e.ss,r.os=e.os,r.ds=e.ds,r}return a(t,e),t}(t.Transaction),l=function(e){function l(e,r){n(this,l);var a=i(this,Object.getPrototypeOf(l).call(this,e,r));return a.os=new t.utils.RBTree,a.ds=new t.utils.RBTree,a.ss=new t.utils.RBTree,a}return a(l,e),o(l,[{key:"logTable",value:function(){var e=this;e.requestTransaction(regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("User: ",this.store.y.connector.userId,"=============================="),e.t0=console,e.delegateYield(this.getStateSet(),"t1",3);case 3:return e.t2=e.t1,e.t0.log.call(e.t0,"State Set (SS):",e.t2),console.log("Operation Store (OS):"),e.delegateYield(this.os.logTable(),"t3",7);case 7:return console.log("Deletion Store (DS):"),e.delegateYield(this.ds.logTable(),"t4",9);case 9:(this.store.gc1.length>0||this.store.gc2.length>0)&&console.warn("GC1|2 not empty!",this.store.gc1,this.store.gc2),"{}"!==JSON.stringify(this.store.listenersById)&&console.warn("listenersById not empty!"),"[]"!==JSON.stringify(this.store.listenersByIdExecuteNow)&&console.warn("listenersByIdExecuteNow not empty!"),this.store.transactionInProgress&&console.warn("Transaction still in progress!");case 13:case"end":return e.stop()}},t,this)}),!0)}},{key:"transact",value:function(e){for(var t=new r(this);null!==e;){for(var n=e.call(t),i=n.next();!i.done;)i=n.next(i.value);e=this.getNextRequest()}}},{key:"destroy",value:regeneratorRuntime.mark(function u(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:s(Object.getPrototypeOf(l.prototype),"destroy",this).call(this),delete this.os,delete this.ss,delete this.ds;case 4:case"end":return e.stop()}},u,this)})}]),l}(t.AbstractDatabase);t.extend("memory",l)}var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),s=function u(e,t,r){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,t);if(void 0===n){var i=Object.getPrototypeOf(e);return null===i?void 0:u(i,t,r)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(r)};t.exports=l,"undefined"!=typeof Y&&l(Y)},{"./RedBlackTree.js":2}],2:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.exports=function(e){var t=function(){function e(t){if(n(this,e),this.val=t,this.color=!0,this._left=null,this._right=null,this._parent=null,null===t.id)throw new Error("You must define id!")}return a(e,[{key:"isRed",value:function(){return this.color}},{key:"isBlack",value:function(){return!this.color}},{key:"redden",value:function(){return this.color=!0,this}},{key:"blacken",value:function(){return this.color=!1,this}},{key:"rotateLeft",value:function(e){var t=this.parent,r=this.right,n=this.right.left;if(r.left=this,this.right=n,null===t)e.root=r,r._parent=null;else if(t.left===this)t.left=r;else{if(t.right!==this)throw new Error("The elements are wrongly connected!");t.right=r}}},{key:"next",value:function(){if(null!==this.right){for(var e=this.right;null!==e.left;)e=e.left;return e}for(var t=this;null!==t.parent&&t!==t.parent.left;)t=t.parent;return t.parent}},{key:"prev",value:function(){if(null!==this.left){for(var e=this.left;null!==e.right;)e=e.right;return e}for(var t=this;null!==t.parent&&t!==t.parent.right;)t=t.parent;return t.parent}},{key:"rotateRight",value:function(e){var t=this.parent,r=this.left,n=this.left.right;if(r.right=this,this.left=n,null===t)e.root=r,r._parent=null;else if(t.left===this)t.left=r;else{if(t.right!==this)throw new Error("The elements are wrongly connected!");t.right=r}}},{key:"getUncle",value:function(){return this.parent===this.parent.parent.left?this.parent.parent.right:this.parent.parent.left}},{key:"grandparent",get:function(){return this.parent.parent}},{key:"parent",get:function(){return this._parent}},{key:"sibling",get:function(){return this===this.parent.left?this.parent.right:this.parent.left}},{key:"left",get:function(){return this._left},set:function(e){null!==e&&(e._parent=this),this._left=e}},{key:"right",get:function(){return this._right},set:function(e){null!==e&&(e._parent=this),this._right=e}}]),e}(),r=function(){function r(){n(this,r),this.root=null,this.length=0}return a(r,[{key:"findNext",value:regeneratorRuntime.mark(function l(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.findWithLowerBound([e[0],e[1]+1]),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}},l,this)})},{key:"findPrev",value:regeneratorRuntime.mark(function o(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.findWithUpperBound([e[0],e[1]-1]),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}},o,this)})},{key:"findNodeWithLowerBound",value:function(t){if(void 0===t)throw new Error("You must define from!");var r=this.root;if(null===r)return null;for(;;)if(null!==t&&!e.utils.smaller(t,r.val.id)||null===r.left){if(null===t||!e.utils.smaller(r.val.id,t))return r;if(null===r.right)return r.next();r=r.right}else r=r.left}},{key:"findNodeWithUpperBound",value:function(t){if(void 0===t)throw new Error("You must define from!");var r=this.root;if(null===r)return null;for(;;)if(null!==t&&!e.utils.smaller(r.val.id,t)||null===r.right){if(null===t||!e.utils.smaller(t,r.val.id))return r;if(null===r.left)return r.prev();r=r.left}else r=r.right}},{key:"findWithLowerBound",value:regeneratorRuntime.mark(function s(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=this.findNodeWithLowerBound(e),r.abrupt("return",null==t?null:t.val);case 2:case"end":return r.stop()}},s,this)})},{key:"findWithUpperBound",value:regeneratorRuntime.mark(function u(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=this.findNodeWithUpperBound(e),r.abrupt("return",null==t?null:t.val);case 2:case"end":return r.stop()}},u,this)})},{key:"iterate",value:regeneratorRuntime.mark(function f(t,r,n,i){var a;return regeneratorRuntime.wrap(function(l){for(;;)switch(l.prev=l.next){case 0:a=this.findNodeWithLowerBound(r);case 1:if(null===a||null!==n&&!e.utils.smaller(a.val.id,n)&&!e.utils.compareIds(a.val.id,n)){l.next=6;break}return l.delegateYield(i.call(t,a.val),"t0",3);case 3:a=a.next(),l.next=1;break;case 6:return l.abrupt("return",!0);case 7:case"end":return l.stop()}},f,this)})},{key:"logTable",value:regeneratorRuntime.mark(function c(e,t,r){var n;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return null==r&&(r=function(){return!0}),null==e&&(e=null),null==t&&(t=null),n=[],a.delegateYield(this.iterate(this,e,t,regeneratorRuntime.mark(function l(e){var t,a;return regeneratorRuntime.wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(r(e)){t={};for(a in e)"object"===i(e[a])?t[a]=JSON.stringify(e[a]):t[a]=e[a];n.push(t)}case 1:case"end":return l.stop()}},l,this)})),"t0",5);case 5:null!=console.table&&console.table(n);case 6:case"end":return a.stop()}},c,this)})},{key:"find",value:regeneratorRuntime.mark(function h(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",(t=this.findNode(e))?t.val:null);case 1:case"end":return r.stop()}},h,this)})},{key:"findNode",value:function(t){if(null==t||t.constructor!==Array)throw new Error("Expect id to be an array!");var r=this.root;if(null===r)return!1;for(;;){if(null===r)return!1;if(e.utils.smaller(t,r.val.id))r=r.left;else{if(!e.utils.smaller(r.val.id,t))return r;r=r.right}}}},{key:"delete",value:regeneratorRuntime.mark(function p(e){var r,n,i,a;return regeneratorRuntime.wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(null!=e&&e.constructor===Array){l.next=2;break}throw new Error("id is expected to be an Array!");case 2:if(r=this.findNode(e),null!=r){l.next=5;break}throw new Error("Element does not exist!");case 5:if(this.length--,null!==r.left&&null!==r.right){for(n=r.left;null!==n.right;)n=n.right;r.val=n.val,r=n}if(a=r.left||r.right,null===a?(i=!0,a=new t({id:0}),a.blacken(),r.right=a):i=!1,null!==r.parent){l.next=14;break}return i?this.root=null:(this.root=a,a.blacken(),a._parent=null),l.abrupt("return");case 14:if(r.parent.left!==r){l.next=18;break}r.parent.left=a,l.next=23;break;case 18:if(r.parent.right!==r){l.next=22;break}r.parent.right=a,l.next=23;break;case 22:throw new Error("Impossible!");case 23:if(r.isBlack()&&(a.isRed()?a.blacken():this._fixDelete(a)),this.root.blacken(),!i){l.next=35;break}if(a.parent.left!==a){l.next=30;break}a.parent.left=null,l.next=35;break;case 30:if(a.parent.right!==a){l.next=34;break}a.parent.right=null,l.next=35;break;case 34:throw new Error("Impossible #3");case 35:case"end":return l.stop()}},p,this)})},{key:"_fixDelete",value:function(e){function t(e){return null!==e?e.isBlack():!0}function r(e){return null!==e?e.isRed():!1}if(null!==e.parent){var n=e.sibling;if(r(n)){if(e.parent.redden(),n.blacken(),e===e.parent.left)e.parent.rotateLeft(this);else{if(e!==e.parent.right)throw new Error("Impossible #2");e.parent.rotateRight(this)}n=e.sibling}e.parent.isBlack()&&n.isBlack()&&t(n.left)&&t(n.right)?(n.redden(),this._fixDelete(e.parent)):e.parent.isRed()&&n.isBlack()&&t(n.left)&&t(n.right)?(n.redden(),e.parent.blacken()):(e===e.parent.left&&n.isBlack()&&r(n.left)&&t(n.right)?(n.redden(),n.left.blacken(),n.rotateRight(this),n=e.sibling):e===e.parent.right&&n.isBlack()&&r(n.right)&&t(n.left)&&(n.redden(),n.right.blacken(),n.rotateLeft(this),n=e.sibling),n.color=e.parent.color,e.parent.blacken(),e===e.parent.left?(n.right.blacken(),e.parent.rotateLeft(this)):(n.left.blacken(),e.parent.rotateRight(this)))}}},{key:"put",value:regeneratorRuntime.mark(function d(r){var n,i;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(null!=r&&null!=r.id&&r.id.constructor===Array){a.next=2;break}throw new Error("v is expected to have an id property which is an Array!");case 2:if(n=new t(r),null===this.root){a.next=31;break}i=this.root;case 5:if(!e.utils.smaller(n.val.id,i.val.id)){a.next=15;break}if(null!==i.left){a.next=12;break}return i.left=n,a.abrupt("break",28);case 12:i=i.left;case 13:a.next=26;break;case 15:if(!e.utils.smaller(i.val.id,n.val.id)){a.next=24;break}if(null!==i.right){a.next=21;break}return i.right=n,a.abrupt("break",28);case 21:i=i.right;case 22:a.next=26;break;case 24:return i.val=n.val,a.abrupt("return",i);case 26:a.next=5;break;case 28:this._fixInsert(n),a.next=32;break;case 31:this.root=n;case 32:return this.length++,this.root.blacken(),a.abrupt("return",n);case 35:case"end":return a.stop()}},d,this)})},{key:"_fixInsert",value:function(e){if(null===e.parent)return void e.blacken();if(!e.parent.isBlack()){var t=e.getUncle();null!==t&&t.isRed()?(e.parent.blacken(),t.blacken(),e.grandparent.redden(),this._fixInsert(e.grandparent)):(e===e.parent.right&&e.parent===e.grandparent.left?(e.parent.rotateLeft(this),e=e.left):e===e.parent.left&&e.parent===e.grandparent.right&&(e.parent.rotateRight(this),e=e.right),e.parent.blacken(),e.grandparent.redden(),e===e.parent.left?e.grandparent.rotateRight(this):e.grandparent.rotateLeft(this))}}}]),r}();e.utils.RBTree=r}},{}]},{},[1]);
//# sourceMappingURL=y-memory.js.map