nlptoolkit-datastructure 1.0.1 → 1.0.2
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/heap/Heap.d.ts +13 -0
- package/dist/heap/Heap.js +74 -0
- package/dist/heap/Heap.js.map +1 -0
- package/dist/heap/HeapNode.d.ts +5 -0
- package/dist/heap/HeapNode.js +23 -0
- package/dist/heap/HeapNode.js.map +1 -0
- package/dist/heap/MaxHeap.d.ts +5 -0
- package/dist/heap/MaxHeap.js +24 -0
- package/dist/heap/MaxHeap.js.map +1 -0
- package/dist/heap/MinHeap.d.ts +5 -0
- package/dist/heap/MinHeap.js +24 -0
- package/dist/heap/MinHeap.js.map +1 -0
- package/package.json +1 -1
- package/source/heap/Heap.ts +73 -0
- package/source/heap/HeapNode.ts +13 -0
- package/source/heap/MaxHeap.ts +14 -0
- package/source/heap/MinHeap.ts +13 -0
- package/tests/HeapTest.ts +40 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class Heap<T> {
|
|
2
|
+
private readonly array;
|
|
3
|
+
protected comparator: <T>(item1: T, item2: T) => number;
|
|
4
|
+
private count;
|
|
5
|
+
constructor(N: number, comparator: <T>(item1: T, item2: T) => number);
|
|
6
|
+
compare(data1: T, data2: T): number;
|
|
7
|
+
isEmpty(): boolean;
|
|
8
|
+
private swapNode;
|
|
9
|
+
protected percolateDown(no: number): void;
|
|
10
|
+
protected percolateUp(no: number): void;
|
|
11
|
+
delete(): T;
|
|
12
|
+
insert(data: T): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./HeapNode"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Heap = void 0;
|
|
13
|
+
const HeapNode_1 = require("./HeapNode");
|
|
14
|
+
class Heap {
|
|
15
|
+
constructor(N, comparator) {
|
|
16
|
+
this.comparator = comparator;
|
|
17
|
+
this.array = new Array();
|
|
18
|
+
this.count = 0;
|
|
19
|
+
for (let i = 0; i < N; i++) {
|
|
20
|
+
this.array.push();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
compare(data1, data2) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
isEmpty() {
|
|
27
|
+
return this.count == 0;
|
|
28
|
+
}
|
|
29
|
+
swapNode(index1, index2) {
|
|
30
|
+
let tmp = this.array[index1];
|
|
31
|
+
this.array[index1] = this.array[index2];
|
|
32
|
+
this.array[index2] = tmp;
|
|
33
|
+
}
|
|
34
|
+
percolateDown(no) {
|
|
35
|
+
let left = 2 * no + 1;
|
|
36
|
+
let right = 2 * no + 2;
|
|
37
|
+
while ((left < this.count && this.compare(this.array[no].getData(), this.array[left].getData()) < 0) ||
|
|
38
|
+
(right < this.count && this.compare(this.array[no].getData(), this.array[right].getData()) < 0)) {
|
|
39
|
+
if (right >= this.count || this.compare(this.array[left].getData(), this.array[right].getData()) > 0) {
|
|
40
|
+
this.swapNode(no, left);
|
|
41
|
+
no = left;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.swapNode(no, right);
|
|
45
|
+
no = right;
|
|
46
|
+
}
|
|
47
|
+
left = 2 * no + 1;
|
|
48
|
+
right = 2 * no + 2;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
percolateUp(no) {
|
|
52
|
+
let parent = Math.floor((no - 1) / 2);
|
|
53
|
+
while (parent >= 0 && this.compare(this.array[parent].getData(), this.array[no].getData()) < 0) {
|
|
54
|
+
this.swapNode(parent, no);
|
|
55
|
+
no = parent;
|
|
56
|
+
parent = Math.floor((no - 1) / 2);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
delete() {
|
|
60
|
+
let tmp = this.array[0];
|
|
61
|
+
this.array[0] = this.array[this.count - 1];
|
|
62
|
+
this.percolateDown(0);
|
|
63
|
+
this.count = this.count - 1;
|
|
64
|
+
return tmp.getData();
|
|
65
|
+
}
|
|
66
|
+
insert(data) {
|
|
67
|
+
this.count = this.count + 1;
|
|
68
|
+
this.array[this.count - 1] = new HeapNode_1.HeapNode(data);
|
|
69
|
+
this.percolateUp(this.count - 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.Heap = Heap;
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=Heap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Heap.js","sourceRoot":"","sources":["../../source/heap/Heap.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,yCAAoC;IAEpC,MAAa,IAAI;QAMb,YAAY,CAAS,EAAE,UAA6C;YAChE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;YAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,EAAe,CAAA;YACrC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;YACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAC;gBACvB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;aACpB;QACL,CAAC;QAED,OAAO,CAAC,KAAQ,EAAE,KAAQ;YACtB,OAAO,CAAC,CAAC;QACb,CAAC;QAEM,OAAO;YACV,OAAO,IAAI,CAAC,KAAK,IAAI,CAAC,CAAA;QAC1B,CAAC;QAEO,QAAQ,CAAC,MAAc,EAAE,MAAc;YAC3C,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAC5B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CA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
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HeapNode = void 0;
|
|
13
|
+
class HeapNode {
|
|
14
|
+
constructor(data) {
|
|
15
|
+
this.data = data;
|
|
16
|
+
}
|
|
17
|
+
getData() {
|
|
18
|
+
return this.data;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.HeapNode = HeapNode;
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=HeapNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeapNode.js","sourceRoot":"","sources":["../../source/heap/HeapNode.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,MAAa,QAAQ;QAIjB,YAAY,IAAO;YACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QACpB,CAAC;QAEM,OAAO;YACV,OAAO,IAAI,CAAC,IAAI,CAAA;QACpB,CAAC;KAEJ;IAZD,4BAYC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./Heap"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MaxHeap = void 0;
|
|
13
|
+
const Heap_1 = require("./Heap");
|
|
14
|
+
class MaxHeap extends Heap_1.Heap {
|
|
15
|
+
constructor(N, comparator) {
|
|
16
|
+
super(N, comparator);
|
|
17
|
+
}
|
|
18
|
+
compare(data1, data2) {
|
|
19
|
+
return this.comparator(data1, data2);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.MaxHeap = MaxHeap;
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=MaxHeap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaxHeap.js","sourceRoot":"","sources":["../../source/heap/MaxHeap.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,iCAA4B;IAG5B,MAAa,OAAW,SAAQ,WAAO;QAEnC,YAAY,CAAS,EAAE,UAA6C;YAChE,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;QACxB,CAAC;QAED,OAAO,CAAC,KAAQ,EAAE,KAAQ;YACtB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACxC,CAAC;KAEJ;IAVD,0BAUC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./Heap"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MinHeap = void 0;
|
|
13
|
+
const Heap_1 = require("./Heap");
|
|
14
|
+
class MinHeap extends Heap_1.Heap {
|
|
15
|
+
constructor(N, comparator) {
|
|
16
|
+
super(N, comparator);
|
|
17
|
+
}
|
|
18
|
+
compare(data1, data2) {
|
|
19
|
+
return -this.comparator(data1, data2);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.MinHeap = MinHeap;
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=MinHeap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MinHeap.js","sourceRoot":"","sources":["../../source/heap/MinHeap.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,iCAA4B;IAE5B,MAAa,OAAW,SAAQ,WAAO;QAEnC,YAAY,CAAS,EAAE,UAA6C;YAChE,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;QACxB,CAAC;QAED,OAAO,CAAC,KAAQ,EAAE,KAAQ;YACtB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACzC,CAAC;KAEJ;IAVD,0BAUC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {HeapNode} from "./HeapNode";
|
|
2
|
+
|
|
3
|
+
export class Heap<T> {
|
|
4
|
+
|
|
5
|
+
private readonly array: Array<HeapNode<T>>
|
|
6
|
+
protected comparator : <T>(item1: T, item2: T) => number
|
|
7
|
+
private count: number
|
|
8
|
+
|
|
9
|
+
constructor(N: number, comparator: <T>(item1: T, item2: T) => number){
|
|
10
|
+
this.comparator = comparator
|
|
11
|
+
this.array = new Array<HeapNode<T>>()
|
|
12
|
+
this.count = 0
|
|
13
|
+
for (let i = 0; i < N; i++){
|
|
14
|
+
this.array.push()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
compare(data1: T, data2: T): number{
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public isEmpty(): boolean{
|
|
23
|
+
return this.count == 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private swapNode(index1: number, index2: number){
|
|
27
|
+
let tmp = this.array[index1]
|
|
28
|
+
this.array[index1] = this.array[index2]
|
|
29
|
+
this.array[index2] = tmp
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected percolateDown(no: number) {
|
|
33
|
+
let left = 2 * no + 1
|
|
34
|
+
let right = 2 * no + 2
|
|
35
|
+
while ((left < this.count && this.compare(this.array[no].getData(), this.array[left].getData()) < 0) ||
|
|
36
|
+
(right < this.count && this.compare(this.array[no].getData(), this.array[right].getData()) < 0)) {
|
|
37
|
+
if (right >= this.count || this.compare(this.array[left].getData(), this.array[right].getData()) > 0) {
|
|
38
|
+
this.swapNode(no, left)
|
|
39
|
+
no = left
|
|
40
|
+
} else {
|
|
41
|
+
this.swapNode(no, right)
|
|
42
|
+
no = right
|
|
43
|
+
}
|
|
44
|
+
left = 2 * no + 1
|
|
45
|
+
right = 2 * no + 2
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected percolateUp(no: number){
|
|
50
|
+
let parent = Math.floor((no - 1) / 2)
|
|
51
|
+
while (parent >= 0 && this.compare(this.array[parent].getData(), this.array[no].getData()) < 0){
|
|
52
|
+
this.swapNode(parent, no)
|
|
53
|
+
no = parent
|
|
54
|
+
parent = Math.floor((no - 1) / 2)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public delete(): T{
|
|
59
|
+
let tmp = this.array[0]
|
|
60
|
+
this.array[0] = this.array[this.count - 1]
|
|
61
|
+
this.percolateDown(0)
|
|
62
|
+
this.count = this.count - 1
|
|
63
|
+
return tmp.getData()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public insert(data: T){
|
|
67
|
+
this.count = this.count + 1
|
|
68
|
+
this.array[this.count - 1] = new HeapNode<T>(data)
|
|
69
|
+
this.percolateUp(this.count - 1)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {Heap} from "./Heap";
|
|
2
|
+
import {HeapNode} from "./HeapNode";
|
|
3
|
+
|
|
4
|
+
export class MaxHeap<T> extends Heap<T>{
|
|
5
|
+
|
|
6
|
+
constructor(N: number, comparator: <T>(item1: T, item2: T) => number){
|
|
7
|
+
super(N, comparator)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
compare(data1: T, data2: T): number {
|
|
11
|
+
return this.comparator(data1, data2)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {Heap} from "./Heap";
|
|
2
|
+
|
|
3
|
+
export class MinHeap<T> extends Heap<T>{
|
|
4
|
+
|
|
5
|
+
constructor(N: number, comparator: <T>(item1: T, item2: T) => number){
|
|
6
|
+
super(N, comparator)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
compare(data1: T, data2: T): number {
|
|
10
|
+
return -this.comparator(data1, data2)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {MaxHeap} from "../dist/heap/MaxHeap";
|
|
2
|
+
import * as assert from "assert";
|
|
3
|
+
import {MinHeap} from "../dist/heap/MinHeap";
|
|
4
|
+
|
|
5
|
+
describe('HeapTest', function() {
|
|
6
|
+
describe('HeapTest', function() {
|
|
7
|
+
function compare<T>(item1: T, item2: T): number {
|
|
8
|
+
if (typeof item1 == "number" && typeof item2 == "number"){
|
|
9
|
+
return item1 - item2
|
|
10
|
+
}
|
|
11
|
+
return 0
|
|
12
|
+
}
|
|
13
|
+
it('testMaxHeap', function() {
|
|
14
|
+
let maxHeap : MaxHeap<number> = new MaxHeap<number>(8, compare)
|
|
15
|
+
maxHeap.insert(4)
|
|
16
|
+
maxHeap.insert(6)
|
|
17
|
+
maxHeap.insert(2)
|
|
18
|
+
maxHeap.insert(5)
|
|
19
|
+
maxHeap.insert(3)
|
|
20
|
+
maxHeap.insert(1)
|
|
21
|
+
maxHeap.insert(7)
|
|
22
|
+
assert.equal(7, maxHeap.delete())
|
|
23
|
+
assert.equal(6, maxHeap.delete())
|
|
24
|
+
assert.equal(5, maxHeap.delete())
|
|
25
|
+
});
|
|
26
|
+
it('testMinHeap', function() {
|
|
27
|
+
let minHeap : MinHeap<number> = new MinHeap<number>(8, compare)
|
|
28
|
+
minHeap.insert(4)
|
|
29
|
+
minHeap.insert(6)
|
|
30
|
+
minHeap.insert(2)
|
|
31
|
+
minHeap.insert(5)
|
|
32
|
+
minHeap.insert(3)
|
|
33
|
+
minHeap.insert(1)
|
|
34
|
+
minHeap.insert(7)
|
|
35
|
+
assert.equal(1, minHeap.delete())
|
|
36
|
+
assert.equal(2, minHeap.delete())
|
|
37
|
+
assert.equal(3, minHeap.delete())
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|