Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tsdotnet/linked-node-list

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsdotnet/linked-node-list - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

172

dist-esm/LinkedNodeList.js

@@ -8,2 +8,3 @@ /*

import ArgumentException from '@tsdotnet/exceptions/dist/ArgumentException';
import IterableCollectionBase from '@tsdotnet/collection-base/dist/IterableCollectionBase';
/* eslint-disable @typescript-eslint/no-this-alias */

@@ -27,6 +28,6 @@ /*****************************

*/
export default class LinkedNodeList {
export default class LinkedNodeList extends IterableCollectionBase {
constructor() {
super(...arguments);
this._unsafeCount = 0;
this._version = 0;
}

@@ -43,9 +44,2 @@ /**

/**
* The version number used to track changes.
* @returns {number}
*/
get version() {
return this._version;
}
/**
* The first node. Will be null if the collection is empty.

@@ -62,15 +56,2 @@ */

}
/**
* Iteratively counts the number of linked nodes and returns the value.
* @returns {number}
*/
getCount() {
let next = this._first;
let i = 0;
while (next) {
i++;
next = next.next;
}
return i;
}
static *valueIterableFrom(list) {

@@ -94,17 +75,2 @@ if (!list)

}
*[Symbol.iterator]() {
const version = this._version;
let current, next = this.first;
while (next) {
this.assertVersion(version);
current = next;
next = current.next;
yield current;
}
}
assertVersion(version) {
if (version !== this._version)
throw new InvalidOperationException('Collection was modified.');
return true;
}
/**

@@ -136,3 +102,3 @@ * Erases the linked node's references to each other and returns the number of nodes.

console.warn('LinkedNodeList: Forward versus reverse count does not match when clearing. Forward: ' + cF + ', Reverse: ' + cL);
this._version++;
this._incrementVersion();
this._unsafeCount = 0;

@@ -142,2 +108,37 @@ return cF;

/**
* Removes the specified node.
* Returns true if successful and false if not found (already removed).
* @param node
* @returns {boolean}
*/
removeNode(node) {
if (!node)
throw new ArgumentNullException('node');
const _ = this, prev = node.previous, next = node.next;
let a = false, b = false;
if (prev)
prev.next = next;
else if (_._first == node)
_._first = next;
else
a = true;
if (next)
next.previous = prev;
else if (_._last == node)
_._last = prev;
else
b = true;
if (a !== b) {
throw new ArgumentException('node', `Provided node is has no ${a ? 'previous' : 'next'} reference but is not the ${a ? 'first' : 'last'} node!`);
}
const removed = !a && !b;
if (removed) {
_._incrementVersion();
_._unsafeCount--;
node.previous = undefined;
node.next = undefined;
}
return removed;
}
/**
* Clears the list.

@@ -205,35 +206,30 @@ */

/**
* Removes the specified node.
* Returns true if successful and false if not found (already removed).
* Inserts a node before the specified 'before' node.
* If no 'before' node is specified, it inserts it as the first node.
* @param node
* @returns {boolean}
* @param before
* @returns {LinkedNodeList}
*/
removeNode(node) {
if (!node)
throw new ArgumentNullException('node');
const _ = this, prev = node.previous, next = node.next;
let a = false, b = false;
if (prev)
prev.next = next;
else if (_._first == node)
_._first = next;
else
a = true;
if (next)
next.previous = prev;
else if (_._last == node)
_._last = prev;
else
b = true;
if (a !== b) {
throw new ArgumentException('node', `Provided node is has no ${a ? 'previous' : 'next'} reference but is not the ${a ? 'first' : 'last'} node!`);
addNodeBefore(node, before) {
assertValidDetached(node);
const _ = this;
if (!before) {
before = _._first;
}
const removed = !a && !b;
if (removed) {
_._version++;
_._unsafeCount--;
node.previous = undefined;
node.next = undefined;
if (before) {
const prev = before.previous;
node.previous = prev;
node.next = before;
before.previous = node;
if (prev)
prev.next = node;
if (before == _._first)
_._first = node;
}
return removed;
else {
_._first = _._last = node;
}
_._incrementVersion();
_._unsafeCount++;
return this;
}

@@ -290,32 +286,2 @@ /**

/**
* Inserts a node before the specified 'before' node.
* If no 'before' node is specified, it inserts it as the first node.
* @param node
* @param before
* @returns {LinkedNodeList}
*/
addNodeBefore(node, before) {
assertValidDetached(node);
const _ = this;
if (!before) {
before = _._first;
}
if (before) {
const prev = before.previous;
node.previous = prev;
node.next = before;
before.previous = node;
if (prev)
prev.next = node;
if (before == _._first)
_._first = node;
}
else {
_._first = _._last = node;
}
_._version++;
_._unsafeCount++;
return this;
}
/**
* Inserts a node after the specified 'after' node.

@@ -346,3 +312,3 @@ * If no 'after' node is specified, it appends it as the last node.

}
_._version++;
_._incrementVersion();
_._unsafeCount++;

@@ -372,5 +338,13 @@ return _;

_._last = replacement;
_._version++;
_._incrementVersion();
return _;
}
*_getIterator() {
let current, next = this.first;
while (next) {
current = next;
next = current.next;
yield current;
}
}
}

@@ -377,0 +351,0 @@ function assertValidDetached(node, propName = 'node') {

import { ArrayLikeWritable, PredicateWithIndex } from '@tsdotnet/common-interfaces';
import { LinkedNode, LinkedNodeWithValue, NodeWithValue } from './LinkedListNode';
import IterableCollectionBase from '@tsdotnet/collection-base/dist/IterableCollectionBase';
export { LinkedNode, LinkedNodeWithValue, NodeWithValue };

@@ -21,7 +22,5 @@ /*****************************

*/
export default class LinkedNodeList<TNode extends LinkedNode<TNode>> implements Iterable<TNode> {
export default class LinkedNodeList<TNode extends LinkedNode<TNode>> extends IterableCollectionBase<TNode> {
private _first;
private _version;
private _last;
constructor();
private _unsafeCount;

@@ -36,7 +35,2 @@ /**

/**
* The version number used to track changes.
* @returns {number}
*/
get version(): number;
/**
* The first node. Will be null if the collection is empty.

@@ -49,11 +43,4 @@ */

get last(): TNode | undefined;
/**
* Iteratively counts the number of linked nodes and returns the value.
* @returns {number}
*/
getCount(): number;
static valueIterableFrom<T>(list: LinkedNodeList<LinkedNodeWithValue<T>>): Iterable<T>;
static copyValues<T, TDestination extends ArrayLikeWritable<any>>(list: LinkedNodeList<LinkedNodeWithValue<T>>, array: TDestination, index?: number): TDestination;
[Symbol.iterator](): Iterator<TNode>;
assertVersion(version: number): true | never;
/**

@@ -65,2 +52,9 @@ * Erases the linked node's references to each other and returns the number of nodes.

/**
* Removes the specified node.
* Returns true if successful and false if not found (already removed).
* @param node
* @returns {boolean}
*/
removeNode(node: TNode): boolean;
/**
* Clears the list.

@@ -92,8 +86,9 @@ */

/**
* Removes the specified node.
* Returns true if successful and false if not found (already removed).
* Inserts a node before the specified 'before' node.
* If no 'before' node is specified, it inserts it as the first node.
* @param node
* @returns {boolean}
* @param before
* @returns {LinkedNodeList}
*/
removeNode(node: TNode): boolean;
addNodeBefore(node: TNode, before?: TNode): this;
/**

@@ -124,10 +119,2 @@ * Removes the first node and returns it if successful.

/**
* Inserts a node before the specified 'before' node.
* If no 'before' node is specified, it inserts it as the first node.
* @param node
* @param before
* @returns {LinkedNodeList}
*/
addNodeBefore(node: TNode, before?: TNode): this;
/**
* Inserts a node after the specified 'after' node.

@@ -147,2 +134,3 @@ * If no 'after' node is specified, it appends it as the last node.

replace(node: TNode, replacement: TNode): this;
protected _getIterator(): Iterator<TNode>;
}

@@ -11,2 +11,3 @@ "use strict";

const ArgumentException_1 = tslib_1.__importDefault(require("@tsdotnet/exceptions/dist/ArgumentException"));
const IterableCollectionBase_1 = tslib_1.__importDefault(require("@tsdotnet/collection-base/dist/IterableCollectionBase"));
/* eslint-disable @typescript-eslint/no-this-alias */

@@ -30,6 +31,6 @@ /*****************************

*/
class LinkedNodeList {
class LinkedNodeList extends IterableCollectionBase_1.default {
constructor() {
super(...arguments);
this._unsafeCount = 0;
this._version = 0;
}

@@ -46,9 +47,2 @@ /**

/**
* The version number used to track changes.
* @returns {number}
*/
get version() {
return this._version;
}
/**
* The first node. Will be null if the collection is empty.

@@ -65,15 +59,2 @@ */

}
/**
* Iteratively counts the number of linked nodes and returns the value.
* @returns {number}
*/
getCount() {
let next = this._first;
let i = 0;
while (next) {
i++;
next = next.next;
}
return i;
}
static *valueIterableFrom(list) {

@@ -97,17 +78,2 @@ if (!list)

}
*[Symbol.iterator]() {
const version = this._version;
let current, next = this.first;
while (next) {
this.assertVersion(version);
current = next;
next = current.next;
yield current;
}
}
assertVersion(version) {
if (version !== this._version)
throw new InvalidOperationException_1.default('Collection was modified.');
return true;
}
/**

@@ -139,3 +105,3 @@ * Erases the linked node's references to each other and returns the number of nodes.

console.warn('LinkedNodeList: Forward versus reverse count does not match when clearing. Forward: ' + cF + ', Reverse: ' + cL);
this._version++;
this._incrementVersion();
this._unsafeCount = 0;

@@ -145,2 +111,37 @@ return cF;

/**
* Removes the specified node.
* Returns true if successful and false if not found (already removed).
* @param node
* @returns {boolean}
*/
removeNode(node) {
if (!node)
throw new ArgumentNullException_1.default('node');
const _ = this, prev = node.previous, next = node.next;
let a = false, b = false;
if (prev)
prev.next = next;
else if (_._first == node)
_._first = next;
else
a = true;
if (next)
next.previous = prev;
else if (_._last == node)
_._last = prev;
else
b = true;
if (a !== b) {
throw new ArgumentException_1.default('node', `Provided node is has no ${a ? 'previous' : 'next'} reference but is not the ${a ? 'first' : 'last'} node!`);
}
const removed = !a && !b;
if (removed) {
_._incrementVersion();
_._unsafeCount--;
node.previous = undefined;
node.next = undefined;
}
return removed;
}
/**
* Clears the list.

@@ -208,35 +209,30 @@ */

/**
* Removes the specified node.
* Returns true if successful and false if not found (already removed).
* Inserts a node before the specified 'before' node.
* If no 'before' node is specified, it inserts it as the first node.
* @param node
* @returns {boolean}
* @param before
* @returns {LinkedNodeList}
*/
removeNode(node) {
if (!node)
throw new ArgumentNullException_1.default('node');
const _ = this, prev = node.previous, next = node.next;
let a = false, b = false;
if (prev)
prev.next = next;
else if (_._first == node)
_._first = next;
else
a = true;
if (next)
next.previous = prev;
else if (_._last == node)
_._last = prev;
else
b = true;
if (a !== b) {
throw new ArgumentException_1.default('node', `Provided node is has no ${a ? 'previous' : 'next'} reference but is not the ${a ? 'first' : 'last'} node!`);
addNodeBefore(node, before) {
assertValidDetached(node);
const _ = this;
if (!before) {
before = _._first;
}
const removed = !a && !b;
if (removed) {
_._version++;
_._unsafeCount--;
node.previous = undefined;
node.next = undefined;
if (before) {
const prev = before.previous;
node.previous = prev;
node.next = before;
before.previous = node;
if (prev)
prev.next = node;
if (before == _._first)
_._first = node;
}
return removed;
else {
_._first = _._last = node;
}
_._incrementVersion();
_._unsafeCount++;
return this;
}

@@ -293,32 +289,2 @@ /**

/**
* Inserts a node before the specified 'before' node.
* If no 'before' node is specified, it inserts it as the first node.
* @param node
* @param before
* @returns {LinkedNodeList}
*/
addNodeBefore(node, before) {
assertValidDetached(node);
const _ = this;
if (!before) {
before = _._first;
}
if (before) {
const prev = before.previous;
node.previous = prev;
node.next = before;
before.previous = node;
if (prev)
prev.next = node;
if (before == _._first)
_._first = node;
}
else {
_._first = _._last = node;
}
_._version++;
_._unsafeCount++;
return this;
}
/**
* Inserts a node after the specified 'after' node.

@@ -349,3 +315,3 @@ * If no 'after' node is specified, it appends it as the last node.

}
_._version++;
_._incrementVersion();
_._unsafeCount++;

@@ -375,5 +341,13 @@ return _;

_._last = replacement;
_._version++;
_._incrementVersion();
return _;
}
*_getIterator() {
let current, next = this.first;
while (next) {
current = next;
next = current.next;
yield current;
}
}
}

@@ -380,0 +354,0 @@ exports.default = LinkedNodeList;

{
"name": "@tsdotnet/linked-node-list",
"version": "1.1.1",
"version": "1.1.2",
"description": "An unprotected bi-directional linked list. Useful for implementing other collections.",

@@ -16,2 +16,3 @@ "author": "electricessence",

"bump": "npm run precommit && npm version patch",
"bump-minor": "npm run precommit && npm version minor",
"docs": "rimraf docs/* && rimraf docs/.nojekyll && typedoc --options typedoc.json --readme none --theme minimal && node ./.build/create-nojekyll.js",

@@ -52,2 +53,3 @@ "lint": "eslint src/**/*.ts",

"dependencies": {
"@tsdotnet/collection-base": "^1.0.2",
"@tsdotnet/common-interfaces": "^1.0.2",

@@ -54,0 +56,0 @@ "@tsdotnet/exceptions": "^1.0.12"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc