Socket
Socket
Sign inDemoInstall

directed-graph-typed

Package Overview
Dependencies
Maintainers
1
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

directed-graph-typed - npm Package Compare versions

Comparing version 1.38.9 to 1.39.0

8

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

@@ -73,2 +73,10 @@ export declare class BinaryIndexedTree {

/**
* The function calculates the prefix sum of an array using a binary indexed tree.
* @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
* array for which we want to calculate the prefix sum.
* @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
* `i`.
*/
getPrefixSum(i: number): number;
/**
* The function returns the value of a specific index in a freqMap data structure, or a default value if

@@ -75,0 +83,0 @@ * the index is not found.

@@ -124,2 +124,19 @@ "use strict";

/**
* The function calculates the prefix sum of an array using a binary indexed tree.
* @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
* array for which we want to calculate the prefix sum.
* @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
* `i`.
*/
getPrefixSum(i) {
this._checkIndex(i);
i++; // Convert to 1-based index
let sum = 0;
while (i > 0) {
sum += this._getFrequency(i);
i -= i & -i;
}
return sum;
}
/**
* The function returns the value of a specific index in a freqMap data structure, or a default value if

@@ -126,0 +143,0 @@ * the index is not found.

6

dist/data-structures/graph/abstract-graph.d.ts

@@ -68,3 +68,3 @@ import type { DijkstraResult, VertexKey } from '../../types';

abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
abstract removeEdge(edge: E): E | null;
abstract deleteEdge(edge: E): E | null;
abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;

@@ -94,3 +94,3 @@ abstract degreeOf(vertexOrKey: V | VertexKey): number;

/**
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID

@@ -100,3 +100,3 @@ * (`VertexKey`).

*/
removeVertex(vertexOrKey: V | VertexKey): boolean;
deleteVertex(vertexOrKey: V | VertexKey): boolean;
/**

@@ -103,0 +103,0 @@ * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.

@@ -120,3 +120,3 @@ "use strict";

/**
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID

@@ -126,3 +126,3 @@ * (`VertexKey`).

*/
removeVertex(vertexOrKey) {
deleteVertex(vertexOrKey) {
const vertexKey = this._getVertexKey(vertexOrKey);

@@ -141,3 +141,3 @@ return this._vertices.delete(vertexKey);

for (const v of vertices) {
removed.push(this.removeVertex(v));
removed.push(this.deleteVertex(v));
}

@@ -535,3 +535,3 @@ return removed.length > 0;

}
const heap = new priority_queue_1.PriorityQueue((a, b) => a.key - b.key);
const heap = new priority_queue_1.PriorityQueue({ comparator: (a, b) => a.key - b.key });
heap.add({ key: 0, val: srcVertex });

@@ -538,0 +538,0 @@ distMap.set(srcVertex, 0);

@@ -87,3 +87,3 @@ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';

*/
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
deleteEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
/**

@@ -93,5 +93,5 @@ * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.

* and `dest`, which represent the source and destination vertices of the edge, respectively.
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
* @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
*/
removeEdge(edge: E): E | null;
deleteEdge(edge: E): E | null;
/**

@@ -105,3 +105,3 @@ * The function removes edges between two vertices and returns the removed edges.

*/
removeEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
deleteEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
/**

@@ -108,0 +108,0 @@ * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.

@@ -133,3 +133,3 @@ "use strict";

*/
removeEdgeSrcToDest(srcOrKey, destOrKey) {
deleteEdgeSrcToDest(srcOrKey, destOrKey) {
const src = this._getVertex(srcOrKey);

@@ -155,5 +155,5 @@ const dest = this._getVertex(destOrKey);

* and `dest`, which represent the source and destination vertices of the edge, respectively.
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
* @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
*/
removeEdge(edge) {
deleteEdge(edge) {
let removed = null;

@@ -182,7 +182,7 @@ const src = this._getVertex(edge.src);

*/
removeEdgesBetween(v1, v2) {
deleteEdgesBetween(v1, v2) {
const removed = [];
if (v1 && v2) {
const v1ToV2 = this.removeEdgeSrcToDest(v1, v2);
const v2ToV1 = this.removeEdgeSrcToDest(v2, v1);
const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
v1ToV2 && removed.push(v1ToV2);

@@ -189,0 +189,0 @@ v2ToV1 && removed.push(v2ToV1);

@@ -74,9 +74,9 @@ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';

*/
removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
deleteEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
/**
* The removeEdge function removes an edge between two vertices in a graph.
* The deleteEdge function removes an edge between two vertices in a graph.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
*/
removeEdge(edge: E): E | null;
deleteEdge(edge: E): E | null;
/**

@@ -83,0 +83,0 @@ * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that

@@ -112,3 +112,3 @@ "use strict";

*/
removeEdgeBetween(v1, v2) {
deleteEdgeBetween(v1, v2) {
const vertex1 = this._getVertex(v1);

@@ -131,8 +131,8 @@ const vertex2 = this._getVertex(v2);

/**
* The removeEdge function removes an edge between two vertices in a graph.
* The deleteEdge function removes an edge between two vertices in a graph.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
*/
removeEdge(edge) {
return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
deleteEdge(edge) {
return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
}

@@ -139,0 +139,0 @@ /**

@@ -8,6 +8,9 @@ /**

import type { Comparator, DFSOrderPattern } from '../../types';
export declare class Heap<E> {
export declare class Heap<E = any> {
protected nodes: E[];
protected readonly comparator: Comparator<E>;
constructor(comparator: Comparator<E>);
constructor(options: {
comparator: Comparator<E>;
nodes?: E[];
});
/**

@@ -24,7 +27,9 @@ * Get the size (number of elements) of the heap.

* Static method that creates a binary heap from an array of nodes and a comparison function.
* @param nodes
* @param comparator - Comparison function.
* @returns A new Heap instance.
* @param options
*/
static heapify<E>(nodes: E[], comparator: Comparator<E>): Heap<E>;
static heapify<E>(options: {
nodes: E[];
comparator: Comparator<E>;
}): Heap<E>;
/**

@@ -31,0 +36,0 @@ * Insert an element into the heap and maintain the heap properties.

@@ -11,5 +11,9 @@ "use strict";

class Heap {
constructor(comparator) {
constructor(options) {
this.nodes = [];
this.comparator = comparator;
this.comparator = options.comparator;
if (options.nodes && options.nodes.length > 0) {
this.nodes = options.nodes;
this.fix();
}
}

@@ -32,11 +36,7 @@ /**

* Static method that creates a binary heap from an array of nodes and a comparison function.
* @param nodes
* @param comparator - Comparison function.
* @returns A new Heap instance.
* @param options
*/
static heapify(nodes, comparator) {
const binaryHeap = new Heap(comparator);
binaryHeap.nodes = [...nodes];
binaryHeap.fix(); // Fix heap properties
return binaryHeap;
static heapify(options) {
return new Heap(options);
}

@@ -166,3 +166,3 @@ /**

clone() {
const clonedHeap = new Heap(this.comparator);
const clonedHeap = new Heap({ comparator: this.comparator });
clonedHeap.nodes = [...this.nodes];

@@ -169,0 +169,0 @@ return clonedHeap;

@@ -11,3 +11,6 @@ /**

export declare class MaxHeap<E = any> extends Heap<E> {
constructor(comparator?: Comparator<E>);
constructor(options?: {
comparator: Comparator<E>;
nodes?: E[];
});
}

@@ -13,13 +13,15 @@ "use strict";

class MaxHeap extends heap_1.Heap {
constructor(comparator = (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
constructor(options = {
comparator: (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
}
else {
return b - a;
}
}
else {
return b - a;
}
}) {
super(comparator);
super(options);
}
}
exports.MaxHeap = MaxHeap;

@@ -11,3 +11,6 @@ /**

export declare class MinHeap<E = any> extends Heap<E> {
constructor(comparator?: Comparator<E>);
constructor(options?: {
comparator: Comparator<E>;
nodes?: E[];
});
}

@@ -13,13 +13,15 @@ "use strict";

class MinHeap extends heap_1.Heap {
constructor(comparator = (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
constructor(options = {
comparator: (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
}
else {
return a - b;
}
}
else {
return a - b;
}
}) {
super(comparator);
super(options);
}
}
exports.MinHeap = MinHeap;

@@ -11,3 +11,6 @@ /**

export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
constructor(compare?: Comparator<E>);
constructor(options?: {
comparator: Comparator<E>;
nodes?: E[];
});
}

@@ -13,13 +13,15 @@ "use strict";

class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
constructor(compare = (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
constructor(options = {
comparator: (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
}
else {
return b - a;
}
}
else {
return b - a;
}
}) {
super(compare);
super(options);
}
}
exports.MaxPriorityQueue = MaxPriorityQueue;

@@ -11,3 +11,6 @@ /**

export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
constructor(compare?: Comparator<E>);
constructor(options?: {
comparator: Comparator<E>;
nodes?: E[];
});
}

@@ -13,13 +13,15 @@ "use strict";

class MinPriorityQueue extends priority_queue_1.PriorityQueue {
constructor(compare = (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
constructor(options = {
comparator: (a, b) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
}
else {
return a - b;
}
}
else {
return a - b;
}
}) {
super(compare);
super(options);
}
}
exports.MinPriorityQueue = MinPriorityQueue;

@@ -10,4 +10,7 @@ /**

import { Comparator } from '../../types';
export declare class PriorityQueue<E> extends Heap<E> {
constructor(comparator: Comparator<E>);
export declare class PriorityQueue<E = any> extends Heap<E> {
constructor(options: {
comparator: Comparator<E>;
nodes?: E[];
});
}

@@ -13,6 +13,6 @@ "use strict";

class PriorityQueue extends heap_1.Heap {
constructor(comparator) {
super(comparator);
constructor(options) {
super(options);
}
}
exports.PriorityQueue = PriorityQueue;
{
"name": "directed-graph-typed",
"version": "1.38.9",
"version": "1.39.0",
"description": "Directed Graph. Javascript & Typescript Data Structure.",

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

"dependencies": {
"data-structure-typed": "^1.38.9"
"data-structure-typed": "^1.39.0"
}
}

@@ -147,2 +147,22 @@ /**

/**
* The function calculates the prefix sum of an array using a binary indexed tree.
* @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
* array for which we want to calculate the prefix sum.
* @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
* `i`.
*/
getPrefixSum(i: number): number {
this._checkIndex(i);
i++; // Convert to 1-based index
let sum = 0;
while (i > 0) {
sum += this._getFrequency(i);
i -= i & -i;
}
return sum;
}
/**
* The function returns the value of a specific index in a freqMap data structure, or a default value if

@@ -149,0 +169,0 @@ * the index is not found.

@@ -133,3 +133,3 @@ /**

abstract removeEdge(edge: E): E | null;
abstract deleteEdge(edge: E): E | null;

@@ -183,3 +183,3 @@ abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;

/**
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID

@@ -189,3 +189,3 @@ * (`VertexKey`).

*/
removeVertex(vertexOrKey: V | VertexKey): boolean {
deleteVertex(vertexOrKey: V | VertexKey): boolean {
const vertexKey = this._getVertexKey(vertexOrKey);

@@ -205,3 +205,3 @@ return this._vertices.delete(vertexKey);

for (const v of vertices) {
removed.push(this.removeVertex(v));
removed.push(this.deleteVertex(v));
}

@@ -629,3 +629,3 @@ return removed.length > 0;

const heap = new PriorityQueue<{ key: number; val: V }>((a, b) => a.key - b.key);
const heap = new PriorityQueue<{ key: number; val: V }>({comparator: (a, b) => a.key - b.key});
heap.add({key: 0, val: srcVertex});

@@ -632,0 +632,0 @@

@@ -156,3 +156,3 @@ /**

*/
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null {
deleteEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null {
const src: V | null = this._getVertex(srcOrKey);

@@ -181,5 +181,5 @@ const dest: V | null = this._getVertex(destOrKey);

* and `dest`, which represent the source and destination vertices of the edge, respectively.
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
* @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
*/
removeEdge(edge: E): E | null {
deleteEdge(edge: E): E | null {
let removed: E | null = null;

@@ -211,8 +211,8 @@ const src = this._getVertex(edge.src);

*/
removeEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[] {
deleteEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[] {
const removed: E[] = [];
if (v1 && v2) {
const v1ToV2 = this.removeEdgeSrcToDest(v1, v2);
const v2ToV1 = this.removeEdgeSrcToDest(v2, v1);
const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);

@@ -219,0 +219,0 @@ v1ToV2 && removed.push(v1ToV2);

@@ -130,3 +130,3 @@ /**

*/
removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null {
deleteEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null {
const vertex1: V | null = this._getVertex(v1);

@@ -152,8 +152,8 @@ const vertex2: V | null = this._getVertex(v2);

/**
* The removeEdge function removes an edge between two vertices in a graph.
* The deleteEdge function removes an edge between two vertices in a graph.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
*/
removeEdge(edge: E): E | null {
return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
deleteEdge(edge: E): E | null {
return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
}

@@ -160,0 +160,0 @@

@@ -10,8 +10,12 @@ /**

export class Heap<E> {
export class Heap<E = any> {
protected nodes: E[] = [];
protected readonly comparator: Comparator<E>;
constructor(comparator: Comparator<E>) {
this.comparator = comparator;
constructor(options: { comparator: Comparator<E>; nodes?: E[] }) {
this.comparator = options.comparator;
if (options.nodes && options.nodes.length > 0) {
this.nodes = options.nodes;
this.fix();
}
}

@@ -36,11 +40,7 @@

* Static method that creates a binary heap from an array of nodes and a comparison function.
* @param nodes
* @param comparator - Comparison function.
* @returns A new Heap instance.
* @param options
*/
static heapify<E>(nodes: E[], comparator: Comparator<E>): Heap<E> {
const binaryHeap = new Heap<E>(comparator);
binaryHeap.nodes = [...nodes];
binaryHeap.fix(); // Fix heap properties
return binaryHeap;
static heapify<E>(options: { nodes: E[]; comparator: Comparator<E> }): Heap<E> {
return new Heap<E>(options);
}

@@ -185,3 +185,3 @@

clone(): Heap<E> {
const clonedHeap = new Heap<E>(this.comparator);
const clonedHeap = new Heap<E>({comparator: this.comparator});
clonedHeap.nodes = [...this.nodes];

@@ -275,3 +275,3 @@ return clonedHeap;

root?: FibonacciHeapNode<E>;
size: number = 0;
size = 0;
protected min?: FibonacciHeapNode<E>;

@@ -278,0 +278,0 @@ protected readonly comparator: Comparator<E>;

@@ -14,12 +14,14 @@ /**

constructor(
comparator: Comparator<E> = (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return b - a;
options: { comparator: Comparator<E>; nodes?: E[] } = {
comparator: (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return b - a;
}
}
}
) {
super(comparator);
super(options);
}
}

@@ -14,12 +14,14 @@ /**

constructor(
comparator: Comparator<E> = (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return a - b;
options: { comparator: Comparator<E>; nodes?: E[] } = {
comparator: (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return a - b;
}
}
}
) {
super(comparator);
super(options);
}
}

@@ -13,12 +13,14 @@ /**

constructor(
compare: Comparator<E> = (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return b - a;
options: { comparator: Comparator<E>; nodes?: E[] } = {
comparator: (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return b - a;
}
}
}
) {
super(compare);
super(options);
}
}

@@ -13,12 +13,14 @@ /**

constructor(
compare: Comparator<E> = (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return a - b;
options: { comparator: Comparator<E>; nodes?: E[] } = {
comparator: (a: E, b: E) => {
if (!(typeof a === 'number' && typeof b === 'number')) {
throw new Error('The a, b params of compare function must be number');
} else {
return a - b;
}
}
}
) {
super(compare);
super(options);
}
}

@@ -12,6 +12,6 @@ /**

export class PriorityQueue<E> extends Heap<E> {
constructor(comparator: Comparator<E>) {
super(comparator);
export class PriorityQueue<E = any> extends Heap<E> {
constructor(options: { comparator: Comparator<E>; nodes?: E[] }) {
super(options);
}
}
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