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

1 line
66 KiB
Plaintext

{"version":3,"sources":["../yjs/node_modules/browser-pack/_prelude.js","src/Memory.js","y-memory.js","src/RedBlackTree.js"],"names":["e","t","n","r","s","o","u","a","require","i","f","Error","code","l","exports","call","length",1,"module","_classCallCheck","instance","Constructor","TypeError","_possibleConstructorReturn","self","ReferenceError","_inherits","subClass","superClass","prototype","Object","create","constructor","value","enumerable","writable","configurable","setPrototypeOf","__proto__","extend","Y","Transaction","_Y$Transaction","store","this","_this","getPrototypeOf","ss","os","ds","Database","_Y$AbstractDatabase","y","opts","_this2","utils","RBTree","_createClass","key","requestTransaction","regeneratorRuntime","mark","_callee","wrap","_context","prev","next","console","log","connector","userId","t0","delegateYield","getStateSet","t2","t1","logTable","gc1","gc2","warn","JSON","stringify","listenersById","listenersByIdExecuteNow","transactionInProgress","stop","makeGen","gen","res","done","getNextRequest","destroy","_context2","_get","AbstractDatabase","defineProperties","target","props","descriptor","defineProperty","protoProps","staticProps","get","object","property","receiver","Function","desc","getOwnPropertyDescriptor","undefined","parent","getter","./RedBlackTree.js",2,"_typeof","Symbol","iterator","obj","N","val","color","_left","_right","_parent","id","tree","newParent","right","newRight","left","root","p","newLeft","set","findNext","findWithLowerBound","abrupt","findPrev","findWithUpperBound","from","smaller","to","_context3","findNodeWithLowerBound","_context4","findNodeWithUpperBound","iterate","_context5","compareIds","filter","_context7","o_","_context6","push","table","find","_context8","findNode","Array","_delete","d","isFakeChild","child","_context9","blacken","isBlack","isRed","_fixDelete","node","sibling","redden","rotateLeft","rotateRight","put","v","_context10","_fixInsert","uncle","getUncle","grandparent"],"mappings":"CAAA,QAAAA,GAAAC,EAAAC,EAAAC,GAAA,QAAAC,GAAAC,EAAAC,GAAA,IAAAJ,EAAAG,GAAA,CAAA,IAAAJ,EAAAI,GAAA,CAAA,GAAAE,GAAA,kBAAAC,UAAAA,OAAA,KAAAF,GAAAC,EAAA,MAAAA,GAAAF,GAAA,EAAA,IAAAI,EAAA,MAAA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AEiL,eASdjL,IAAMA,EAAE4G,OAAOiB,OAAS7H,EAAE4G,SAAW5G,EAAEiL,YAAYlD,MACrD/H,EAAE4G,OAAO6D,WAAW/H,MAAK1C,EAIrBA,EAAE+H,MACG/H,IAAMA,EAAE4G,OAAOmB,MAAQ/H,EAAE4G,SAAW5G,EAAEiL,YAAYpD,QAC3D7H,EAAE4G,OAAO8D,YAAYhI,MAAK1C,EAEtBA,EAAE6H,OACP7H,EAIC4G,OAAOsD,UACTlK,EAAEiL,YAAYT,SACVxK,IAAMA,EAAE4G,OAAOmB,KAEjB/H,EAAEiL,YAAYP,YAAYhI,MAG1B1C,EAAEiL,YAAYR,WAAW/H,YAnW3BY,IAyWNhB,GAAEe,MAAMC,OAASA,aD2cR","file":"y-memory.js","sourcesContent":["(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})","/* global Y */\r\n'use strict'\r\n\r\nfunction extend (Y) {\r\n require('./RedBlackTree.js')(Y)\r\n class Transaction extends Y.Transaction {\r\n constructor (store) {\r\n super(store)\r\n this.store = store\r\n this.ss = store.ss\r\n this.os = store.os\r\n this.ds = store.ds\r\n }\r\n }\r\n class Database extends Y.AbstractDatabase {\r\n constructor (y, opts) {\r\n super(y, opts)\r\n this.os = new Y.utils.RBTree()\r\n this.ds = new Y.utils.RBTree()\r\n this.ss = new Y.utils.RBTree()\r\n }\r\n logTable () {\r\n var self = this\r\n self.requestTransaction(function * () {\r\n console.log('User: ', this.store.y.connector.userId, \"==============================\") // eslint-disable-line\r\n console.log(\"State Set (SS):\", yield* this.getStateSet()) // eslint-disable-line\r\n console.log(\"Operation Store (OS):\") // eslint-disable-line\r\n yield* this.os.logTable() // eslint-disable-line\r\n console.log(\"Deletion Store (DS):\") //eslint-disable-line\r\n yield* this.ds.logTable() // eslint-disable-line\r\n if (this.store.gc1.length > 0 || this.store.gc2.length > 0) {\r\n console.warn('GC1|2 not empty!', this.store.gc1, this.store.gc2)\r\n }\r\n if (JSON.stringify(this.store.listenersById) !== '{}') {\r\n console.warn('listenersById not empty!')\r\n }\r\n if (JSON.stringify(this.store.listenersByIdExecuteNow) !== '[]') {\r\n console.warn('listenersByIdExecuteNow not empty!')\r\n }\r\n if (this.store.transactionInProgress) {\r\n console.warn('Transaction still in progress!')\r\n }\r\n }, true)\r\n }\r\n transact (makeGen) {\r\n var t = new Transaction(this)\r\n while (makeGen !== null) {\r\n var gen = makeGen.call(t)\r\n var res = gen.next()\r\n while (!res.done) {\r\n res = gen.next(res.value)\r\n }\r\n makeGen = this.getNextRequest()\r\n }\r\n }\r\n * destroy () {\r\n super.destroy()\r\n delete this.os\r\n delete this.ss\r\n delete this.ds\r\n }\r\n }\r\n Y.extend('memory', Database)\r\n}\r\n\r\nmodule.exports = extend\r\nif (typeof Y !== 'undefined') {\r\n extend(Y)\r\n}\r\n","(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){\n/* global Y */\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if (\"value\" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nfunction extend(Y) {\n require('./RedBlackTree.js')(Y);\n\n var Transaction = function (_Y$Transaction) {\n _inherits(Transaction, _Y$Transaction);\n\n function Transaction(store) {\n _classCallCheck(this, Transaction);\n\n var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Transaction).call(this, store));\n\n _this.store = store;\n _this.ss = store.ss;\n _this.os = store.os;\n _this.ds = store.ds;\n return _this;\n }\n\n return Transaction;\n }(Y.Transaction);\n\n var Database = function (_Y$AbstractDatabase) {\n _inherits(Database, _Y$AbstractDatabase);\n\n function Database(y, opts) {\n _classCallCheck(this, Database);\n\n var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Database).call(this, y, opts));\n\n _this2.os = new Y.utils.RBTree();\n _this2.ds = new Y.utils.RBTree();\n _this2.ss = new Y.utils.RBTree();\n return _this2;\n }\n\n _createClass(Database, [{\n key: 'logTable',\n value: function logTable() {\n var self = this;\n self.requestTransaction(regeneratorRuntime.mark(function _callee() {\n return regeneratorRuntime.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n console.log('User: ', this.store.y.connector.userId, \"==============================\"); // eslint-disable-line\n _context.t0 = console;\n return _context.delegateYield(this.getStateSet(), 't1', 3);\n\n case 3:\n _context.t2 = _context.t1;\n\n _context.t0.log.call(_context.t0, \"State Set (SS):\", _context.t2);\n\n // eslint-disable-line\n console.log(\"Operation Store (OS):\"); // eslint-disable-line\n return _context.delegateYield(this.os.logTable(), 't3', 7);\n\n case 7:\n // eslint-disable-line\n console.log(\"Deletion Store (DS):\"); //eslint-disable-line\n return _context.delegateYield(this.ds.logTable(), 't4', 9);\n\n case 9:\n // eslint-disable-line\n if (this.store.gc1.length > 0 || this.store.gc2.length > 0) {\n console.warn('GC1|2 not empty!', this.store.gc1, this.store.gc2);\n }\n if (JSON.stringify(this.store.listenersById) !== '{}') {\n console.warn('listenersById not empty!');\n }\n if (JSON.stringify(this.store.listenersByIdExecuteNow) !== '[]') {\n console.warn('listenersByIdExecuteNow not empty!');\n }\n if (this.store.transactionInProgress) {\n console.warn('Transaction still in progress!');\n }\n\n case 13:\n case 'end':\n return _context.stop();\n }\n }\n }, _callee, this);\n }), true);\n }\n }, {\n key: 'transact',\n value: function transact(makeGen) {\n var t = new Transaction(this);\n while (makeGen !== null) {\n var gen = makeGen.call(t);\n var res = gen.next();\n while (!res.done) {\n res = gen.next(res.value);\n }\n makeGen = this.getNextRequest();\n }\n }\n }, {\n key: 'destroy',\n value: regeneratorRuntime.mark(function destroy() {\n return regeneratorRuntime.wrap(function destroy$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n _get(Object.getPrototypeOf(Database.prototype), 'destroy', this).call(this);\n delete this.os;\n delete this.ss;\n delete this.ds;\n\n case 4:\n case 'end':\n return _context2.stop();\n }\n }\n }, destroy, this);\n })\n }]);\n\n return Database;\n }(Y.AbstractDatabase);\n\n Y.extend('memory', Database);\n}\n\nmodule.exports = extend;\nif (typeof Y !== 'undefined') {\n extend(Y);\n}\n\n},{\"./RedBlackTree.js\":2}],2:[function(require,module,exports){\n'use strict';\n\n/*\r\n This file contains a not so fancy implemantion of a Red Black Tree.\r\n*/\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol ? \"symbol\" : typeof obj; };\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nmodule.exports = function (Y) {\n var N = function () {\n // A created node is always red!\n\n function N(val) {\n _classCallCheck(this, N);\n\n this.val = val;\n this.color = true;\n this._left = null;\n this._right = null;\n this._parent = null;\n if (val.id === null) {\n throw new Error('You must define id!');\n }\n }\n\n _createClass(N, [{\n key: 'isRed',\n value: function isRed() {\n return this.color;\n }\n }, {\n key: 'isBlack',\n value: function isBlack() {\n return !this.color;\n }\n }, {\n key: 'redden',\n value: function redden() {\n this.color = true;return this;\n }\n }, {\n key: 'blacken',\n value: function blacken() {\n this.color = false;return this;\n }\n }, {\n key: 'rotateLeft',\n value: function rotateLeft(tree) {\n var parent = this.parent;\n var newParent = this.right;\n var newRight = this.right.left;\n newParent.left = this;\n this.right = newRight;\n if (parent === null) {\n tree.root = newParent;\n newParent._parent = null;\n } else if (parent.left === this) {\n parent.left = newParent;\n } else if (parent.right === this) {\n parent.right = newParent;\n } else {\n throw new Error('The elements are wrongly connected!');\n }\n }\n }, {\n key: 'next',\n value: function next() {\n if (this.right !== null) {\n // search the most left node in the right tree\n var o = this.right;\n while (o.left !== null) {\n o = o.left;\n }\n return o;\n } else {\n var p = this;\n while (p.parent !== null && p !== p.parent.left) {\n p = p.parent;\n }\n return p.parent;\n }\n }\n }, {\n key: 'prev',\n value: function prev() {\n if (this.left !== null) {\n // search the most right node in the left tree\n var o = this.left;\n while (o.right !== null) {\n o = o.right;\n }\n return o;\n } else {\n var p = this;\n while (p.parent !== null && p !== p.parent.right) {\n p = p.parent;\n }\n return p.parent;\n }\n }\n }, {\n key: 'rotateRight',\n value: function rotateRight(tree) {\n var parent = this.parent;\n var newParent = this.left;\n var newLeft = this.left.right;\n newParent.right = this;\n this.left = newLeft;\n if (parent === null) {\n tree.root = newParent;\n newParent._parent = null;\n } else if (parent.left === this) {\n parent.left = newParent;\n } else if (parent.right === this) {\n parent.right = newParent;\n } else {\n throw new Error('The elements are wrongly connected!');\n }\n }\n }, {\n key: 'getUncle',\n value: function getUncle() {\n // we can assume that grandparent exists when this is called!\n if (this.parent === this.parent.parent.left) {\n return this.parent.parent.right;\n } else {\n return this.parent.parent.left;\n }\n }\n }, {\n key: 'grandparent',\n get: function get() {\n return this.parent.parent;\n }\n }, {\n key: 'parent',\n get: function get() {\n return this._parent;\n }\n }, {\n key: 'sibling',\n get: function get() {\n return this === this.parent.left ? this.parent.right : this.parent.left;\n }\n }, {\n key: 'left',\n get: function get() {\n return this._left;\n },\n set: function set(n) {\n if (n !== null) {\n n._parent = this;\n }\n this._left = n;\n }\n }, {\n key: 'right',\n get: function get() {\n return this._right;\n },\n set: function set(n) {\n if (n !== null) {\n n._parent = this;\n }\n this._right = n;\n }\n }]);\n\n return N;\n }();\n\n var RBTree = function () {\n function RBTree() {\n _classCallCheck(this, RBTree);\n\n this.root = null;\n this.length = 0;\n }\n\n _createClass(RBTree, [{\n key: 'findNext',\n value: regeneratorRuntime.mark(function findNext(id) {\n return regeneratorRuntime.wrap(function findNext$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n return _context.delegateYield(this.findWithLowerBound([id[0], id[1] + 1]), 't0', 1);\n\n case 1:\n return _context.abrupt('return', _context.t0);\n\n case 2:\n case 'end':\n return _context.stop();\n }\n }\n }, findNext, this);\n })\n }, {\n key: 'findPrev',\n value: regeneratorRuntime.mark(function findPrev(id) {\n return regeneratorRuntime.wrap(function findPrev$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n return _context2.delegateYield(this.findWithUpperBound([id[0], id[1] - 1]), 't0', 1);\n\n case 1:\n return _context2.abrupt('return', _context2.t0);\n\n case 2:\n case 'end':\n return _context2.stop();\n }\n }\n }, findPrev, this);\n })\n }, {\n key: 'findNodeWithLowerBound',\n value: function findNodeWithLowerBound(from) {\n if (from === void 0) {\n throw new Error('You must define from!');\n }\n var o = this.root;\n if (o === null) {\n return null;\n } else {\n while (true) {\n if ((from === null || Y.utils.smaller(from, o.val.id)) && o.left !== null) {\n // o is included in the bound\n // try to find an element that is closer to the bound\n o = o.left;\n } else if (from !== null && Y.utils.smaller(o.val.id, from)) {\n // o is not within the bound, maybe one of the right elements is..\n if (o.right !== null) {\n o = o.right;\n } else {\n // there is no right element. Search for the next bigger element,\n // this should be within the bounds\n return o.next();\n }\n } else {\n return o;\n }\n }\n }\n }\n }, {\n key: 'findNodeWithUpperBound',\n value: function findNodeWithUpperBound(to) {\n if (to === void 0) {\n throw new Error('You must define from!');\n }\n var o = this.root;\n if (o === null) {\n return null;\n } else {\n while (true) {\n if ((to === null || Y.utils.smaller(o.val.id, to)) && o.right !== null) {\n // o is included in the bound\n // try to find an element that is closer to the bound\n o = o.right;\n } else if (to !== null && Y.utils.smaller(to, o.val.id)) {\n // o is not within the bound, maybe one of the left elements is..\n if (o.left !== null) {\n o = o.left;\n } else {\n // there is no left element. Search for the prev smaller element,\n // this should be within the bounds\n return o.prev();\n }\n } else {\n return o;\n }\n }\n }\n }\n }, {\n key: 'findWithLowerBound',\n value: regeneratorRuntime.mark(function findWithLowerBound(from) {\n var n;\n return regeneratorRuntime.wrap(function findWithLowerBound$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n n = this.findNodeWithLowerBound(from);\n return _context3.abrupt('return', n == null ? null : n.val);\n\n case 2:\n case 'end':\n return _context3.stop();\n }\n }\n }, findWithLowerBound, this);\n })\n }, {\n key: 'findWithUpperBound',\n value: regeneratorRuntime.mark(function findWithUpperBound(to) {\n var n;\n return regeneratorRuntime.wrap(function findWithUpperBound$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n n = this.findNodeWithUpperBound(to);\n return _context4.abrupt('return', n == null ? null : n.val);\n\n case 2:\n case 'end':\n return _context4.stop();\n }\n }\n }, findWithUpperBound, this);\n })\n }, {\n key: 'iterate',\n value: regeneratorRuntime.mark(function iterate(t, from, to, f) {\n var o;\n return regeneratorRuntime.wrap(function iterate$(_context5) {\n while (1) {\n switch (_context5.prev = _context5.next) {\n case 0:\n o = this.findNodeWithLowerBound(from);\n\n case 1:\n if (!(o !== null && (to === null || Y.utils.smaller(o.val.id, to) || Y.utils.compareIds(o.val.id, to)))) {\n _context5.next = 6;\n break;\n }\n\n return _context5.delegateYield(f.call(t, o.val), 't0', 3);\n\n case 3:\n o = o.next();\n _context5.next = 1;\n break;\n\n case 6:\n return _context5.abrupt('return', true);\n\n case 7:\n case 'end':\n return _context5.stop();\n }\n }\n }, iterate, this);\n })\n }, {\n key: 'logTable',\n value: regeneratorRuntime.mark(function logTable(from, to, filter) {\n var os;\n return regeneratorRuntime.wrap(function logTable$(_context7) {\n while (1) {\n switch (_context7.prev = _context7.next) {\n case 0:\n if (filter == null) {\n filter = function filter() {\n return true;\n };\n }\n if (from == null) {\n from = null;\n }\n if (to == null) {\n to = null;\n }\n os = [];\n return _context7.delegateYield(this.iterate(this, from, to, regeneratorRuntime.mark(function _callee(o) {\n var o_, key;\n return regeneratorRuntime.wrap(function _callee$(_context6) {\n while (1) {\n switch (_context6.prev = _context6.next) {\n case 0:\n if (filter(o)) {\n o_ = {};\n\n for (key in o) {\n if (_typeof(o[key]) === 'object') {\n o_[key] = JSON.stringify(o[key]);\n } else {\n o_[key] = o[key];\n }\n }\n os.push(o_);\n }\n\n case 1:\n case 'end':\n return _context6.stop();\n }\n }\n }, _callee, this);\n })), 't0', 5);\n\n case 5:\n if (console.table != null) {\n console.table(os);\n }\n\n case 6:\n case 'end':\n return _context7.stop();\n }\n }\n }, logTable, this);\n })\n }, {\n key: 'find',\n value: regeneratorRuntime.mark(function find(id) {\n var n;\n return regeneratorRuntime.wrap(function find$(_context8) {\n while (1) {\n switch (_context8.prev = _context8.next) {\n case 0:\n return _context8.abrupt('return', (n = this.findNode(id)) ? n.val : null);\n\n case 1:\n case 'end':\n return _context8.stop();\n }\n }\n }, find, this);\n })\n }, {\n key: 'findNode',\n value: function findNode(id) {\n if (id == null || id.constructor !== Array) {\n throw new Error('Expect id to be an array!');\n }\n var o = this.root;\n if (o === null) {\n return false;\n } else {\n while (true) {\n if (o === null) {\n return false;\n }\n if (Y.utils.smaller(id, o.val.id)) {\n o = o.left;\n } else if (Y.utils.smaller(o.val.id, id)) {\n o = o.right;\n } else {\n return o;\n }\n }\n }\n }\n }, {\n key: 'delete',\n value: regeneratorRuntime.mark(function _delete(id) {\n var d, o, isFakeChild, child;\n return regeneratorRuntime.wrap(function _delete$(_context9) {\n while (1) {\n switch (_context9.prev = _context9.next) {\n case 0:\n if (!(id == null || id.constructor !== Array)) {\n _context9.next = 2;\n break;\n }\n\n throw new Error('id is expected to be an Array!');\n\n case 2:\n d = this.findNode(id);\n\n if (!(d == null)) {\n _context9.next = 5;\n break;\n }\n\n throw new Error('Element does not exist!');\n\n case 5:\n this.length--;\n if (d.left !== null && d.right !== null) {\n // switch d with the greates element in the left subtree.\n // o should have at most one child.\n o = d.left;\n // find\n\n while (o.right !== null) {\n o = o.right;\n }\n // switch\n d.val = o.val;\n d = o;\n }\n // d has at most one child\n // let n be the node that replaces d\n child = d.left || d.right;\n\n if (child === null) {\n isFakeChild = true;\n child = new N({ id: 0 });\n child.blacken();\n d.right = child;\n } else {\n isFakeChild = false;\n }\n\n if (!(d.parent === null)) {\n _context9.next = 14;\n break;\n }\n\n if (!isFakeChild) {\n this.root = child;\n child.blacken();\n child._parent = null;\n } else {\n this.root = null;\n }\n return _context9.abrupt('return');\n\n case 14:\n if (!(d.parent.left === d)) {\n _context9.next = 18;\n break;\n }\n\n d.parent.left = child;\n _context9.next = 23;\n break;\n\n case 18:\n if (!(d.parent.right === d)) {\n _context9.next = 22;\n break;\n }\n\n d.parent.right = child;\n _context9.next = 23;\n break;\n\n case 22:\n throw new Error('Impossible!');\n\n case 23:\n if (d.isBlack()) {\n if (child.isRed()) {\n child.blacken();\n } else {\n this._fixDelete(child);\n }\n }\n this.root.blacken();\n\n if (!isFakeChild) {\n _context9.next = 35;\n break;\n }\n\n if (!(child.parent.left === child)) {\n _context9.next = 30;\n break;\n }\n\n child.parent.left = null;\n _context9.next = 35;\n break;\n\n case 30:\n if (!(child.parent.right === child)) {\n _context9.next = 34;\n break;\n }\n\n child.parent.right = null;\n _context9.next = 35;\n break;\n\n case 34:\n throw new Error('Impossible #3');\n\n case 35:\n case 'end':\n return _context9.stop();\n }\n }\n }, _delete, this);\n })\n }, {\n key: '_fixDelete',\n value: function _fixDelete(n) {\n function isBlack(node) {\n return node !== null ? node.isBlack() : true;\n }\n function isRed(node) {\n return node !== null ? node.isRed() : false;\n }\n if (n.parent === null) {\n // this can only be called after the first iteration of fixDelete.\n return;\n }\n // d was already replaced by the child\n // d is not the root\n // d and child are black\n var sibling = n.sibling;\n if (isRed(sibling)) {\n // make sibling the grandfather\n n.parent.redden();\n sibling.blacken();\n if (n === n.parent.left) {\n n.parent.rotateLeft(this);\n } else if (n === n.parent.right) {\n n.parent.rotateRight(this);\n } else {\n throw new Error('Impossible #2');\n }\n sibling = n.sibling;\n }\n // parent, sibling, and children of n are black\n if (n.parent.isBlack() && sibling.isBlack() && isBlack(sibling.left) && isBlack(sibling.right)) {\n sibling.redden();\n this._fixDelete(n.parent);\n } else if (n.parent.isRed() && sibling.isBlack() && isBlack(sibling.left) && isBlack(sibling.right)) {\n sibling.redden();\n n.parent.blacken();\n } else {\n if (n === n.parent.left && sibling.isBlack() && isRed(sibling.left) && isBlack(sibling.right)) {\n sibling.redden();\n sibling.left.blacken();\n sibling.rotateRight(this);\n sibling = n.sibling;\n } else if (n === n.parent.right && sibling.isBlack() && isRed(sibling.right) && isBlack(sibling.left)) {\n sibling.redden();\n sibling.right.blacken();\n sibling.rotateLeft(this);\n sibling = n.sibling;\n }\n sibling.color = n.parent.color;\n n.parent.blacken();\n if (n === n.parent.left) {\n sibling.right.blacken();\n n.parent.rotateLeft(this);\n } else {\n sibling.left.blacken();\n n.parent.rotateRight(this);\n }\n }\n }\n }, {\n key: 'put',\n value: regeneratorRuntime.mark(function put(v) {\n var node, p;\n return regeneratorRuntime.wrap(function put$(_context10) {\n while (1) {\n switch (_context10.prev = _context10.next) {\n case 0:\n if (!(v == null || v.id == null || v.id.constructor !== Array)) {\n _context10.next = 2;\n break;\n }\n\n throw new Error('v is expected to have an id property which is an Array!');\n\n case 2:\n node = new N(v);\n\n if (!(this.root !== null)) {\n _context10.next = 31;\n break;\n }\n\n p = this.root; // p abbrev. parent\n\n case 5:\n if (!true) {\n _context10.next = 28;\n break;\n }\n\n if (!Y.utils.smaller(node.val.id, p.val.id)) {\n _context10.next = 15;\n break;\n }\n\n if (!(p.left === null)) {\n _context10.next = 12;\n break;\n }\n\n p.left = node;\n return _context10.abrupt('break', 28);\n\n case 12:\n p = p.left;\n\n case 13:\n _context10.next = 26;\n break;\n\n case 15:\n if (!Y.utils.smaller(p.val.id, node.val.id)) {\n _context10.next = 24;\n break;\n }\n\n if (!(p.right === null)) {\n _context10.next = 21;\n break;\n }\n\n p.right = node;\n return _context10.abrupt('break', 28);\n\n case 21:\n p = p.right;\n\n case 22:\n _context10.next = 26;\n break;\n\n case 24:\n p.val = node.val;\n return _context10.abrupt('return', p);\n\n case 26:\n _context10.next = 5;\n break;\n\n case 28:\n this._fixInsert(node);\n _context10.next = 32;\n break;\n\n case 31:\n this.root = node;\n\n case 32:\n this.length++;\n this.root.blacken();\n return _context10.abrupt('return', node);\n\n case 35:\n case 'end':\n return _context10.stop();\n }\n }\n }, put, this);\n })\n }, {\n key: '_fixInsert',\n value: function _fixInsert(n) {\n if (n.parent === null) {\n n.blacken();\n return;\n } else if (n.parent.isBlack()) {\n return;\n }\n var uncle = n.getUncle();\n if (uncle !== null && uncle.isRed()) {\n // Note: parent: red, uncle: red\n n.parent.blacken();\n uncle.blacken();\n n.grandparent.redden();\n this._fixInsert(n.grandparent);\n } else {\n // Note: parent: red, uncle: black or null\n // Now we transform the tree in such a way that\n // either of these holds:\n // 1) grandparent.left.isRed\n // and grandparent.left.left.isRed\n // 2) grandparent.right.isRed\n // and grandparent.right.right.isRed\n if (n === n.parent.right && n.parent === n.grandparent.left) {\n n.parent.rotateLeft(this);\n // Since we rotated and want to use the previous\n // cases, we need to set n in such a way that\n // n.parent.isRed again\n n = n.left;\n } else if (n === n.parent.left && n.parent === n.grandparent.right) {\n n.parent.rotateRight(this);\n // see above\n n = n.right;\n }\n // Case 1) or 2) hold from here on.\n // Now traverse grandparent, make parent a black node\n // on the highest level which holds two red nodes.\n n.parent.blacken();\n n.grandparent.redden();\n if (n === n.parent.left) {\n // Case 1\n n.grandparent.rotateRight(this);\n } else {\n // Case 2\n n.grandparent.rotateLeft(this);\n }\n }\n }\n }]);\n\n return RBTree;\n }();\n\n Y.utils.RBTree = RBTree;\n};\n\n},{}]},{},[1])\n\n","'use strict'\r\n\r\n/*\r\n This file contains a not so fancy implemantion of a Red Black Tree.\r\n*/\r\nmodule.exports = function (Y) {\r\n class N {\r\n // A created node is always red!\r\n constructor (val) {\r\n this.val = val\r\n this.color = true\r\n this._left = null\r\n this._right = null\r\n this._parent = null\r\n if (val.id === null) {\r\n throw new Error('You must define id!')\r\n }\r\n }\r\n isRed () { return this.color }\r\n isBlack () { return !this.color }\r\n redden () { this.color = true; return this }\r\n blacken () { this.color = false; return this }\r\n get grandparent () {\r\n return this.parent.parent\r\n }\r\n get parent () {\r\n return this._parent\r\n }\r\n get sibling () {\r\n return (this === this.parent.left)\r\n ? this.parent.right : this.parent.left\r\n }\r\n get left () {\r\n return this._left\r\n }\r\n get right () {\r\n return this._right\r\n }\r\n set left (n) {\r\n if (n !== null) {\r\n n._parent = this\r\n }\r\n this._left = n\r\n }\r\n set right (n) {\r\n if (n !== null) {\r\n n._parent = this\r\n }\r\n this._right = n\r\n }\r\n rotateLeft (tree) {\r\n var parent = this.parent\r\n var newParent = this.right\r\n var newRight = this.right.left\r\n newParent.left = this\r\n this.right = newRight\r\n if (parent === null) {\r\n tree.root = newParent\r\n newParent._parent = null\r\n } else if (parent.left === this) {\r\n parent.left = newParent\r\n } else if (parent.right === this) {\r\n parent.right = newParent\r\n } else {\r\n throw new Error('The elements are wrongly connected!')\r\n }\r\n }\r\n next () {\r\n if (this.right !== null) {\r\n // search the most left node in the right tree\r\n var o = this.right\r\n while (o.left !== null) {\r\n o = o.left\r\n }\r\n return o\r\n } else {\r\n var p = this\r\n while (p.parent !== null && p !== p.parent.left) {\r\n p = p.parent\r\n }\r\n return p.parent\r\n }\r\n }\r\n prev () {\r\n if (this.left !== null) {\r\n // search the most right node in the left tree\r\n var o = this.left\r\n while (o.right !== null) {\r\n o = o.right\r\n }\r\n return o\r\n } else {\r\n var p = this\r\n while (p.parent !== null && p !== p.parent.right) {\r\n p = p.parent\r\n }\r\n return p.parent\r\n }\r\n }\r\n rotateRight (tree) {\r\n var parent = this.parent\r\n var newParent = this.left\r\n var newLeft = this.left.right\r\n newParent.right = this\r\n this.left = newLeft\r\n if (parent === null) {\r\n tree.root = newParent\r\n newParent._parent = null\r\n } else if (parent.left === this) {\r\n parent.left = newParent\r\n } else if (parent.right === this) {\r\n parent.right = newParent\r\n } else {\r\n throw new Error('The elements are wrongly connected!')\r\n }\r\n }\r\n getUncle () {\r\n // we can assume that grandparent exists when this is called!\r\n if (this.parent === this.parent.parent.left) {\r\n return this.parent.parent.right\r\n } else {\r\n return this.parent.parent.left\r\n }\r\n }\r\n }\r\n\r\n class RBTree {\r\n constructor () {\r\n this.root = null\r\n this.length = 0\r\n }\r\n * findNext (id) {\r\n return yield* this.findWithLowerBound([id[0], id[1] + 1])\r\n }\r\n * findPrev (id) {\r\n return yield* this.findWithUpperBound([id[0], id[1] - 1])\r\n }\r\n findNodeWithLowerBound (from) {\r\n if (from === void 0) {\r\n throw new Error('You must define from!')\r\n }\r\n var o = this.root\r\n if (o === null) {\r\n return null\r\n } else {\r\n while (true) {\r\n if ((from === null || Y.utils.smaller(from, o.val.id)) && o.left !== null) {\r\n // o is included in the bound\r\n // try to find an element that is closer to the bound\r\n o = o.left\r\n } else if (from !== null && Y.utils.smaller(o.val.id, from)) {\r\n // o is not within the bound, maybe one of the right elements is..\r\n if (o.right !== null) {\r\n o = o.right\r\n } else {\r\n // there is no right element. Search for the next bigger element,\r\n // this should be within the bounds\r\n return o.next()\r\n }\r\n } else {\r\n return o\r\n }\r\n }\r\n }\r\n }\r\n findNodeWithUpperBound (to) {\r\n if (to === void 0) {\r\n throw new Error('You must define from!')\r\n }\r\n var o = this.root\r\n if (o === null) {\r\n return null\r\n } else {\r\n while (true) {\r\n if ((to === null || Y.utils.smaller(o.val.id, to)) && o.right !== null) {\r\n // o is included in the bound\r\n // try to find an element that is closer to the bound\r\n o = o.right\r\n } else if (to !== null && Y.utils.smaller(to, o.val.id)) {\r\n // o is not within the bound, maybe one of the left elements is..\r\n if (o.left !== null) {\r\n o = o.left\r\n } else {\r\n // there is no left element. Search for the prev smaller element,\r\n // this should be within the bounds\r\n return o.prev()\r\n }\r\n } else {\r\n return o\r\n }\r\n }\r\n }\r\n }\r\n * findWithLowerBound (from) {\r\n var n = this.findNodeWithLowerBound(from)\r\n return n == null ? null : n.val\r\n }\r\n * findWithUpperBound (to) {\r\n var n = this.findNodeWithUpperBound(to)\r\n return n == null ? null : n.val\r\n }\r\n * iterate (t, from, to, f) {\r\n var o = this.findNodeWithLowerBound(from)\r\n while (o !== null && (to === null || Y.utils.smaller(o.val.id, to) || Y.utils.compareIds(o.val.id, to))) {\r\n yield* f.call(t, o.val)\r\n o = o.next()\r\n }\r\n return true\r\n }\r\n * logTable (from, to, filter) {\r\n if (filter == null) {\r\n filter = function () {\r\n return true\r\n }\r\n }\r\n if (from == null) { from = null }\r\n if (to == null) { to = null }\r\n var os = []\r\n yield* this.iterate(this, from, to, function * (o) {\r\n if (filter(o)) {\r\n var o_ = {}\r\n for (var key in o) {\r\n if (typeof o[key] === 'object') {\r\n o_[key] = JSON.stringify(o[key])\r\n } else {\r\n o_[key] = o[key]\r\n }\r\n }\r\n os.push(o_)\r\n }\r\n })\r\n if (console.table != null) {\r\n console.table(os)\r\n }\r\n }\r\n * find (id) {\r\n var n\r\n return (n = this.findNode(id)) ? n.val : null\r\n }\r\n findNode (id) {\r\n if (id == null || id.constructor !== Array) {\r\n throw new Error('Expect id to be an array!')\r\n }\r\n var o = this.root\r\n if (o === null) {\r\n return false\r\n } else {\r\n while (true) {\r\n if (o === null) {\r\n return false\r\n }\r\n if (Y.utils.smaller(id, o.val.id)) {\r\n o = o.left\r\n } else if (Y.utils.smaller(o.val.id, id)) {\r\n o = o.right\r\n } else {\r\n return o\r\n }\r\n }\r\n }\r\n }\r\n * delete (id) {\r\n if (id == null || id.constructor !== Array) {\r\n throw new Error('id is expected to be an Array!')\r\n }\r\n var d = this.findNode(id)\r\n if (d == null) {\r\n throw new Error('Element does not exist!')\r\n }\r\n this.length--\r\n if (d.left !== null && d.right !== null) {\r\n // switch d with the greates element in the left subtree.\r\n // o should have at most one child.\r\n var o = d.left\r\n // find\r\n while (o.right !== null) {\r\n o = o.right\r\n }\r\n // switch\r\n d.val = o.val\r\n d = o\r\n }\r\n // d has at most one child\r\n // let n be the node that replaces d\r\n var isFakeChild\r\n var child = d.left || d.right\r\n if (child === null) {\r\n isFakeChild = true\r\n child = new N({id: 0})\r\n child.blacken()\r\n d.right = child\r\n } else {\r\n isFakeChild = false\r\n }\r\n\r\n if (d.parent === null) {\r\n if (!isFakeChild) {\r\n this.root = child\r\n child.blacken()\r\n child._parent = null\r\n } else {\r\n this.root = null\r\n }\r\n return\r\n } else if (d.parent.left === d) {\r\n d.parent.left = child\r\n } else if (d.parent.right === d) {\r\n d.parent.right = child\r\n } else {\r\n throw new Error('Impossible!')\r\n }\r\n if (d.isBlack()) {\r\n if (child.isRed()) {\r\n child.blacken()\r\n } else {\r\n this._fixDelete(child)\r\n }\r\n }\r\n this.root.blacken()\r\n if (isFakeChild) {\r\n if (child.parent.left === child) {\r\n child.parent.left = null\r\n } else if (child.parent.right === child) {\r\n child.parent.right = null\r\n } else {\r\n throw new Error('Impossible #3')\r\n }\r\n }\r\n }\r\n _fixDelete (n) {\r\n function isBlack (node) {\r\n return node !== null ? node.isBlack() : true\r\n }\r\n function isRed (node) {\r\n return node !== null ? node.isRed() : false\r\n }\r\n if (n.parent === null) {\r\n // this can only be called after the first iteration of fixDelete.\r\n return\r\n }\r\n // d was already replaced by the child\r\n // d is not the root\r\n // d and child are black\r\n var sibling = n.sibling\r\n if (isRed(sibling)) {\r\n // make sibling the grandfather\r\n n.parent.redden()\r\n sibling.blacken()\r\n if (n === n.parent.left) {\r\n n.parent.rotateLeft(this)\r\n } else if (n === n.parent.right) {\r\n n.parent.rotateRight(this)\r\n } else {\r\n throw new Error('Impossible #2')\r\n }\r\n sibling = n.sibling\r\n }\r\n // parent, sibling, and children of n are black\r\n if (n.parent.isBlack() &&\r\n sibling.isBlack() &&\r\n isBlack(sibling.left) &&\r\n isBlack(sibling.right)\r\n ) {\r\n sibling.redden()\r\n this._fixDelete(n.parent)\r\n } else if (n.parent.isRed() &&\r\n sibling.isBlack() &&\r\n isBlack(sibling.left) &&\r\n isBlack(sibling.right)\r\n ) {\r\n sibling.redden()\r\n n.parent.blacken()\r\n } else {\r\n if (n === n.parent.left &&\r\n sibling.isBlack() &&\r\n isRed(sibling.left) &&\r\n isBlack(sibling.right)\r\n ) {\r\n sibling.redden()\r\n sibling.left.blacken()\r\n sibling.rotateRight(this)\r\n sibling = n.sibling\r\n } else if (n === n.parent.right &&\r\n sibling.isBlack() &&\r\n isRed(sibling.right) &&\r\n isBlack(sibling.left)\r\n ) {\r\n sibling.redden()\r\n sibling.right.blacken()\r\n sibling.rotateLeft(this)\r\n sibling = n.sibling\r\n }\r\n sibling.color = n.parent.color\r\n n.parent.blacken()\r\n if (n === n.parent.left) {\r\n sibling.right.blacken()\r\n n.parent.rotateLeft(this)\r\n } else {\r\n sibling.left.blacken()\r\n n.parent.rotateRight(this)\r\n }\r\n }\r\n }\r\n * put (v) {\r\n if (v == null || v.id == null || v.id.constructor !== Array) {\r\n throw new Error('v is expected to have an id property which is an Array!')\r\n }\r\n var node = new N(v)\r\n if (this.root !== null) {\r\n var p = this.root // p abbrev. parent\r\n while (true) {\r\n if (Y.utils.smaller(node.val.id, p.val.id)) {\r\n if (p.left === null) {\r\n p.left = node\r\n break\r\n } else {\r\n p = p.left\r\n }\r\n } else if (Y.utils.smaller(p.val.id, node.val.id)) {\r\n if (p.right === null) {\r\n p.right = node\r\n break\r\n } else {\r\n p = p.right\r\n }\r\n } else {\r\n p.val = node.val\r\n return p\r\n }\r\n }\r\n this._fixInsert(node)\r\n } else {\r\n this.root = node\r\n }\r\n this.length++\r\n this.root.blacken()\r\n return node\r\n }\r\n _fixInsert (n) {\r\n if (n.parent === null) {\r\n n.blacken()\r\n return\r\n } else if (n.parent.isBlack()) {\r\n return\r\n }\r\n var uncle = n.getUncle()\r\n if (uncle !== null && uncle.isRed()) {\r\n // Note: parent: red, uncle: red\r\n n.parent.blacken()\r\n uncle.blacken()\r\n n.grandparent.redden()\r\n this._fixInsert(n.grandparent)\r\n } else {\r\n // Note: parent: red, uncle: black or null\r\n // Now we transform the tree in such a way that\r\n // either of these holds:\r\n // 1) grandparent.left.isRed\r\n // and grandparent.left.left.isRed\r\n // 2) grandparent.right.isRed\r\n // and grandparent.right.right.isRed\r\n if (n === n.parent.right && n.parent === n.grandparent.left) {\r\n n.parent.rotateLeft(this)\r\n // Since we rotated and want to use the previous\r\n // cases, we need to set n in such a way that\r\n // n.parent.isRed again\r\n n = n.left\r\n } else if (n === n.parent.left && n.parent === n.grandparent.right) {\r\n n.parent.rotateRight(this)\r\n // see above\r\n n = n.right\r\n }\r\n // Case 1) or 2) hold from here on.\r\n // Now traverse grandparent, make parent a black node\r\n // on the highest level which holds two red nodes.\r\n n.parent.blacken()\r\n n.grandparent.redden()\r\n if (n === n.parent.left) {\r\n // Case 1\r\n n.grandparent.rotateRight(this)\r\n } else {\r\n // Case 2\r\n n.grandparent.rotateLeft(this)\r\n }\r\n }\r\n }\r\n }\r\n\r\n Y.utils.RBTree = RBTree\r\n}\r\n"],"sourceRoot":"/source/"}