connective-tissue
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,2 +5,23 @@ 'use strict'; | ||
function _classPrivateMethodGet(receiver, privateSet, fn) { | ||
if (!privateSet.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return fn; | ||
} | ||
/** | ||
* @module Atomics | ||
*/ | ||
/** | ||
* Implements a bi-directional node | ||
* | ||
* `Node` implements as a member a pointer to the list to which it belongs | ||
* @param {any} value | ||
* @returns {Node} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function Node(value) { | ||
@@ -14,3 +35,29 @@ return { | ||
} | ||
/** | ||
* Implements a uni-directional (forward) node | ||
* | ||
* `ForwardNode` implements as a member a pointer to the list to which it belongs | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function ForwardNode(value) { | ||
return { | ||
next: null, | ||
list: null, | ||
value | ||
}; | ||
} | ||
/** | ||
* Implements a ring data structure for terminating a bi-directional list | ||
* | ||
* @returns {Sentinel} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function Sentinel() { | ||
@@ -23,18 +70,390 @@ return { | ||
// the next node of the tail, and the previous node of | ||
// the head | ||
/** | ||
* Implements a circular singular (linear) linked list | ||
* @class CircularSinglyLinkedList | ||
*/ | ||
class CircularDoublyLinkedList { | ||
var _newHead = /*#__PURE__*/new WeakSet(); | ||
var _findNodeBefore = /*#__PURE__*/new WeakSet(); | ||
var _move = /*#__PURE__*/new WeakSet(); | ||
class CircularSinglyLinkedList { | ||
constructor() { | ||
this.sentinel = new Sentinel(); // current list length sans the sentinel terminator | ||
_move.add(this); | ||
_findNodeBefore.add(this); | ||
_newHead.add(this); | ||
/** | ||
* The head node; implemented internally as a ring | ||
* @property {ForwardNode} | ||
*/ | ||
this.head = null; | ||
/** | ||
* The current size of the list | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
} | ||
/** | ||
* Bootstrap a new head node | ||
* @param {ForwardNode} node | ||
* @returns {ForwardNode} | ||
* @private | ||
*/ | ||
/** | ||
* Instantiate an empty circular singly linked list | ||
* @returns {CircularSinglyLinkedList} | ||
* @static | ||
*/ | ||
static create() { | ||
return new CircularSinglyLinkedList(); | ||
} | ||
/** | ||
* The current size of the list | ||
* @returns {number} | ||
*/ | ||
size() { | ||
return this.length; | ||
} | ||
/** | ||
* Returns the next list node, if extant; else, null | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} | ||
*/ | ||
next(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
const p = node.next; | ||
if (p && node.list == this) return p; | ||
return null; | ||
} | ||
/** | ||
* Returns the previous list node, if extant; else, null | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} | ||
*/ | ||
prev(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
const p = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
return p ? p : null; | ||
} | ||
/** | ||
* Remove a given node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
remove(node) { | ||
if (!this.head || !node) return null; | ||
if (node.list !== this) return null; | ||
let tmp1 = this.head; | ||
let tmp2; | ||
while (tmp1 != node) { | ||
tmp2 = tmp1; | ||
tmp1 = tmp1.next; | ||
} | ||
if (tmp1 === this.head) { | ||
tmp2 = this.head; | ||
while (tmp2.next !== this.head) tmp2 = tmp2.next; | ||
this.head = this.head.next; | ||
tmp2.next = this.head; | ||
} else { | ||
tmp2.next = tmp1.next; | ||
} | ||
node.list = null; | ||
this.length--; | ||
return node; | ||
} | ||
removeHead() { | ||
if (!this.head) return null; | ||
let tmp1 = this.head; | ||
let tmp2 = this.head; | ||
if (tmp1.next === this.head) this.head = null;else { | ||
while (tmp1.next !== this.head) { | ||
tmp1 = tmp1.next; | ||
} | ||
this.head = this.head.next; | ||
tmp1.next = this.head; | ||
} | ||
this.length--; | ||
tmp2.list = null; | ||
return tmp2; | ||
} | ||
/** | ||
* Remove the last node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
pop() { | ||
if (!this.head) return null; | ||
let tmp = this.head; | ||
while (tmp.next !== this.head) tmp = tmp.next; | ||
return this.remove(tmp); | ||
} | ||
/** | ||
* Move a given node to its new position after `mark` | ||
* | ||
* If either the given node or mark are not an element of the list; node == mark; or mark.next == node, the list is not modified | ||
* | ||
* Both the node and mark must not be null | ||
* @param {ForwardNode} node | ||
* @param {ForwardNode} mark | ||
* @returns {ForwardNode} | ||
*/ | ||
moveAfter(node, mark) { | ||
if (!node || !mark) return; | ||
if (node.list !== this || node === mark || mark.list !== this) { | ||
return; | ||
} | ||
if (mark.next === node) return; | ||
_classPrivateMethodGet(this, _move, _move2).call(this, node, mark); | ||
} | ||
/** | ||
* Move a given node to its new position before `mark` | ||
* | ||
* If either the given node or mark are not an element of the list; node == mark; or node.next == mark, the list is not modified | ||
* | ||
* Both the node and mark must not be null | ||
* @param {ForwardNode} node | ||
* @param {ForwardNode} mark | ||
* @returns {ForwardNode} | ||
*/ | ||
moveBefore(node, mark) { | ||
if (!node || !mark) return; | ||
if (node.list !== this || node === mark || mark.list !== this) { | ||
return; | ||
} | ||
if (node.next === mark) return; | ||
const tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, mark); | ||
_classPrivateMethodGet(this, _move, _move2).call(this, node, tmp); | ||
} | ||
/** | ||
* Push a new node with value `value` to the front of the list | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
*/ | ||
pushFront(value) { | ||
const node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
const tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, this.head); | ||
node.next = this.head; | ||
this.head = node; | ||
tmp.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Push a new node with value `value` to the back of the list | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
*/ | ||
pushBack(value) { | ||
const node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
if (this.head && this.length == 1) { | ||
this.head.next = node; | ||
} else { | ||
const tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, this.head); | ||
tmp.next = node; | ||
} | ||
node.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Insert a new node with value `value` immediately after `mark` | ||
* | ||
* If `mark` is not an element of the list, the list is not modified | ||
* | ||
* `mark` must not be null | ||
* @param {any} value | ||
* @param {ForwardNode} mark | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
insertAfter(value, mark) { | ||
if (!mark) return null; | ||
if (mark.list !== this) return null; | ||
const node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
const tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, mark.next); | ||
if (tmp.next === this.head) { | ||
tmp.next = node; | ||
node.next = this.head; | ||
} else { | ||
node.next = tmp.next; | ||
tmp.next = node; | ||
} | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Insert a new node with value `value` immediately before `mark` | ||
* | ||
* If `mark` is not an element of the list, the list is not modified | ||
* | ||
* `mark` must not be null | ||
* @param {any} value | ||
* @param {ForwardNode} mark | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
insertBefore(value, mark) { | ||
if (!mark) return null; | ||
if (mark.list !== this) return null; | ||
return this.insertAfter(value, this.prev(mark)); | ||
} | ||
/** | ||
* Insert a copy of another list at the back of the caller list | ||
* | ||
* The lists may be the same, but must not be null | ||
* @param {CircularSinglyLinkedList} other | ||
*/ | ||
pushBackList(other) { | ||
if (!other) return; | ||
for (let i = other.size(), n = other.head; i > 0; i--, n = other.next(n)) { | ||
this.pushBack(n.value); | ||
} | ||
} | ||
/** | ||
* Insert a copy of another list at the front of the caller list | ||
* | ||
* The lists may be the same, but must not be null | ||
* @param {CircularSinglyLinkedList} other | ||
*/ | ||
pushFrontList(other) { | ||
if (!other) return; | ||
for (let i = other.size(), n = other.prev(other.head); i > 0; i--, n = other.prev(n)) { | ||
this.pushFront(n.value); | ||
} | ||
} | ||
} | ||
function _newHead2(node) { | ||
this.head = node; | ||
node.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
function _findNodeBefore2(target) { | ||
let tmp = this.head; | ||
while (tmp.next != target) { | ||
tmp = tmp.next; | ||
} | ||
return tmp; | ||
} | ||
function _move2(node, at) { | ||
const tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
tmp.next = node.next; | ||
node.next = at.next; | ||
at.next = node; | ||
return node; | ||
} | ||
/** | ||
* Implements a circular doubly linked list as a ring, such that | ||
* the sentinel node is both the next node of the tail, and the previous node | ||
* of the head | ||
* @class CircularDoublyLinkedList | ||
*/ | ||
class CircularDoublyLinkedList { | ||
constructor() { | ||
/** | ||
* The sentinel terminator node | ||
* @property {Sentinel} | ||
*/ | ||
this.sentinel = new Sentinel(); | ||
this.sentinel.next = this.sentinel; | ||
this.sentinel.prev = this.sentinel; | ||
/** | ||
* The list length, sans the sentinel terminator | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
} | ||
/** | ||
* Instantiate an empty circular doubly linked list | ||
* @returns {CircularDoublyLinkedList} | ||
* @static | ||
*/ | ||
static create() { | ||
return new CircularDoublyLinkedList(); | ||
} | ||
/** | ||
* The current size of the list, sans the sentinel node | ||
* @returns {number} | ||
*/ | ||
size() { | ||
@@ -131,3 +550,9 @@ return this.length; | ||
} | ||
/** | ||
* Remove the last node from the list | ||
* @param {Node} node | ||
* @returns {Node} The removed node | ||
*/ | ||
pop() { | ||
@@ -253,3 +678,3 @@ return this.remove(this.tail()); | ||
* | ||
* If either the given node or mark are not an element of the list, or node == mark. the list is not modified | ||
* If either the given node or mark are not an element of the list, or node == mark, the list is not modified | ||
* | ||
@@ -273,3 +698,3 @@ * Both the node and mark must not be null | ||
* | ||
* If either the given node or mark are not an element of the list, or node == mark. the list is not modified | ||
* If either the given node or mark are not an element of the list, or node == mark, the list is not modified | ||
* | ||
@@ -339,3 +764,2 @@ * Both the node and mark must not be null | ||
exports.CircularDoublyLinkedList = CircularDoublyLinkedList; | ||
exports.Node = Node; | ||
exports.Sentinel = Sentinel; | ||
exports.CircularSinglyLinkedList = CircularSinglyLinkedList; |
@@ -23,2 +23,15 @@ function _classCallCheck(instance, Constructor) { | ||
/** | ||
* @module Atomics | ||
*/ | ||
/** | ||
* Implements a bi-directional node | ||
* | ||
* `Node` implements as a member a pointer to the list to which it belongs | ||
* @param {any} value | ||
* @returns {Node} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function Node(value) { | ||
@@ -32,3 +45,29 @@ return { | ||
} | ||
/** | ||
* Implements a uni-directional (forward) node | ||
* | ||
* `ForwardNode` implements as a member a pointer to the list to which it belongs | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function ForwardNode(value) { | ||
return { | ||
next: null, | ||
list: null, | ||
value: value | ||
}; | ||
} | ||
/** | ||
* Implements a ring data structure for terminating a bi-directional list | ||
* | ||
* @returns {Sentinel} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function Sentinel() { | ||
@@ -41,5 +80,384 @@ return { | ||
// the next node of the tail, and the previous node of | ||
// the head | ||
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; } | ||
/** | ||
* Implements a circular singular (linear) linked list | ||
* @class CircularSinglyLinkedList | ||
*/ | ||
var _newHead = /*#__PURE__*/new WeakSet(); | ||
var _findNodeBefore = /*#__PURE__*/new WeakSet(); | ||
var _move = /*#__PURE__*/new WeakSet(); | ||
var CircularSinglyLinkedList = /*#__PURE__*/function () { | ||
function CircularSinglyLinkedList() { | ||
_classCallCheck(this, CircularSinglyLinkedList); | ||
_move.add(this); | ||
_findNodeBefore.add(this); | ||
_newHead.add(this); | ||
/** | ||
* The head node; implemented internally as a ring | ||
* @property {ForwardNode} | ||
*/ | ||
this.head = null; | ||
/** | ||
* The current size of the list | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
} | ||
/** | ||
* Bootstrap a new head node | ||
* @param {ForwardNode} node | ||
* @returns {ForwardNode} | ||
* @private | ||
*/ | ||
_createClass(CircularSinglyLinkedList, [{ | ||
key: "size", | ||
value: | ||
/** | ||
* The current size of the list | ||
* @returns {number} | ||
*/ | ||
function size() { | ||
return this.length; | ||
} | ||
/** | ||
* Returns the next list node, if extant; else, null | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} | ||
*/ | ||
}, { | ||
key: "next", | ||
value: function next(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
var p = node.next; | ||
if (p && node.list == this) return p; | ||
return null; | ||
} | ||
/** | ||
* Returns the previous list node, if extant; else, null | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} | ||
*/ | ||
}, { | ||
key: "prev", | ||
value: function prev(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
var p = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
return p ? p : null; | ||
} | ||
/** | ||
* Remove a given node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
}, { | ||
key: "remove", | ||
value: function remove(node) { | ||
if (!this.head || !node) return null; | ||
if (node.list !== this) return null; | ||
var tmp1 = this.head; | ||
var tmp2; | ||
while (tmp1 != node) { | ||
tmp2 = tmp1; | ||
tmp1 = tmp1.next; | ||
} | ||
if (tmp1 === this.head) { | ||
tmp2 = this.head; | ||
while (tmp2.next !== this.head) { | ||
tmp2 = tmp2.next; | ||
} | ||
this.head = this.head.next; | ||
tmp2.next = this.head; | ||
} else { | ||
tmp2.next = tmp1.next; | ||
} | ||
node.list = null; | ||
this.length--; | ||
return node; | ||
} | ||
}, { | ||
key: "removeHead", | ||
value: function removeHead() { | ||
if (!this.head) return null; | ||
var tmp1 = this.head; | ||
var tmp2 = this.head; | ||
if (tmp1.next === this.head) this.head = null;else { | ||
while (tmp1.next !== this.head) { | ||
tmp1 = tmp1.next; | ||
} | ||
this.head = this.head.next; | ||
tmp1.next = this.head; | ||
} | ||
this.length--; | ||
tmp2.list = null; | ||
return tmp2; | ||
} | ||
/** | ||
* Remove the last node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
}, { | ||
key: "pop", | ||
value: function pop() { | ||
if (!this.head) return null; | ||
var tmp = this.head; | ||
while (tmp.next !== this.head) { | ||
tmp = tmp.next; | ||
} | ||
return this.remove(tmp); | ||
} | ||
/** | ||
* Move a given node to its new position after `mark` | ||
* | ||
* If either the given node or mark are not an element of the list; node == mark; or mark.next == node, the list is not modified | ||
* | ||
* Both the node and mark must not be null | ||
* @param {ForwardNode} node | ||
* @param {ForwardNode} mark | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "moveAfter", | ||
value: function moveAfter(node, mark) { | ||
if (!node || !mark) return; | ||
if (node.list !== this || node === mark || mark.list !== this) { | ||
return; | ||
} | ||
if (mark.next === node) return; | ||
_classPrivateMethodGet(this, _move, _move2).call(this, node, mark); | ||
} | ||
/** | ||
* Move a given node to its new position before `mark` | ||
* | ||
* If either the given node or mark are not an element of the list; node == mark; or node.next == mark, the list is not modified | ||
* | ||
* Both the node and mark must not be null | ||
* @param {ForwardNode} node | ||
* @param {ForwardNode} mark | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "moveBefore", | ||
value: function moveBefore(node, mark) { | ||
if (!node || !mark) return; | ||
if (node.list !== this || node === mark || mark.list !== this) { | ||
return; | ||
} | ||
if (node.next === mark) return; | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, mark); | ||
_classPrivateMethodGet(this, _move, _move2).call(this, node, tmp); | ||
} | ||
/** | ||
* Push a new node with value `value` to the front of the list | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "pushFront", | ||
value: function pushFront(value) { | ||
var node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, this.head); | ||
node.next = this.head; | ||
this.head = node; | ||
tmp.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Push a new node with value `value` to the back of the list | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "pushBack", | ||
value: function pushBack(value) { | ||
var node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
if (this.head && this.length == 1) { | ||
this.head.next = node; | ||
} else { | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, this.head); | ||
tmp.next = node; | ||
} | ||
node.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Insert a new node with value `value` immediately after `mark` | ||
* | ||
* If `mark` is not an element of the list, the list is not modified | ||
* | ||
* `mark` must not be null | ||
* @param {any} value | ||
* @param {ForwardNode} mark | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
key: "insertAfter", | ||
value: function insertAfter(value, mark) { | ||
if (!mark) return null; | ||
if (mark.list !== this) return null; | ||
var node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, mark.next); | ||
if (tmp.next === this.head) { | ||
tmp.next = node; | ||
node.next = this.head; | ||
} else { | ||
node.next = tmp.next; | ||
tmp.next = node; | ||
} | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Insert a new node with value `value` immediately before `mark` | ||
* | ||
* If `mark` is not an element of the list, the list is not modified | ||
* | ||
* `mark` must not be null | ||
* @param {any} value | ||
* @param {ForwardNode} mark | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
key: "insertBefore", | ||
value: function insertBefore(value, mark) { | ||
if (!mark) return null; | ||
if (mark.list !== this) return null; | ||
return this.insertAfter(value, this.prev(mark)); | ||
} | ||
/** | ||
* Insert a copy of another list at the back of the caller list | ||
* | ||
* The lists may be the same, but must not be null | ||
* @param {CircularSinglyLinkedList} other | ||
*/ | ||
}, { | ||
key: "pushBackList", | ||
value: function pushBackList(other) { | ||
if (!other) return; | ||
for (var i = other.size(), n = other.head; i > 0; i--, n = other.next(n)) { | ||
this.pushBack(n.value); | ||
} | ||
} | ||
/** | ||
* Insert a copy of another list at the front of the caller list | ||
* | ||
* The lists may be the same, but must not be null | ||
* @param {CircularSinglyLinkedList} other | ||
*/ | ||
}, { | ||
key: "pushFrontList", | ||
value: function pushFrontList(other) { | ||
if (!other) return; | ||
for (var i = other.size(), n = other.prev(other.head); i > 0; i--, n = other.prev(n)) { | ||
this.pushFront(n.value); | ||
} | ||
} | ||
}], [{ | ||
key: "create", | ||
value: | ||
/** | ||
* Instantiate an empty circular singly linked list | ||
* @returns {CircularSinglyLinkedList} | ||
* @static | ||
*/ | ||
function create() { | ||
return new CircularSinglyLinkedList(); | ||
} | ||
}]); | ||
return CircularSinglyLinkedList; | ||
}(); | ||
function _newHead2(node) { | ||
this.head = node; | ||
node.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
function _findNodeBefore2(target) { | ||
var tmp = this.head; | ||
while (tmp.next != target) { | ||
tmp = tmp.next; | ||
} | ||
return tmp; | ||
} | ||
function _move2(node, at) { | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
tmp.next = node.next; | ||
node.next = at.next; | ||
at.next = node; | ||
return node; | ||
} | ||
/** | ||
* Implements a circular doubly linked list as a ring, such that | ||
* the sentinel node is both the next node of the tail, and the previous node | ||
* of the head | ||
* @class CircularDoublyLinkedList | ||
*/ | ||
var CircularDoublyLinkedList = /*#__PURE__*/function () { | ||
@@ -49,12 +467,31 @@ function CircularDoublyLinkedList() { | ||
this.sentinel = new Sentinel(); // current list length sans the sentinel terminator | ||
/** | ||
* The sentinel terminator node | ||
* @property {Sentinel} | ||
*/ | ||
this.sentinel = new Sentinel(); | ||
this.sentinel.next = this.sentinel; | ||
this.sentinel.prev = this.sentinel; | ||
/** | ||
* The list length, sans the sentinel terminator | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
this.sentinel.next = this.sentinel; | ||
this.sentinel.prev = this.sentinel; | ||
} | ||
/** | ||
* Instantiate an empty circular doubly linked list | ||
* @returns {CircularDoublyLinkedList} | ||
* @static | ||
*/ | ||
_createClass(CircularDoublyLinkedList, [{ | ||
key: "size", | ||
value: function size() { | ||
value: | ||
/** | ||
* The current size of the list, sans the sentinel node | ||
* @returns {number} | ||
*/ | ||
function size() { | ||
return this.length; | ||
@@ -156,2 +593,8 @@ } | ||
} | ||
/** | ||
* Remove the last node from the list | ||
* @param {Node} node | ||
* @returns {Node} The removed node | ||
*/ | ||
}, { | ||
@@ -286,3 +729,3 @@ key: "pop", | ||
* | ||
* If either the given node or mark are not an element of the list, or node == mark. the list is not modified | ||
* If either the given node or mark are not an element of the list, or node == mark, the list is not modified | ||
* | ||
@@ -307,3 +750,3 @@ * Both the node and mark must not be null | ||
* | ||
* If either the given node or mark are not an element of the list, or node == mark. the list is not modified | ||
* If either the given node or mark are not an element of the list, or node == mark, the list is not modified | ||
* | ||
@@ -383,2 +826,2 @@ * Both the node and mark must not be null | ||
export { CircularDoublyLinkedList, Node, Sentinel }; | ||
export { CircularDoublyLinkedList, CircularSinglyLinkedList }; |
@@ -29,2 +29,15 @@ (function (global, factory) { | ||
/** | ||
* @module Atomics | ||
*/ | ||
/** | ||
* Implements a bi-directional node | ||
* | ||
* `Node` implements as a member a pointer to the list to which it belongs | ||
* @param {any} value | ||
* @returns {Node} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function Node(value) { | ||
@@ -38,3 +51,29 @@ return { | ||
} | ||
/** | ||
* Implements a uni-directional (forward) node | ||
* | ||
* `ForwardNode` implements as a member a pointer to the list to which it belongs | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function ForwardNode(value) { | ||
return { | ||
next: null, | ||
list: null, | ||
value: value | ||
}; | ||
} | ||
/** | ||
* Implements a ring data structure for terminating a bi-directional list | ||
* | ||
* @returns {Sentinel} | ||
* @constructor | ||
* @memberof module:Atomics | ||
*/ | ||
function Sentinel() { | ||
@@ -47,5 +86,384 @@ return { | ||
// the next node of the tail, and the previous node of | ||
// the head | ||
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; } | ||
/** | ||
* Implements a circular singular (linear) linked list | ||
* @class CircularSinglyLinkedList | ||
*/ | ||
var _newHead = /*#__PURE__*/new WeakSet(); | ||
var _findNodeBefore = /*#__PURE__*/new WeakSet(); | ||
var _move = /*#__PURE__*/new WeakSet(); | ||
var CircularSinglyLinkedList = /*#__PURE__*/function () { | ||
function CircularSinglyLinkedList() { | ||
_classCallCheck(this, CircularSinglyLinkedList); | ||
_move.add(this); | ||
_findNodeBefore.add(this); | ||
_newHead.add(this); | ||
/** | ||
* The head node; implemented internally as a ring | ||
* @property {ForwardNode} | ||
*/ | ||
this.head = null; | ||
/** | ||
* The current size of the list | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
} | ||
/** | ||
* Bootstrap a new head node | ||
* @param {ForwardNode} node | ||
* @returns {ForwardNode} | ||
* @private | ||
*/ | ||
_createClass(CircularSinglyLinkedList, [{ | ||
key: "size", | ||
value: | ||
/** | ||
* The current size of the list | ||
* @returns {number} | ||
*/ | ||
function size() { | ||
return this.length; | ||
} | ||
/** | ||
* Returns the next list node, if extant; else, null | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} | ||
*/ | ||
}, { | ||
key: "next", | ||
value: function next(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
var p = node.next; | ||
if (p && node.list == this) return p; | ||
return null; | ||
} | ||
/** | ||
* Returns the previous list node, if extant; else, null | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} | ||
*/ | ||
}, { | ||
key: "prev", | ||
value: function prev(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
var p = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
return p ? p : null; | ||
} | ||
/** | ||
* Remove a given node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
}, { | ||
key: "remove", | ||
value: function remove(node) { | ||
if (!this.head || !node) return null; | ||
if (node.list !== this) return null; | ||
var tmp1 = this.head; | ||
var tmp2; | ||
while (tmp1 != node) { | ||
tmp2 = tmp1; | ||
tmp1 = tmp1.next; | ||
} | ||
if (tmp1 === this.head) { | ||
tmp2 = this.head; | ||
while (tmp2.next !== this.head) { | ||
tmp2 = tmp2.next; | ||
} | ||
this.head = this.head.next; | ||
tmp2.next = this.head; | ||
} else { | ||
tmp2.next = tmp1.next; | ||
} | ||
node.list = null; | ||
this.length--; | ||
return node; | ||
} | ||
}, { | ||
key: "removeHead", | ||
value: function removeHead() { | ||
if (!this.head) return null; | ||
var tmp1 = this.head; | ||
var tmp2 = this.head; | ||
if (tmp1.next === this.head) this.head = null;else { | ||
while (tmp1.next !== this.head) { | ||
tmp1 = tmp1.next; | ||
} | ||
this.head = this.head.next; | ||
tmp1.next = this.head; | ||
} | ||
this.length--; | ||
tmp2.list = null; | ||
return tmp2; | ||
} | ||
/** | ||
* Remove the last node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
}, { | ||
key: "pop", | ||
value: function pop() { | ||
if (!this.head) return null; | ||
var tmp = this.head; | ||
while (tmp.next !== this.head) { | ||
tmp = tmp.next; | ||
} | ||
return this.remove(tmp); | ||
} | ||
/** | ||
* Move a given node to its new position after `mark` | ||
* | ||
* If either the given node or mark are not an element of the list; node == mark; or mark.next == node, the list is not modified | ||
* | ||
* Both the node and mark must not be null | ||
* @param {ForwardNode} node | ||
* @param {ForwardNode} mark | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "moveAfter", | ||
value: function moveAfter(node, mark) { | ||
if (!node || !mark) return; | ||
if (node.list !== this || node === mark || mark.list !== this) { | ||
return; | ||
} | ||
if (mark.next === node) return; | ||
_classPrivateMethodGet(this, _move, _move2).call(this, node, mark); | ||
} | ||
/** | ||
* Move a given node to its new position before `mark` | ||
* | ||
* If either the given node or mark are not an element of the list; node == mark; or node.next == mark, the list is not modified | ||
* | ||
* Both the node and mark must not be null | ||
* @param {ForwardNode} node | ||
* @param {ForwardNode} mark | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "moveBefore", | ||
value: function moveBefore(node, mark) { | ||
if (!node || !mark) return; | ||
if (node.list !== this || node === mark || mark.list !== this) { | ||
return; | ||
} | ||
if (node.next === mark) return; | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, mark); | ||
_classPrivateMethodGet(this, _move, _move2).call(this, node, tmp); | ||
} | ||
/** | ||
* Push a new node with value `value` to the front of the list | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "pushFront", | ||
value: function pushFront(value) { | ||
var node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, this.head); | ||
node.next = this.head; | ||
this.head = node; | ||
tmp.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Push a new node with value `value` to the back of the list | ||
* @param {any} value | ||
* @returns {ForwardNode} | ||
*/ | ||
}, { | ||
key: "pushBack", | ||
value: function pushBack(value) { | ||
var node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
if (this.head && this.length == 1) { | ||
this.head.next = node; | ||
} else { | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, this.head); | ||
tmp.next = node; | ||
} | ||
node.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Insert a new node with value `value` immediately after `mark` | ||
* | ||
* If `mark` is not an element of the list, the list is not modified | ||
* | ||
* `mark` must not be null | ||
* @param {any} value | ||
* @param {ForwardNode} mark | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
key: "insertAfter", | ||
value: function insertAfter(value, mark) { | ||
if (!mark) return null; | ||
if (mark.list !== this) return null; | ||
var node = new ForwardNode(value); | ||
if (!this.head) return _classPrivateMethodGet(this, _newHead, _newHead2).call(this, node); | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, mark.next); | ||
if (tmp.next === this.head) { | ||
tmp.next = node; | ||
node.next = this.head; | ||
} else { | ||
node.next = tmp.next; | ||
tmp.next = node; | ||
} | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Insert a new node with value `value` immediately before `mark` | ||
* | ||
* If `mark` is not an element of the list, the list is not modified | ||
* | ||
* `mark` must not be null | ||
* @param {any} value | ||
* @param {ForwardNode} mark | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
key: "insertBefore", | ||
value: function insertBefore(value, mark) { | ||
if (!mark) return null; | ||
if (mark.list !== this) return null; | ||
return this.insertAfter(value, this.prev(mark)); | ||
} | ||
/** | ||
* Insert a copy of another list at the back of the caller list | ||
* | ||
* The lists may be the same, but must not be null | ||
* @param {CircularSinglyLinkedList} other | ||
*/ | ||
}, { | ||
key: "pushBackList", | ||
value: function pushBackList(other) { | ||
if (!other) return; | ||
for (var i = other.size(), n = other.head; i > 0; i--, n = other.next(n)) { | ||
this.pushBack(n.value); | ||
} | ||
} | ||
/** | ||
* Insert a copy of another list at the front of the caller list | ||
* | ||
* The lists may be the same, but must not be null | ||
* @param {CircularSinglyLinkedList} other | ||
*/ | ||
}, { | ||
key: "pushFrontList", | ||
value: function pushFrontList(other) { | ||
if (!other) return; | ||
for (var i = other.size(), n = other.prev(other.head); i > 0; i--, n = other.prev(n)) { | ||
this.pushFront(n.value); | ||
} | ||
} | ||
}], [{ | ||
key: "create", | ||
value: | ||
/** | ||
* Instantiate an empty circular singly linked list | ||
* @returns {CircularSinglyLinkedList} | ||
* @static | ||
*/ | ||
function create() { | ||
return new CircularSinglyLinkedList(); | ||
} | ||
}]); | ||
return CircularSinglyLinkedList; | ||
}(); | ||
function _newHead2(node) { | ||
this.head = node; | ||
node.next = this.head; | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
function _findNodeBefore2(target) { | ||
var tmp = this.head; | ||
while (tmp.next != target) { | ||
tmp = tmp.next; | ||
} | ||
return tmp; | ||
} | ||
function _move2(node, at) { | ||
var tmp = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
tmp.next = node.next; | ||
node.next = at.next; | ||
at.next = node; | ||
return node; | ||
} | ||
/** | ||
* Implements a circular doubly linked list as a ring, such that | ||
* the sentinel node is both the next node of the tail, and the previous node | ||
* of the head | ||
* @class CircularDoublyLinkedList | ||
*/ | ||
var CircularDoublyLinkedList = /*#__PURE__*/function () { | ||
@@ -55,12 +473,31 @@ function CircularDoublyLinkedList() { | ||
this.sentinel = new Sentinel(); // current list length sans the sentinel terminator | ||
/** | ||
* The sentinel terminator node | ||
* @property {Sentinel} | ||
*/ | ||
this.sentinel = new Sentinel(); | ||
this.sentinel.next = this.sentinel; | ||
this.sentinel.prev = this.sentinel; | ||
/** | ||
* The list length, sans the sentinel terminator | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
this.sentinel.next = this.sentinel; | ||
this.sentinel.prev = this.sentinel; | ||
} | ||
/** | ||
* Instantiate an empty circular doubly linked list | ||
* @returns {CircularDoublyLinkedList} | ||
* @static | ||
*/ | ||
_createClass(CircularDoublyLinkedList, [{ | ||
key: "size", | ||
value: function size() { | ||
value: | ||
/** | ||
* The current size of the list, sans the sentinel node | ||
* @returns {number} | ||
*/ | ||
function size() { | ||
return this.length; | ||
@@ -162,2 +599,8 @@ } | ||
} | ||
/** | ||
* Remove the last node from the list | ||
* @param {Node} node | ||
* @returns {Node} The removed node | ||
*/ | ||
}, { | ||
@@ -292,3 +735,3 @@ key: "pop", | ||
* | ||
* If either the given node or mark are not an element of the list, or node == mark. the list is not modified | ||
* If either the given node or mark are not an element of the list, or node == mark, the list is not modified | ||
* | ||
@@ -313,3 +756,3 @@ * Both the node and mark must not be null | ||
* | ||
* If either the given node or mark are not an element of the list, or node == mark. the list is not modified | ||
* If either the given node or mark are not an element of the list, or node == mark, the list is not modified | ||
* | ||
@@ -390,4 +833,3 @@ * Both the node and mark must not be null | ||
exports.CircularDoublyLinkedList = CircularDoublyLinkedList; | ||
exports.Node = Node; | ||
exports.Sentinel = Sentinel; | ||
exports.CircularSinglyLinkedList = CircularSinglyLinkedList; | ||
@@ -394,0 +836,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["connective-tissue"]={})}(this,(function(e){"use strict";function t(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function n(e){return{next:null,prev:null,list:null,value:e}}function i(){return{next:null,prev:null}}var s=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.sentinel=new i,this.length=0,this.sentinel.next=this.sentinel,this.sentinel.prev=this.sentinel}var s,l,r;return s=e,r=[{key:"create",value:function(){return new e}}],(l=[{key:"size",value:function(){return this.length}},{key:"next",value:function(e){var t=e.next;return t&&null!=e.list&&t!=e.list.sentinel?t:null}},{key:"prev",value:function(e){var t=e.prev;return t&&null!=e.list&&t!=e.list.sentinel?t:null}},{key:"head",value:function(){return this.length?this.sentinel.next:null}},{key:"tail",value:function(){return this.length?this.sentinel.prev:null}},{key:"insert",value:function(e,t){return e.prev=t,e.next=t.next,e.prev.next=e,e.next.prev=e,e.list=this,this.length++,e}},{key:"remove",value:function(e){return e.list===this&&(e.prev.next=e.next,e.next.prev=e.prev,e.next=null,e.prev=null,e.list=null,this.length--),e}},{key:"pop",value:function(){return this.remove(this.tail())}},{key:"move",value:function(e,t){return e===t||(e.prev.next=e.next,e.next.prev=e.prev,e.prev=t,e.next=t.next,e.prev.next=e,e.next.prev=e),e}},{key:"pushFront",value:function(t){return this.sentinel.next||Object.assign(this,new e),this.insertValue(t,this.sentinel)}},{key:"pushBack",value:function(t){return this.sentinel.next||Object.assign(this,new e),this.insertValue(t,this.sentinel.prev)}},{key:"insertBefore",value:function(e,t){return t.list!==this?null:this.insertValue(e,t.prev)}},{key:"insertAfter",value:function(e,t){return t.list!==this?null:this.insertValue(e,t)}},{key:"moveToFront",value:function(e){e.list===this&&this.sentinel.next!==e&&this.move(e,this.sentinel)}},{key:"moveToBack",value:function(e){e.list===this&&this.sentinel.prev!==e&&this.move(e,this.sentinel.prev)}},{key:"moveBefore",value:function(e,t){e.list===this&&e!==t&&t.list===this&&this.move(e,t.prev)}},{key:"moveAfter",value:function(e,t){e.list===this&&e!==t&&t.list===this&&this.move(e,t)}},{key:"insertValue",value:function(e,t){return this.insert(new n(e),t)}},{key:"pushBackList",value:function(t){this.sentinel.next||Object.assign(this,new e);for(var n=t.size(),i=t.head();n>0;n--,i=t.next(i))this.insertValue(i.value,this.sentinel.prev)}},{key:"pushFrontList",value:function(t){this.sentinel.next||Object.assign(this,new e);for(var n=t.size(),i=t.tail();n>0;n--,i=t.prev(i))this.insertValue(i.value,this.sentinel)}}])&&t(s.prototype,l),r&&t(s,r),e}();e.CircularDoublyLinkedList=s,e.Node=n,e.Sentinel=i,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["connective-tissue"]={})}(this,(function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function i(e,t,i){return t&&n(e.prototype,t),i&&n(e,i),e}function s(e){return{next:null,prev:null,list:null,value:e}}function l(e){return{next:null,list:null,value:e}}function r(){return{next:null,prev:null}}function h(e,t,n){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return n}var u=new WeakSet,a=new WeakSet,o=new WeakSet,v=function(){function e(){t(this,e),o.add(this),a.add(this),u.add(this),this.head=null,this.length=0}return i(e,[{key:"size",value:function(){return this.length}},{key:"next",value:function(e){if(!e||e.list&&e.list!==this)return null;var t=e.next;return t&&e.list==this?t:null}},{key:"prev",value:function(e){if(!e||e.list&&e.list!==this)return null;var t=h(this,a,c).call(this,e);return t||null}},{key:"remove",value:function(e){if(!this.head||!e)return null;if(e.list!==this)return null;for(var t,n=this.head;n!=e;)t=n,n=n.next;if(n===this.head){for(t=this.head;t.next!==this.head;)t=t.next;this.head=this.head.next,t.next=this.head}else t.next=n.next;return e.list=null,this.length--,e}},{key:"removeHead",value:function(){if(!this.head)return null;var e=this.head,t=this.head;if(e.next===this.head)this.head=null;else{for(;e.next!==this.head;)e=e.next;this.head=this.head.next,e.next=this.head}return this.length--,t.list=null,t}},{key:"pop",value:function(){if(!this.head)return null;for(var e=this.head;e.next!==this.head;)e=e.next;return this.remove(e)}},{key:"moveAfter",value:function(e,t){e&&t&&e.list===this&&e!==t&&t.list===this&&t.next!==e&&h(this,o,x).call(this,e,t)}},{key:"moveBefore",value:function(e,t){if(e&&t&&e.list===this&&e!==t&&t.list===this&&e.next!==t){var n=h(this,a,c).call(this,t);h(this,o,x).call(this,e,n)}}},{key:"pushFront",value:function(e){var t=new l(e);if(!this.head)return h(this,u,f).call(this,t);var n=h(this,a,c).call(this,this.head);return t.next=this.head,this.head=t,n.next=this.head,t.list=this,this.length++,t}},{key:"pushBack",value:function(e){var t=new l(e);if(!this.head)return h(this,u,f).call(this,t);this.head&&1==this.length?this.head.next=t:h(this,a,c).call(this,this.head).next=t;return t.next=this.head,t.list=this,this.length++,t}},{key:"insertAfter",value:function(e,t){if(!t)return null;if(t.list!==this)return null;var n=new l(e);if(!this.head)return h(this,u,f).call(this,n);var i=h(this,a,c).call(this,t.next);return i.next===this.head?(i.next=n,n.next=this.head):(n.next=i.next,i.next=n),n.list=this,this.length++,n}},{key:"insertBefore",value:function(e,t){return t?t.list!==this?null:this.insertAfter(e,this.prev(t)):null}},{key:"pushBackList",value:function(e){if(e)for(var t=e.size(),n=e.head;t>0;t--,n=e.next(n))this.pushBack(n.value)}},{key:"pushFrontList",value:function(e){if(e)for(var t=e.size(),n=e.prev(e.head);t>0;t--,n=e.prev(n))this.pushFront(n.value)}}],[{key:"create",value:function(){return new e}}]),e}();function f(e){return this.head=e,e.next=this.head,e.list=this,this.length++,e}function c(e){for(var t=this.head;t.next!=e;)t=t.next;return t}function x(e,t){return h(this,a,c).call(this,e).next=e.next,e.next=t.next,t.next=e,e}var d=function(){function e(){t(this,e),this.sentinel=new r,this.sentinel.next=this.sentinel,this.sentinel.prev=this.sentinel,this.length=0}return i(e,[{key:"size",value:function(){return this.length}},{key:"next",value:function(e){var t=e.next;return t&&null!=e.list&&t!=e.list.sentinel?t:null}},{key:"prev",value:function(e){var t=e.prev;return t&&null!=e.list&&t!=e.list.sentinel?t:null}},{key:"head",value:function(){return this.length?this.sentinel.next:null}},{key:"tail",value:function(){return this.length?this.sentinel.prev:null}},{key:"insert",value:function(e,t){return e.prev=t,e.next=t.next,e.prev.next=e,e.next.prev=e,e.list=this,this.length++,e}},{key:"remove",value:function(e){return e.list===this&&(e.prev.next=e.next,e.next.prev=e.prev,e.next=null,e.prev=null,e.list=null,this.length--),e}},{key:"pop",value:function(){return this.remove(this.tail())}},{key:"move",value:function(e,t){return e===t||(e.prev.next=e.next,e.next.prev=e.prev,e.prev=t,e.next=t.next,e.prev.next=e,e.next.prev=e),e}},{key:"pushFront",value:function(t){return this.sentinel.next||Object.assign(this,new e),this.insertValue(t,this.sentinel)}},{key:"pushBack",value:function(t){return this.sentinel.next||Object.assign(this,new e),this.insertValue(t,this.sentinel.prev)}},{key:"insertBefore",value:function(e,t){return t.list!==this?null:this.insertValue(e,t.prev)}},{key:"insertAfter",value:function(e,t){return t.list!==this?null:this.insertValue(e,t)}},{key:"moveToFront",value:function(e){e.list===this&&this.sentinel.next!==e&&this.move(e,this.sentinel)}},{key:"moveToBack",value:function(e){e.list===this&&this.sentinel.prev!==e&&this.move(e,this.sentinel.prev)}},{key:"moveBefore",value:function(e,t){e.list===this&&e!==t&&t.list===this&&this.move(e,t.prev)}},{key:"moveAfter",value:function(e,t){e.list===this&&e!==t&&t.list===this&&this.move(e,t)}},{key:"insertValue",value:function(e,t){return this.insert(new s(e),t)}},{key:"pushBackList",value:function(t){this.sentinel.next||Object.assign(this,new e);for(var n=t.size(),i=t.head();n>0;n--,i=t.next(i))this.insertValue(i.value,this.sentinel.prev)}},{key:"pushFrontList",value:function(t){this.sentinel.next||Object.assign(this,new e);for(var n=t.size(),i=t.tail();n>0;n--,i=t.prev(i))this.insertValue(i.value,this.sentinel)}}],[{key:"create",value:function(){return new e}}]),e}();e.CircularDoublyLinkedList=d,e.CircularSinglyLinkedList=v,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "connective-tissue", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -26,3 +26,4 @@ "main": "./dist/connective-tissue.cjs.js", | ||
"test": "tape -r 'esm' './__tests__/**/*.test.js'", | ||
"test:watch": "nodemon --exec 'npm run test'" | ||
"test:watch": "nodemon --exec 'yarn test'", | ||
"doc": "jsdoc2md -d 1 --plugin dmd-readable -t README.hbs --files ./lib/* > README.md" | ||
}, | ||
@@ -38,4 +39,4 @@ "author": "Matthew Zito <matthewtzito@gmail.com> (goldmund)", | ||
"lib/**/*.js": [ | ||
"npm run lint", | ||
"npm run test" | ||
"yarn lint", | ||
"yarn test" | ||
] | ||
@@ -55,5 +56,6 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "7.13.8", | ||
"@babel/core": "7.14.3", | ||
"@babel/eslint-parser": "7.14.4", | ||
"@babel/plugin-transform-runtime": "7.13.9", | ||
"@babel/preset-env": "7.13.9", | ||
"@babel/preset-env": "7.14.4", | ||
"@commitlint/cli": "12.0.1", | ||
@@ -64,12 +66,14 @@ "@commitlint/config-conventional": "12.0.1", | ||
"@rollup/plugin-node-resolve": "11.2.0", | ||
"babel-eslint": "10.1.0", | ||
"core-js": "3.9.1", | ||
"cz-conventional-changelog": "3.3.0", | ||
"eslint": "7.21.0", | ||
"dmd-readable": "1.2.4", | ||
"eslint": "7.28.0", | ||
"esm": "3.2.25", | ||
"husky": "4.3.8", | ||
"jsdoc-to-markdown": "7.0.1", | ||
"lint-staged": "10.5.4", | ||
"minami": "1.2.3", | ||
"nodemon": "2.0.7", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.40.0", | ||
"rollup": "2.51.1", | ||
"rollup-plugin-terser": "7.0.2", | ||
@@ -76,0 +80,0 @@ "semantic-release": "^17.4.3", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144298
8
2075
2602
24