connective-tissue
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -69,3 +69,3 @@ 'use strict'; | ||
/** | ||
* Implements a circular singular (linear) linked list | ||
* Implements a circular singly (linear) linked list | ||
* @class CircularSinglyLinkedList | ||
@@ -133,6 +133,5 @@ */ | ||
next(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
if (!node || !node.list || node.list !== this) return null; | ||
const p = node.next; | ||
if (p && node.list == this) return p; | ||
return null; | ||
return p ? p : null; | ||
} | ||
@@ -147,3 +146,3 @@ /** | ||
prev(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
if (!node || !node.list || node.list !== this) return null; | ||
@@ -187,3 +186,8 @@ const p = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
} | ||
/** | ||
* Excise the head of the list and return it; if the head is not extant, return null | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
removeHead() { | ||
@@ -761,3 +765,195 @@ if (!this.head) return null; | ||
/** | ||
* Implements a singly linked list | ||
* @class SinglyLinkedList | ||
*/ | ||
class SinglyLinkedList { | ||
constructor() { | ||
/** | ||
* The head node | ||
* @property {ForwardNode} | ||
*/ | ||
this.head = null; | ||
/** | ||
* The current size of the list | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
} | ||
/** | ||
* Instantiate an empty singly linked list | ||
* @returns {SinglyLinkedList} | ||
* @static | ||
*/ | ||
static create() { | ||
return new SinglyLinkedList(); | ||
} | ||
/** | ||
* 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; | ||
return node.next; | ||
} | ||
/** | ||
* 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) node.next = null;else node.next = this.head; | ||
this.head = node; | ||
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) this.head = node;else { | ||
let tmp = this.head; | ||
while (tmp.next !== null) { | ||
tmp = tmp.next; | ||
} | ||
tmp.next = node; | ||
} | ||
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) { | ||
node.next = null; | ||
this.head = node; | ||
} else { | ||
let tmp = this.head; | ||
while (tmp.next !== mark.next) { | ||
// because we maintain a list ref in ea node, not finding the mark | ||
// should never happen... | ||
// but we observe the check nonetheless in the case of a weird edge case | ||
if (!tmp) return null; | ||
tmp = tmp.next; | ||
} | ||
node.next = tmp.next; | ||
tmp.next = node; | ||
} | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Excise the head of the list and return it; if the head is not extant, return null | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
removeHead() { | ||
if (!this.head) return null; | ||
let tmp = this.head; | ||
if (!tmp.next) this.head = null;else this.head = tmp.next; | ||
this.length--; | ||
tmp.list = null; | ||
return tmp; | ||
} | ||
/** | ||
* Remove the last node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
pop() { | ||
if (!this.head) return null; | ||
let tmp1 = this.head; | ||
let tmp2; | ||
if (!tmp1.next) this.head = null;else { | ||
while (tmp1.next != null) { | ||
tmp2 = tmp1; | ||
tmp1 = tmp1.next; | ||
} | ||
tmp2.next = null; | ||
} | ||
this.length--; | ||
tmp1.list = null; | ||
return tmp1; | ||
} | ||
/** | ||
* Remove a given node from the list | ||
* @param {ForwardNode} node | ||
* @returns {(Node|null)} The removed node | ||
*/ | ||
remove(node) { | ||
if (!this.head || !node || node.list !== this || !this.length) return null; | ||
let tmp = this.head; // we can blindly point the head at its next; | ||
// if there's a single node, it'll be null, which is what we'd want | ||
if (tmp === node) this.head = this.head.next;else { | ||
let prev = null; | ||
while (tmp != node) { | ||
prev = tmp; | ||
tmp = tmp.next; | ||
} | ||
prev.next = tmp.next; | ||
} | ||
tmp.list = null; | ||
this.length--; | ||
return tmp; | ||
} | ||
} | ||
exports.CircularDoublyLinkedList = CircularDoublyLinkedList; | ||
exports.CircularSinglyLinkedList = CircularSinglyLinkedList; | ||
exports.SinglyLinkedList = SinglyLinkedList; |
@@ -80,3 +80,3 @@ function _classCallCheck(instance, Constructor) { | ||
/** | ||
* Implements a circular singular (linear) linked list | ||
* Implements a circular singly (linear) linked list | ||
* @class CircularSinglyLinkedList | ||
@@ -140,6 +140,5 @@ */ | ||
value: function next(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
if (!node || !node.list || node.list !== this) return null; | ||
var p = node.next; | ||
if (p && node.list == this) return p; | ||
return null; | ||
return p ? p : null; | ||
} | ||
@@ -155,3 +154,3 @@ /** | ||
value: function prev(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
if (!node || !node.list || node.list !== this) return null; | ||
@@ -198,2 +197,7 @@ var p = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
} | ||
/** | ||
* Excise the head of the list and return it; if the head is not extant, return null | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
@@ -823,2 +827,207 @@ key: "removeHead", | ||
export { CircularDoublyLinkedList, CircularSinglyLinkedList }; | ||
/** | ||
* Implements a singly linked list | ||
* @class SinglyLinkedList | ||
*/ | ||
var SinglyLinkedList = /*#__PURE__*/function () { | ||
function SinglyLinkedList() { | ||
_classCallCheck(this, SinglyLinkedList); | ||
/** | ||
* The head node | ||
* @property {ForwardNode} | ||
*/ | ||
this.head = null; | ||
/** | ||
* The current size of the list | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
} | ||
/** | ||
* Instantiate an empty singly linked list | ||
* @returns {SinglyLinkedList} | ||
* @static | ||
*/ | ||
_createClass(SinglyLinkedList, [{ | ||
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; | ||
return node.next; | ||
} | ||
/** | ||
* 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) node.next = null;else node.next = this.head; | ||
this.head = node; | ||
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) this.head = node;else { | ||
var tmp = this.head; | ||
while (tmp.next !== null) { | ||
tmp = tmp.next; | ||
} | ||
tmp.next = node; | ||
} | ||
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) { | ||
node.next = null; | ||
this.head = node; | ||
} else { | ||
var tmp = this.head; | ||
while (tmp.next !== mark.next) { | ||
// because we maintain a list ref in ea node, not finding the mark | ||
// should never happen... | ||
// but we observe the check nonetheless in the case of a weird edge case | ||
if (!tmp) return null; | ||
tmp = tmp.next; | ||
} | ||
node.next = tmp.next; | ||
tmp.next = node; | ||
} | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Excise the head of the list and return it; if the head is not extant, return null | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
key: "removeHead", | ||
value: function removeHead() { | ||
if (!this.head) return null; | ||
var tmp = this.head; | ||
if (!tmp.next) this.head = null;else this.head = tmp.next; | ||
this.length--; | ||
tmp.list = null; | ||
return tmp; | ||
} | ||
/** | ||
* 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 tmp1 = this.head; | ||
var tmp2; | ||
if (!tmp1.next) this.head = null;else { | ||
while (tmp1.next != null) { | ||
tmp2 = tmp1; | ||
tmp1 = tmp1.next; | ||
} | ||
tmp2.next = null; | ||
} | ||
this.length--; | ||
tmp1.list = null; | ||
return tmp1; | ||
} | ||
/** | ||
* 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 || node.list !== this || !this.length) return null; | ||
var tmp = this.head; // we can blindly point the head at its next; | ||
// if there's a single node, it'll be null, which is what we'd want | ||
if (tmp === node) this.head = this.head.next;else { | ||
var prev = null; | ||
while (tmp != node) { | ||
prev = tmp; | ||
tmp = tmp.next; | ||
} | ||
prev.next = tmp.next; | ||
} | ||
tmp.list = null; | ||
this.length--; | ||
return tmp; | ||
} | ||
}], [{ | ||
key: "create", | ||
value: function create() { | ||
return new SinglyLinkedList(); | ||
} | ||
}]); | ||
return SinglyLinkedList; | ||
}(); | ||
export { CircularDoublyLinkedList, CircularSinglyLinkedList, SinglyLinkedList }; |
@@ -86,3 +86,3 @@ (function (global, factory) { | ||
/** | ||
* Implements a circular singular (linear) linked list | ||
* Implements a circular singly (linear) linked list | ||
* @class CircularSinglyLinkedList | ||
@@ -146,6 +146,5 @@ */ | ||
value: function next(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
if (!node || !node.list || node.list !== this) return null; | ||
var p = node.next; | ||
if (p && node.list == this) return p; | ||
return null; | ||
return p ? p : null; | ||
} | ||
@@ -161,3 +160,3 @@ /** | ||
value: function prev(node) { | ||
if (!node || node.list && node.list !== this) return null; | ||
if (!node || !node.list || node.list !== this) return null; | ||
@@ -204,2 +203,7 @@ var p = _classPrivateMethodGet(this, _findNodeBefore, _findNodeBefore2).call(this, node); | ||
} | ||
/** | ||
* Excise the head of the list and return it; if the head is not extant, return null | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
@@ -829,4 +833,210 @@ key: "removeHead", | ||
/** | ||
* Implements a singly linked list | ||
* @class SinglyLinkedList | ||
*/ | ||
var SinglyLinkedList = /*#__PURE__*/function () { | ||
function SinglyLinkedList() { | ||
_classCallCheck(this, SinglyLinkedList); | ||
/** | ||
* The head node | ||
* @property {ForwardNode} | ||
*/ | ||
this.head = null; | ||
/** | ||
* The current size of the list | ||
* @property {number} | ||
*/ | ||
this.length = 0; | ||
} | ||
/** | ||
* Instantiate an empty singly linked list | ||
* @returns {SinglyLinkedList} | ||
* @static | ||
*/ | ||
_createClass(SinglyLinkedList, [{ | ||
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; | ||
return node.next; | ||
} | ||
/** | ||
* 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) node.next = null;else node.next = this.head; | ||
this.head = node; | ||
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) this.head = node;else { | ||
var tmp = this.head; | ||
while (tmp.next !== null) { | ||
tmp = tmp.next; | ||
} | ||
tmp.next = node; | ||
} | ||
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) { | ||
node.next = null; | ||
this.head = node; | ||
} else { | ||
var tmp = this.head; | ||
while (tmp.next !== mark.next) { | ||
// because we maintain a list ref in ea node, not finding the mark | ||
// should never happen... | ||
// but we observe the check nonetheless in the case of a weird edge case | ||
if (!tmp) return null; | ||
tmp = tmp.next; | ||
} | ||
node.next = tmp.next; | ||
tmp.next = node; | ||
} | ||
node.list = this; | ||
this.length++; | ||
return node; | ||
} | ||
/** | ||
* Excise the head of the list and return it; if the head is not extant, return null | ||
* @returns {(ForwardNode|null)} | ||
*/ | ||
}, { | ||
key: "removeHead", | ||
value: function removeHead() { | ||
if (!this.head) return null; | ||
var tmp = this.head; | ||
if (!tmp.next) this.head = null;else this.head = tmp.next; | ||
this.length--; | ||
tmp.list = null; | ||
return tmp; | ||
} | ||
/** | ||
* 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 tmp1 = this.head; | ||
var tmp2; | ||
if (!tmp1.next) this.head = null;else { | ||
while (tmp1.next != null) { | ||
tmp2 = tmp1; | ||
tmp1 = tmp1.next; | ||
} | ||
tmp2.next = null; | ||
} | ||
this.length--; | ||
tmp1.list = null; | ||
return tmp1; | ||
} | ||
/** | ||
* 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 || node.list !== this || !this.length) return null; | ||
var tmp = this.head; // we can blindly point the head at its next; | ||
// if there's a single node, it'll be null, which is what we'd want | ||
if (tmp === node) this.head = this.head.next;else { | ||
var prev = null; | ||
while (tmp != node) { | ||
prev = tmp; | ||
tmp = tmp.next; | ||
} | ||
prev.next = tmp.next; | ||
} | ||
tmp.list = null; | ||
this.length--; | ||
return tmp; | ||
} | ||
}], [{ | ||
key: "create", | ||
value: function create() { | ||
return new SinglyLinkedList(); | ||
} | ||
}]); | ||
return SinglyLinkedList; | ||
}(); | ||
exports.CircularDoublyLinkedList = CircularDoublyLinkedList; | ||
exports.CircularSinglyLinkedList = CircularSinglyLinkedList; | ||
exports.SinglyLinkedList = SinglyLinkedList; | ||
@@ -833,0 +1043,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){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})})); | ||
!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 h(){return{next:null,prev:null}}function r(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||null}},{key:"prev",value:function(e){if(!e||!e.list||e.list!==this)return null;var t=r(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&&r(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=r(this,a,c).call(this,t);r(this,o,x).call(this,e,n)}}},{key:"pushFront",value:function(e){var t=new l(e);if(!this.head)return r(this,u,f).call(this,t);var n=r(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 r(this,u,f).call(this,t);this.head&&1==this.length?this.head.next=t:r(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 r(this,u,f).call(this,n);var i=r(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 r(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 h,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}(),p=function(){function e(){t(this,e),this.head=null,this.length=0}return i(e,[{key:"size",value:function(){return this.length}},{key:"next",value:function(e){return e&&e.list&&e.list===this?e.next:null}},{key:"pushFront",value:function(e){var t=new l(e);return this.head?t.next=this.head:t.next=null,this.head=t,t.list=this,this.length++,t}},{key:"pushBack",value:function(e){var t=new l(e);if(this.head){for(var n=this.head;null!==n.next;)n=n.next;n.next=t}else this.head=t;return 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){for(var i=this.head;i.next!==t.next;){if(!i)return null;i=i.next}n.next=i.next,i.next=n}else n.next=null,this.head=n;return n.list=this,this.length++,n}},{key:"removeHead",value:function(){if(!this.head)return null;var e=this.head;return e.next?this.head=e.next:this.head=null,this.length--,e.list=null,e}},{key:"pop",value:function(){if(!this.head)return null;var e,t=this.head;if(t.next){for(;null!=t.next;)e=t,t=t.next;e.next=null}else this.head=null;return this.length--,t.list=null,t}},{key:"remove",value:function(e){if(!this.head||!e||e.list!==this||!this.length)return null;var t=this.head;if(t===e)this.head=this.head.next;else{for(var n=null;t!=e;)n=t,t=t.next;n.next=t.next}return t.list=null,this.length--,t}}],[{key:"create",value:function(){return new e}}]),e}();e.CircularDoublyLinkedList=d,e.CircularSinglyLinkedList=v,e.SinglyLinkedList=p,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "connective-tissue", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/connective-tissue.cjs.js", |
@@ -9,6 +9,6 @@ [![Build Status](https://travis-ci.com/MatthewZito/connective-tissue.svg?branch=master)](https://travis-ci.com/MatthewZito/connective-tissue) | ||
- **singly linked list** * | ||
- **circular linked list** * | ||
- **singly linked list** | ||
- **doubly linked list** * | ||
- **header linked list** * | ||
- **circular singly linked list** | ||
- **circular doubly linked list** | ||
@@ -15,0 +15,0 @@ |
102153
2612