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

red-black-tree-typed

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

red-black-tree-typed - npm Package Compare versions

Comparing version 1.51.1 to 1.51.2

26

dist/data-structures/binary-tree/binary-tree.d.ts

@@ -100,3 +100,9 @@ /**

get size(): number;
protected _NIL: NODE;
/**
* The function returns the value of the _NIL property.
* @returns The method is returning the value of the `_NIL` property.
*/
get NIL(): NODE;
/**
* Creates a new instance of BinaryTreeNode with the given key and value.

@@ -145,2 +151,8 @@ * @param {K} key - The key for the new node.

/**
* The function checks if a given node is a real node or null.
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
* @returns a boolean value.
*/
isNodeOrNull(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
/**
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.

@@ -152,9 +164,2 @@ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.

/**
* The function checks if a given value is an entry in a binary tree node.
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
* two type parameters V and NODE, representing the value and node type respectively.
* @returns a boolean value.
*/
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is BTNEntry<K, V>;
/**
* The function checks if a given node is a real node by verifying if it is an instance of

@@ -173,7 +178,8 @@ * BinaryTreeNode and its key is not NaN.

/**
* The function checks if a given node is a real node or null.
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
* The function checks if a given value is an entry in a binary tree node.
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
* two type parameters V and NODE, representing the value and node type respectively.
* @returns a boolean value.
*/
isNodeOrNull(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is BTNEntry<K, V>;
/**

@@ -180,0 +186,0 @@ * Time Complexity O(n)

@@ -9,3 +9,3 @@ /**

import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntry } from '../../types';
import { BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
import { BSTNKeyOrNode, BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
import { BinaryTree, BinaryTreeNode } from './binary-tree';

@@ -214,2 +214,28 @@ import { IBinaryTree } from '../../interfaces';

/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
* callback function.
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
* that you want to search for in the binary search tree. It can be of any type that is compatible
* with the type of nodes in the tree.
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
* function should take a node as its parameter and return a value that can be compared to the
* `identifier` parameter.
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
* using the `ensureNode` method. If it is not provided, the `root`
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
* its default value is taken from the `iterationType` property of the class.
* @returns The method is returning a value of type `NODE | null | undefined`.
*/
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
/**
* Time complexity: O(n)

@@ -216,0 +242,0 @@ * Space complexity: O(n)

@@ -486,2 +486,31 @@ "use strict";

/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
* callback function.
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
* that you want to search for in the binary search tree. It can be of any type that is compatible
* with the type of nodes in the tree.
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
* function should take a node as its parameter and return a value that can be compared to the
* `identifier` parameter.
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
* using the `ensureNode` method. If it is not provided, the `root`
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
* its default value is taken from the `iterationType` property of the class.
* @returns The method is returning a value of type `NODE | null | undefined`.
*/
getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
var _a;
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : undefined;
}
/**
* Time complexity: O(n)

@@ -488,0 +517,0 @@ * Space complexity: O(n)

@@ -1,2 +0,2 @@

import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
import type { BinaryTreeDeleteResult, BTNCallback, KeyOrNodeOrEntry, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
import { CRUD, RBTNColor } from '../../types';

@@ -42,8 +42,2 @@ import { BST, BSTNode } from './bst';

constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K>);
protected _SENTINEL: NODE;
/**
* The function returns the value of the _SENTINEL property.
* @returns The method is returning the value of the `_SENTINEL` property.
*/
get SENTINEL(): NODE;
protected _root: NODE | undefined;

@@ -113,42 +107,2 @@ /**

*
* The function checks if a given node is a real node in a Red-Black Tree.
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
* it can either be of type `NODE` or `undefined`.
* @returns a boolean value.
*/
isRealNode(node: NODE | undefined): node is NODE;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
* callback function.
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
* that you want to search for in the binary search tree. It can be of any type that is compatible
* with the type of nodes in the tree.
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
* function should take a node as its parameter and return a value that can be compared to the
* `identifier` parameter.
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
* using the `ensureNode` method. If it is not provided, the `root`
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
* its default value is taken from the `iterationType` property of the class.
* @returns The method is returning a value of type `NODE | null | undefined`.
*/
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | null | undefined;
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The "clear" function sets the root node of a data structure to a sentinel value and resets the

@@ -155,0 +109,0 @@ * size counter to zero.

@@ -50,4 +50,3 @@ "use strict";

super([], options);
this._SENTINEL = new RedBlackTreeNode(NaN);
this._root = this.SENTINEL;
this._root = this.NIL;
if (keysOrNodesOrEntries) {

@@ -58,9 +57,2 @@ this.addMany(keysOrNodesOrEntries);

/**
* The function returns the value of the _SENTINEL property.
* @returns The method is returning the value of the `_SENTINEL` property.
*/
get SENTINEL() {
return this._SENTINEL;
}
/**
* The function returns the root node of a tree or undefined if there is no root.

@@ -160,49 +152,2 @@ * @returns The root node of the tree structure, or undefined if there is no root node.

*
* The function checks if a given node is a real node in a Red-Black Tree.
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
* it can either be of type `NODE` or `undefined`.
* @returns a boolean value.
*/
isRealNode(node) {
if (node === this.SENTINEL || node === undefined)
return false;
return node instanceof RedBlackTreeNode;
}
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
* callback function.
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
* that you want to search for in the binary search tree. It can be of any type that is compatible
* with the type of nodes in the tree.
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
* function should take a node as its parameter and return a value that can be compared to the
* `identifier` parameter.
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
* using the `ensureNode` method. If it is not provided, the `root`
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
* its default value is taken from the `iterationType` property of the class.
* @returns The method is returning a value of type `NODE | null | undefined`.
*/
getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
var _a;
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : undefined;
}
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The "clear" function sets the root node of a data structure to a sentinel value and resets the

@@ -213,3 +158,3 @@ * size counter to zero.

super.clear();
this._root = this.SENTINEL;
this._root = this.NIL;
}

@@ -376,6 +321,6 @@ /**

if (node.key < current.key) {
current = (_a = current.left) !== null && _a !== void 0 ? _a : this.SENTINEL;
current = (_a = current.left) !== null && _a !== void 0 ? _a : this.NIL;
}
else if (node.key > current.key) {
current = (_b = current.right) !== null && _b !== void 0 ? _b : this.SENTINEL;
current = (_b = current.right) !== null && _b !== void 0 ? _b : this.NIL;
}

@@ -397,4 +342,4 @@ else {

}
node.left = this.SENTINEL;
node.right = this.SENTINEL;
node.left = this.NIL;
node.right = this.NIL;
node.color = 'RED';

@@ -401,0 +346,0 @@ this._insertFixup(node);

{
"name": "red-black-tree-typed",
"version": "1.51.1",
"version": "1.51.2",
"description": "RedBlackTree. Javascript & Typescript Data Structure.",

@@ -145,4 +145,4 @@ "main": "dist/index.js",

"dependencies": {
"data-structure-typed": "^1.51.0"
"data-structure-typed": "^1.51.2"
}
}

@@ -16,3 +16,3 @@ /**

} from '../../types';
import { BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
import { BSTNKeyOrNode, BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
import { BinaryTree, BinaryTreeNode } from './binary-tree';

@@ -548,2 +548,37 @@ import { IBinaryTree } from '../../interfaces';

/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
* callback function.
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
* that you want to search for in the binary search tree. It can be of any type that is compatible
* with the type of nodes in the tree.
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
* function should take a node as its parameter and return a value that can be compared to the
* `identifier` parameter.
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
* using the `ensureNode` method. If it is not provided, the `root`
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
* its default value is taken from the `iterationType` property of the class.
* @returns The method is returning a value of type `NODE | null | undefined`.
*/
override getNode<C extends BTNCallback<NODE>>(
identifier: ReturnType<C> | undefined,
callback: C = this._DEFAULT_CALLBACK as C,
beginRoot: BSTNKeyOrNode<K, NODE> = this.root,
iterationType: IterationType = this.iterationType
): NODE | undefined {
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
}
/**
* Time complexity: O(n)

@@ -550,0 +585,0 @@ * Space complexity: O(n)

import type {
BinaryTreeDeleteResult,
BSTNKeyOrNode,
BTNCallback,
IterationType,
KeyOrNodeOrEntry,

@@ -76,3 +74,3 @@ RBTreeOptions,

this._root = this.SENTINEL;
this._root = this.NIL;

@@ -84,12 +82,2 @@ if (keysOrNodesOrEntries) {

protected _SENTINEL: NODE = new RedBlackTreeNode<K, V>(NaN as K) as unknown as NODE;
/**
* The function returns the value of the _SENTINEL property.
* @returns The method is returning the value of the `_SENTINEL` property.
*/
get SENTINEL(): NODE {
return this._SENTINEL;
}
protected override _root: NODE | undefined;

@@ -198,56 +186,2 @@

*
* The function checks if a given node is a real node in a Red-Black Tree.
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
* it can either be of type `NODE` or `undefined`.
* @returns a boolean value.
*/
override isRealNode(node: NODE | undefined): node is NODE {
if (node === this.SENTINEL || node === undefined) return false;
return node instanceof RedBlackTreeNode;
}
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
* callback function.
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
* that you want to search for in the binary search tree. It can be of any type that is compatible
* with the type of nodes in the tree.
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
* function should take a node as its parameter and return a value that can be compared to the
* `identifier` parameter.
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
* using the `ensureNode` method. If it is not provided, the `root`
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
* its default value is taken from the `iterationType` property of the class.
* @returns The method is returning a value of type `NODE | null | undefined`.
*/
override getNode<C extends BTNCallback<NODE>>(
identifier: ReturnType<C> | undefined,
callback: C = this._DEFAULT_CALLBACK as C,
beginRoot: BSTNKeyOrNode<K, NODE> = this.root,
iterationType: IterationType = this.iterationType
): NODE | null | undefined {
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
}
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The "clear" function sets the root node of a data structure to a sentinel value and resets the

@@ -258,3 +192,3 @@ * size counter to zero.

super.clear();
this._root = this.SENTINEL;
this._root = this.NIL;
}

@@ -437,5 +371,5 @@

if (node.key < current.key) {
current = current.left ?? this.SENTINEL;
current = current.left ?? this.NIL;
} else if (node.key > current.key) {
current = current.right ?? this.SENTINEL;
current = current.right ?? this.NIL;
} else {

@@ -457,4 +391,4 @@ this._replaceNode(current, node);

node.left = this.SENTINEL;
node.right = this.SENTINEL;
node.left = this.NIL;
node.right = this.NIL;
node.color = 'RED';

@@ -461,0 +395,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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