1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 62× 62× 62× 1× 1× 1× 2× 2× 2× 2× 2× 2× 1× 2× 2× 2× 2× 2× 2× 1× 1× 1× 4× 4× 4× 4× 4× 1× 174× 1× 60× 60× 1× 18× 18× 18× 61× 18× 61× 18× 1× 6× 1× 31× 31× 104× 1× 15× 1× 2× 2× 10× 2× 8× 1× 1× 1× 1× 1× 1× 1× 2× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 2× 2× 1× 2× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× | /*! * @author electricessence / https://github.com/electricessence/ * Based Upon: http://msdn.microsoft.com/en-us/library/he2s3bh7%28v=vs.110%29.aspx * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md */ var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; (function (factory) { Eif (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); Iif (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { define(["require", "exports", "../Compare", "./LinkedNodeList", "../Exceptions/InvalidOperationException", "../Exceptions/ArgumentNullException", "./CollectionBase"], factory); } })(function (require, exports) { "use strict"; var Compare_1 = require("../Compare"); var LinkedNodeList_1 = require("./LinkedNodeList"); var InvalidOperationException_1 = require("../Exceptions/InvalidOperationException"); var ArgumentNullException_1 = require("../Exceptions/ArgumentNullException"); var CollectionBase_1 = require("./CollectionBase"); var InternalNode = (function () { function InternalNode(value, previous, next) { this.value = value; this.previous = previous; this.next = next; } InternalNode.prototype.assertDetached = function () { if (this.next || this.previous) throw new InvalidOperationException_1.InvalidOperationException("Adding a node that is already placed."); }; return InternalNode; }()); function ensureExternal(node, list) { Iif (!node) return null; Iif (!list) throw new ArgumentNullException_1.ArgumentNullException("list"); var external = node.external; Eif (!external) node.external = external = new LinkedListNode(list, node); return external; } function getInternal(node, list) { Iif (!node) throw new ArgumentNullException_1.ArgumentNullException("node"); Iif (!list) throw new ArgumentNullException_1.ArgumentNullException("list"); Iif (node.list != list) throw new InvalidOperationException_1.InvalidOperationException("Provided node does not belong to this list."); var n = node._nodeInternal; Iif (!n) throw new InvalidOperationException_1.InvalidOperationException("Provided node is not valid."); return n; } var LinkedList = (function (_super) { __extends(LinkedList, _super); function LinkedList(source, equalityComparer) { Eif (equalityComparer === void 0) { equalityComparer = Compare_1.areEqual; } _super.call(this, null, equalityComparer); var _ = this; _._listInternal = new LinkedNodeList_1.LinkedNodeList(); _._importEntries(source); } LinkedList.prototype.getCount = function () { return this._listInternal.unsafeCount; }; LinkedList.prototype._addInternal = function (entry) { this._listInternal.addNode(new InternalNode(entry)); return true; }; LinkedList.prototype._removeInternal = function (entry, max) { Iif (max === void 0) { max = Infinity; } var _ = this, equals = _._equalityComparer, list = _._listInternal, removedCount = 0; list.forEach(function (node) { if (equals(entry, node.value) && list.removeNode(node)) removedCount++; return removedCount < max; }); return removedCount; }; LinkedList.prototype._clearInternal = function () { return this._listInternal.clear(); }; LinkedList.prototype.forEach = function (action, useCopy) { Eif (useCopy === void 0) { useCopy = false; } return useCopy ? _super.prototype.forEach.call(this, action, useCopy) : this._listInternal.forEach(function (node, i) { return action(node.value, i); }); }; LinkedList.prototype.getEnumerator = function () { return LinkedNodeList_1.LinkedNodeList.valueEnumeratorFrom(this._listInternal); }; LinkedList.prototype._findFirst = function (entry) { var _ = this, equals = _._equalityComparer, next = _._listInternal.first; while (next) { if (equals(entry, next.value)) return next; next = next.next; } return null; }; LinkedList.prototype._findLast = function (entry) { var _ = this, equals = _._equalityComparer, prev = _._listInternal.last; while (prev) { if (equals(entry, prev.value)) return prev; prev = prev.previous; } return null; }; LinkedList.prototype.removeOnce = function (entry) { return this.remove(entry, 1) !== 0; }; Object.defineProperty(LinkedList.prototype, "first", { get: function () { return ensureExternal(this._listInternal.first, this); }, enumerable: true, configurable: true }); Object.defineProperty(LinkedList.prototype, "last", { get: function () { return ensureExternal(this._listInternal.last, this); }, enumerable: true, configurable: true }); LinkedList.prototype.getValueAt = function (index) { var node = this._listInternal.getNodeAt(index); if (!node) return node && node.value || void (0); }; LinkedList.prototype.getNodeAt = function (index) { return ensureExternal(this._listInternal.getNodeAt(index), this); }; LinkedList.prototype.find = function (entry) { return ensureExternal(this._findFirst(entry), this); }; LinkedList.prototype.findLast = function (entry) { return ensureExternal(this._findLast(entry), this); }; LinkedList.prototype.addFirst = function (entry) { this._listInternal.addNodeBefore(new InternalNode(entry)); this._signalModification(true); }; LinkedList.prototype.addLast = function (entry) { this.add(entry); }; LinkedList.prototype.removeFirst = function () { var _ = this, first = _._listInternal.first; if (first && _._listInternal.removeNode(first)) _._signalModification(true); }; LinkedList.prototype.removeLast = function () { var _ = this, last = _._listInternal.last; if (last && _._listInternal.removeNode(last)) _._signalModification(true); }; LinkedList.prototype.removeNode = function (node) { var _ = this; if (_._listInternal.removeNode(getInternal(node, _))) { _._signalModification(true); return true; } return false; }; LinkedList.prototype.addBefore = function (before, entry) { var _ = this; _._listInternal.addNodeBefore(new InternalNode(entry), getInternal(before, _)); _._signalModification(true); }; LinkedList.prototype.addAfter = function (after, entry) { var _ = this; _._listInternal.addNodeAfter(new InternalNode(entry), getInternal(after, _)); _._signalModification(true); }; LinkedList.prototype.addNodeBefore = function (node, before) { var _ = this; _._listInternal.addNodeBefore(getInternal(before, _), getInternal(node, _)); _._signalModification(true); }; LinkedList.prototype.addNodeAfter = function (node, after) { var _ = this; this._listInternal.addNodeAfter(getInternal(after, _), getInternal(node, _)); _._signalModification(true); }; return LinkedList; }(CollectionBase_1.CollectionBase)); exports.LinkedList = LinkedList; var LinkedListNode = (function () { function LinkedListNode(_list, _nodeInternal) { this._list = _list; this._nodeInternal = _nodeInternal; } Object.defineProperty(LinkedListNode.prototype, "list", { get: function () { return this._list; }, enumerable: true, configurable: true }); Object.defineProperty(LinkedListNode.prototype, "previous", { get: function () { return ensureExternal(this._nodeInternal.previous, this._list); }, enumerable: true, configurable: true }); Object.defineProperty(LinkedListNode.prototype, "next", { get: function () { return ensureExternal(this._nodeInternal.next, this._list); }, enumerable: true, configurable: true }); Object.defineProperty(LinkedListNode.prototype, "value", { get: function () { return this._nodeInternal.value; }, set: function (v) { this._nodeInternal.value = v; }, enumerable: true, configurable: true }); LinkedListNode.prototype.addBefore = function (entry) { this._list.addBefore(this, entry); }; LinkedListNode.prototype.addAfter = function (entry) { this._list.addAfter(this, entry); }; LinkedListNode.prototype.addNodeBefore = function (before) { this._list.addNodeBefore(this, before); }; LinkedListNode.prototype.addNodeAfter = function (after) { this._list.addNodeAfter(this, after); }; LinkedListNode.prototype.remove = function () { this._list.removeNode(this); }; return LinkedListNode; }()); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = LinkedList; }); //# sourceMappingURL=LinkedList.js.map |