data-structure-typed 1.19.1 → 1.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/heap/heap.d.ts +9 -2
- package/dist/data-structures/heap/heap.js +15 -8
- package/dist/data-structures/interfaces/index.d.ts +10 -8
- package/dist/data-structures/interfaces/index.js +10 -8
- package/dist/data-structures/types/heap.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
import { PriorityQueue } from '../priority-queue';
|
|
9
9
|
import type { HeapOptions } from '../types';
|
|
10
10
|
export declare class HeapItem<T = number> {
|
|
11
|
+
/**
|
|
12
|
+
* The constructor function initializes an instance of a class with a priority and a value.
|
|
13
|
+
* @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
|
|
14
|
+
* optional and has a default value of `NaN`.
|
|
15
|
+
* @param {T | null} [val=null] - The `val` parameter is of type `T | null`, which means it can accept a value of type
|
|
16
|
+
* `T` or `null`.
|
|
17
|
+
*/
|
|
11
18
|
constructor(priority?: number, val?: T | null);
|
|
12
19
|
private _priority;
|
|
13
20
|
get priority(): number;
|
|
@@ -25,8 +32,8 @@ export declare abstract class Heap<T = number> {
|
|
|
25
32
|
protected constructor(options?: HeapOptions<T>);
|
|
26
33
|
protected abstract _pq: PriorityQueue<HeapItem<T>>;
|
|
27
34
|
get pq(): PriorityQueue<HeapItem<T>>;
|
|
28
|
-
protected
|
|
29
|
-
get
|
|
35
|
+
protected _priorityExtractor: (val: T) => number;
|
|
36
|
+
get priorityExtractor(): (val: T) => number;
|
|
30
37
|
/**
|
|
31
38
|
* The function returns the size of a priority queue.
|
|
32
39
|
* @returns The size of the priority queue.
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Heap = exports.HeapItem = void 0;
|
|
4
4
|
var HeapItem = /** @class */ (function () {
|
|
5
|
+
/**
|
|
6
|
+
* The constructor function initializes an instance of a class with a priority and a value.
|
|
7
|
+
* @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
|
|
8
|
+
* optional and has a default value of `NaN`.
|
|
9
|
+
* @param {T | null} [val=null] - The `val` parameter is of type `T | null`, which means it can accept a value of type
|
|
10
|
+
* `T` or `null`.
|
|
11
|
+
*/
|
|
5
12
|
function HeapItem(priority, val) {
|
|
6
13
|
if (priority === void 0) { priority = NaN; }
|
|
7
14
|
if (val === void 0) { val = null; }
|
|
@@ -39,14 +46,14 @@ var Heap = /** @class */ (function () {
|
|
|
39
46
|
*/
|
|
40
47
|
function Heap(options) {
|
|
41
48
|
if (options) {
|
|
42
|
-
var
|
|
43
|
-
if (
|
|
49
|
+
var priorityExtractor = options.priorityExtractor;
|
|
50
|
+
if (priorityExtractor !== undefined && typeof priorityExtractor !== 'function') {
|
|
44
51
|
throw new Error('.constructor expects a valid priority function');
|
|
45
52
|
}
|
|
46
|
-
this.
|
|
53
|
+
this._priorityExtractor = priorityExtractor || (function (el) { return +el; });
|
|
47
54
|
}
|
|
48
55
|
else {
|
|
49
|
-
this.
|
|
56
|
+
this._priorityExtractor = function (el) { return +el; };
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
Object.defineProperty(Heap.prototype, "pq", {
|
|
@@ -56,9 +63,9 @@ var Heap = /** @class */ (function () {
|
|
|
56
63
|
enumerable: false,
|
|
57
64
|
configurable: true
|
|
58
65
|
});
|
|
59
|
-
Object.defineProperty(Heap.prototype, "
|
|
66
|
+
Object.defineProperty(Heap.prototype, "priorityExtractor", {
|
|
60
67
|
get: function () {
|
|
61
|
-
return this.
|
|
68
|
+
return this._priorityExtractor;
|
|
62
69
|
},
|
|
63
70
|
enumerable: false,
|
|
64
71
|
configurable: true
|
|
@@ -117,11 +124,11 @@ var Heap = /** @class */ (function () {
|
|
|
117
124
|
if (priority && Number.isNaN(+priority)) {
|
|
118
125
|
throw new Error('.add expects a numeric priority');
|
|
119
126
|
}
|
|
120
|
-
if (Number.isNaN(+priority) && Number.isNaN(this.
|
|
127
|
+
if (Number.isNaN(+priority) && Number.isNaN(this._priorityExtractor(val))) {
|
|
121
128
|
throw new Error('.add expects a numeric priority '
|
|
122
129
|
+ 'or a constructor callback that returns a number');
|
|
123
130
|
}
|
|
124
|
-
var _priority = !Number.isNaN(+priority) ? priority : this.
|
|
131
|
+
var _priority = !Number.isNaN(+priority) ? priority : this._priorityExtractor(val);
|
|
125
132
|
this._pq.add(new HeapItem(_priority, val));
|
|
126
133
|
return this;
|
|
127
134
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
export * from './abstract-binary-tree';
|
|
2
|
-
export * from './bst';
|
|
3
|
-
export * from './avl-tree';
|
|
4
|
-
export * from './segment-tree';
|
|
5
|
-
export * from './tree-multiset';
|
|
6
2
|
export * from './abstract-graph';
|
|
3
|
+
export * from './avl-tree';
|
|
4
|
+
export * from './binary-tree';
|
|
5
|
+
export * from './bst';
|
|
7
6
|
export * from './directed-graph';
|
|
8
|
-
export * from './undirected-graph';
|
|
9
|
-
export * from './priority-queue';
|
|
10
|
-
export * from './heap';
|
|
11
|
-
export * from './singly-linked-list';
|
|
12
7
|
export * from './doubly-linked-list';
|
|
8
|
+
export * from './heap';
|
|
13
9
|
export * from './navigator';
|
|
10
|
+
export * from './priority-queue';
|
|
11
|
+
export * from './rb-tree';
|
|
12
|
+
export * from './segment-tree';
|
|
13
|
+
export * from './singly-linked-list';
|
|
14
|
+
export * from './tree-multiset';
|
|
15
|
+
export * from './undirected-graph';
|
|
@@ -15,15 +15,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./abstract-binary-tree"), exports);
|
|
18
|
-
__exportStar(require("./bst"), exports);
|
|
19
|
-
__exportStar(require("./avl-tree"), exports);
|
|
20
|
-
__exportStar(require("./segment-tree"), exports);
|
|
21
|
-
__exportStar(require("./tree-multiset"), exports);
|
|
22
18
|
__exportStar(require("./abstract-graph"), exports);
|
|
19
|
+
__exportStar(require("./avl-tree"), exports);
|
|
20
|
+
__exportStar(require("./binary-tree"), exports);
|
|
21
|
+
__exportStar(require("./bst"), exports);
|
|
23
22
|
__exportStar(require("./directed-graph"), exports);
|
|
24
|
-
__exportStar(require("./undirected-graph"), exports);
|
|
25
|
-
__exportStar(require("./priority-queue"), exports);
|
|
26
|
-
__exportStar(require("./heap"), exports);
|
|
27
|
-
__exportStar(require("./singly-linked-list"), exports);
|
|
28
23
|
__exportStar(require("./doubly-linked-list"), exports);
|
|
24
|
+
__exportStar(require("./heap"), exports);
|
|
29
25
|
__exportStar(require("./navigator"), exports);
|
|
26
|
+
__exportStar(require("./priority-queue"), exports);
|
|
27
|
+
__exportStar(require("./rb-tree"), exports);
|
|
28
|
+
__exportStar(require("./segment-tree"), exports);
|
|
29
|
+
__exportStar(require("./singly-linked-list"), exports);
|
|
30
|
+
__exportStar(require("./tree-multiset"), exports);
|
|
31
|
+
__exportStar(require("./undirected-graph"), exports);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.3",
|
|
4
4
|
"description": "Javascript & TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|