nlptoolkit-datastructure 1.0.7 → 1.0.8

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/README.md CHANGED
@@ -7,7 +7,7 @@ For Developers
7
7
  ============
8
8
 
9
9
  You can also see [Java](https://github.com/starlangsoftware/DataStructure), [Python](https://github.com/starlangsoftware/DataStructure-Py),
10
- [Cython](https://github.com/starlangsoftware/DataStructure-Cy), [Swift](https://github.com/starlangsoftware/DataStructure-Swift), [C](https://github.com/starlangsoftware/DataStructure-C),
10
+ [Cython](https://github.com/starlangsoftware/DataStructure-Cy), [Swift](https://github.com/starlangsoftware/DataStructure-Swift), [Php](https://github.com/starlangsoftware/DataStructure-Php), [C](https://github.com/starlangsoftware/DataStructure-C),
11
11
  [C#](https://github.com/starlangsoftware/DataStructure-CS), or [C++](https://github.com/starlangsoftware/DataStructure-CPP) repository.
12
12
 
13
13
  ## Requirements
package/dist/Queue.d.ts CHANGED
@@ -3,10 +3,34 @@ export declare class Queue<T> {
3
3
  private head;
4
4
  private tail;
5
5
  private maxSize;
6
+ /**
7
+ * Constructor of the queue data structure
8
+ * @param maxSize Maximum size of the queue
9
+ */
6
10
  constructor(maxSize: number);
11
+ /**
12
+ * Adds a set of elements to the end of the queue
13
+ * @param items Elements to be inserted into the queue
14
+ */
7
15
  enqueueAll(items: Array<T>): void;
16
+ /**
17
+ * Adds an element to the end of the queue.
18
+ * @param item Element added to the queue.
19
+ */
8
20
  enqueue(item: T): void;
21
+ /**
22
+ * Removes an element from the start of the queue.
23
+ * @return Removed item
24
+ */
9
25
  dequeue(): T;
26
+ /**
27
+ * Returns head of the queue.
28
+ * @return Head of the queue
29
+ */
10
30
  peek(): T;
31
+ /**
32
+ * Checks if the queue is empty or not.
33
+ * @return Returns true if the queue is empty, false otherwise.
34
+ */
11
35
  isEmpty(): boolean;
12
36
  }
package/dist/Queue.js CHANGED
@@ -11,6 +11,10 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Queue = void 0;
13
13
  class Queue {
14
+ /**
15
+ * Constructor of the queue data structure
16
+ * @param maxSize Maximum size of the queue
17
+ */
14
18
  constructor(maxSize) {
15
19
  this.list = [];
16
20
  this.head = 0;
@@ -18,23 +22,43 @@
18
22
  this.maxSize = maxSize;
19
23
  this.list = new Array(maxSize);
20
24
  }
25
+ /**
26
+ * Adds a set of elements to the end of the queue
27
+ * @param items Elements to be inserted into the queue
28
+ */
21
29
  enqueueAll(items) {
22
30
  for (let item of items) {
23
31
  this.enqueue(item);
24
32
  }
25
33
  }
34
+ /**
35
+ * Adds an element to the end of the queue.
36
+ * @param item Element added to the queue.
37
+ */
26
38
  enqueue(item) {
27
39
  this.list[this.tail] = item;
28
40
  this.tail = (this.tail + 1) % this.maxSize;
29
41
  }
42
+ /**
43
+ * Removes an element from the start of the queue.
44
+ * @return Removed item
45
+ */
30
46
  dequeue() {
31
47
  let item = this.list[this.head];
32
48
  this.head = (this.head + 1) % this.maxSize;
33
49
  return item;
34
50
  }
51
+ /**
52
+ * Returns head of the queue.
53
+ * @return Head of the queue
54
+ */
35
55
  peek() {
36
56
  return this.list[this.head];
37
57
  }
58
+ /**
59
+ * Checks if the queue is empty or not.
60
+ * @return Returns true if the queue is empty, false otherwise.
61
+ */
38
62
  isEmpty() {
39
63
  return this.head == this.tail;
40
64
  }
package/dist/Queue.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Queue.js","sourceRoot":"","sources":["../source/Queue.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,MAAa,KAAK;QAOd,YAAY,OAAe;YALnB,SAAI,GAAc,EAAE,CAAA;YAMxB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;YACb,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;YACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;YACtB,IAAI,CAAC,IAAI,GAAG,IAAI,KAAK,CAAI,OAAO,CAAC,CAAA;QACrC,CAAC;QAE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AAO,CAAC,IAAI,CAAC,CAAA;aACrB;QACL,CAAC;QAED;;;WAGG;QACI,OAAO,CAAC,IAAO;YAClB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YAC3B,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;QAC9C,CAAC;QAED;;;WAGG;QACI,OAAO;YACV,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC/B,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;YAC1C,OAAO,IAAI,CAAA;QACf,CAAC;QAED;;;WAGG;QACI,IAAI;YACP,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC/B,CAAC;QAED;;;WAGG;QACI,OAAO;YACV,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;QACjC,CAAC;KAEJ;IA/DD,sBA+DC"}
package/dist/Stack.d.ts CHANGED
@@ -1,7 +1,30 @@
1
+ /**
2
+ * Stack is a list data structure consisting of many elements. There are two types of operations defined for the
3
+ * elements of the stack: Adding an element to the stack (push) and removing an element from the stack (pop). In a
4
+ * stack, to be popped element is always the last pushed element. Also, when an element is pushed on to the stack, it
5
+ * is placed on top of the stack (at the end of the list).
6
+ * @param T Type of the data stored in the stack node.
7
+ */
1
8
  export declare class Stack<T> {
2
9
  private list;
3
10
  constructor();
11
+ /**
12
+ * When we push an element on top of the stack, we only need to increase the field top by 1 and place the new
13
+ * element on this new position. If the stack is full before this push operation, we can not push.
14
+ * @param item Item to insert.
15
+ */
4
16
  push(item: T): void;
17
+ /**
18
+ * When we remove an element from the stack (the function also returns that removed element), we need to be careful
19
+ * if the stack was empty or not. If the stack is not empty, the topmost element of the stack is returned and the
20
+ * field top is decreased by 1. If the stack is empty, the function will return null.
21
+ * @return The removed element
22
+ */
5
23
  pop(): T | null;
24
+ /**
25
+ * The function checks whether an array-implemented stack is empty or not. The function returns true if the stack is
26
+ * empty, false otherwise.
27
+ * @return True if the stack is empty, false otherwise.
28
+ */
6
29
  isEmpty(): boolean;
7
30
  }
package/dist/Stack.js CHANGED
@@ -10,13 +10,31 @@
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Stack = void 0;
13
+ /**
14
+ * Stack is a list data structure consisting of many elements. There are two types of operations defined for the
15
+ * elements of the stack: Adding an element to the stack (push) and removing an element from the stack (pop). In a
16
+ * stack, to be popped element is always the last pushed element. Also, when an element is pushed on to the stack, it
17
+ * is placed on top of the stack (at the end of the list).
18
+ * @param T Type of the data stored in the stack node.
19
+ */
13
20
  class Stack {
14
21
  constructor() {
15
22
  this.list = [];
16
23
  }
24
+ /**
25
+ * When we push an element on top of the stack, we only need to increase the field top by 1 and place the new
26
+ * element on this new position. If the stack is full before this push operation, we can not push.
27
+ * @param item Item to insert.
28
+ */
17
29
  push(item) {
18
30
  this.list.push(item);
19
31
  }
32
+ /**
33
+ * When we remove an element from the stack (the function also returns that removed element), we need to be careful
34
+ * if the stack was empty or not. If the stack is not empty, the topmost element of the stack is returned and the
35
+ * field top is decreased by 1. If the stack is empty, the function will return null.
36
+ * @return The removed element
37
+ */
20
38
  pop() {
21
39
  let item = this.list.pop();
22
40
  if (item == undefined) {
@@ -26,6 +44,11 @@
26
44
  return item;
27
45
  }
28
46
  }
47
+ /**
48
+ * The function checks whether an array-implemented stack is empty or not. The function returns true if the stack is
49
+ * empty, false otherwise.
50
+ * @return True if the stack is empty, false otherwise.
51
+ */
29
52
  isEmpty() {
30
53
  return this.list.length == 0;
31
54
  }
package/dist/Stack.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Stack.js","sourceRoot":"","sources":["../source/Stack.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,MAAa,KAAK;QAId;YAFQ,SAAI,GAAc,EAAE,CAAA;QAG5B,CAAC;QAEM,IAAI,CAAC,IAAO;YACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QAEM,GAAG;YACN,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;YAC1B,IAAI,IAAI,IAAI,SAAS,EAAC;gBAClB,OAAO,IAAI,CAAA;aACd;iBAAM;gBACH,OAAO,IAAI,CAAA;aACd;QACL,CAAC;QAEM,OAAO;YACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAA;QAChC,CAAC;KAGJ;IAzBD,sBAyBC"}
1
+ {"version":3,"file":"Stack.js","sourceRoot":"","sources":["../source/Stack.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA;;;;;;OAMG;IACH,MAAa,KAAK;QAId;YAFQ,SAAI,GAAc,EAAE,CAAA;QAG5B,CAAC;QAED;;;;WAIG;QACI,IAAI,CAAC,IAAO;YACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QAED;;;;;WAKG;QACI,GAAG;YACN,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;YAC1B,IAAI,IAAI,IAAI,SAAS,EAAC;gBAClB,OAAO,IAAI,CAAA;aACd;iBAAM;gBACH,OAAO,IAAI,CAAA;aACd;QACL,CAAC;QAED;;;;WAIG;QACI,OAAO;YACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAA;QAChC,CAAC;KAGJ;IAzCD,sBAyCC"}
@@ -1,14 +1,67 @@
1
+ /**
2
+ * <p>The heap data structure is a binary tree structure consisting of N elements. It shows the basic properties of the
3
+ * binary tree data structure. The heap has a root node and each node of it has at most two child nodes
4
+ * (left and right). The root node of the tree is shown at the top, and its branches grow not to up but to down manner.
5
+ * </p>
6
+ *
7
+ * <p>In a heap, if the maximum element is in the root node and all nodes are smaller than its descendants, then this heap
8
+ * is called max-heap, if the minimum element is in the root node and all nodes are larger than its descendants, then
9
+ * this heap is called min-heap.</p>
10
+ * @param T Type of the data stored in the heap node.
11
+ */
1
12
  export declare class Heap<T> {
2
13
  private readonly array;
3
14
  protected comparator: (item1: T, item2: T) => number;
4
15
  private count;
5
16
  private n;
17
+ /**
18
+ * Constructor of the heap. According to the comparator, the heap could be min or max heap.
19
+ * @param N Maximum number of elements in the heap.
20
+ * @param comparator Comparator function to compare two elements.
21
+ */
6
22
  constructor(N: number, comparator: (item1: T, item2: T) => number);
7
23
  compare(data1: T, data2: T): number;
24
+ /**
25
+ * Checks if the heap is empty or not.
26
+ * @return True if the heap is empty, false otherwise.
27
+ */
8
28
  isEmpty(): boolean;
29
+ /**
30
+ * Swaps two heap nodes in the heap given their indexes.
31
+ * @param index1 Index of the first node to swap.
32
+ * @param index2 Index of the second node to swap.
33
+ */
9
34
  private swapNode;
35
+ /**
36
+ * The function percolates down from a node of the tree to restore the max-heap property. Left or right children are
37
+ * checked, if one of them is larger than the current element of the heap, the iteration continues. The iteration is,
38
+ * determining the largest one of the node's children and switching that node's value with the current node's value.
39
+ * We need to check if current node's left and right children exist or not. These checks are done with for the left
40
+ * child and with for the right child.
41
+ * @param no Index of the starting node to restore the max-heap property.
42
+ */
10
43
  protected percolateDown(no: number): void;
44
+ /**
45
+ * The function percolates up from a node of the tree to restore the max-heap property. As long as the max-heap
46
+ * property is corrupted, the parent and its child switch their values. We need to pay attention that, the
47
+ * calculated index of the parent must be a valid number. In other words, while going upper levels,we need to see
48
+ * that we can not go up if we are at the root of the tree.
49
+ * @param no Index of the starting node to restore the max-heap property.
50
+ */
11
51
  protected percolateUp(no: number): void;
52
+ /**
53
+ * The function will return the first element, therefore the first element is stored in the variable, and the first
54
+ * element of the heap is set to the last element of the heap. After that, in order to restore the max-heap
55
+ * property, we percolate down the tree using the function. As a last step, the number of element in the heap is
56
+ * decremented by one.
57
+ * @return The first element
58
+ */
12
59
  delete(): T;
60
+ /**
61
+ * The insertion of a new element to the heap, proceeds from the leaf nodes to the root node. First the new element
62
+ * is added to the end of the heap, then as long as the max-heap property is corrupted, the new element switches
63
+ * place with its parent.
64
+ * @param data New element to be inserted.
65
+ */
13
66
  insert(data: T): void;
14
67
  }
package/dist/heap/Heap.js CHANGED
@@ -11,7 +11,23 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Heap = void 0;
13
13
  const HeapNode_1 = require("./HeapNode");
14
+ /**
15
+ * <p>The heap data structure is a binary tree structure consisting of N elements. It shows the basic properties of the
16
+ * binary tree data structure. The heap has a root node and each node of it has at most two child nodes
17
+ * (left and right). The root node of the tree is shown at the top, and its branches grow not to up but to down manner.
18
+ * </p>
19
+ *
20
+ * <p>In a heap, if the maximum element is in the root node and all nodes are smaller than its descendants, then this heap
21
+ * is called max-heap, if the minimum element is in the root node and all nodes are larger than its descendants, then
22
+ * this heap is called min-heap.</p>
23
+ * @param T Type of the data stored in the heap node.
24
+ */
14
25
  class Heap {
26
+ /**
27
+ * Constructor of the heap. According to the comparator, the heap could be min or max heap.
28
+ * @param N Maximum number of elements in the heap.
29
+ * @param comparator Comparator function to compare two elements.
30
+ */
15
31
  constructor(N, comparator) {
16
32
  this.comparator = comparator;
17
33
  this.array = new Array();
@@ -24,14 +40,31 @@
24
40
  compare(data1, data2) {
25
41
  return 0;
26
42
  }
43
+ /**
44
+ * Checks if the heap is empty or not.
45
+ * @return True if the heap is empty, false otherwise.
46
+ */
27
47
  isEmpty() {
28
48
  return this.count == 0;
29
49
  }
50
+ /**
51
+ * Swaps two heap nodes in the heap given their indexes.
52
+ * @param index1 Index of the first node to swap.
53
+ * @param index2 Index of the second node to swap.
54
+ */
30
55
  swapNode(index1, index2) {
31
56
  let tmp = this.array[index1];
32
57
  this.array[index1] = this.array[index2];
33
58
  this.array[index2] = tmp;
34
59
  }
60
+ /**
61
+ * The function percolates down from a node of the tree to restore the max-heap property. Left or right children are
62
+ * checked, if one of them is larger than the current element of the heap, the iteration continues. The iteration is,
63
+ * determining the largest one of the node's children and switching that node's value with the current node's value.
64
+ * We need to check if current node's left and right children exist or not. These checks are done with for the left
65
+ * child and with for the right child.
66
+ * @param no Index of the starting node to restore the max-heap property.
67
+ */
35
68
  percolateDown(no) {
36
69
  let left = 2 * no + 1;
37
70
  let right = 2 * no + 2;
@@ -49,6 +82,13 @@
49
82
  right = 2 * no + 2;
50
83
  }
51
84
  }
85
+ /**
86
+ * The function percolates up from a node of the tree to restore the max-heap property. As long as the max-heap
87
+ * property is corrupted, the parent and its child switch their values. We need to pay attention that, the
88
+ * calculated index of the parent must be a valid number. In other words, while going upper levels,we need to see
89
+ * that we can not go up if we are at the root of the tree.
90
+ * @param no Index of the starting node to restore the max-heap property.
91
+ */
52
92
  percolateUp(no) {
53
93
  let parent = Math.floor((no - 1) / 2);
54
94
  while (parent >= 0 && this.compare(this.array[parent].getData(), this.array[no].getData()) < 0) {
@@ -57,6 +97,13 @@
57
97
  parent = Math.floor((no - 1) / 2);
58
98
  }
59
99
  }
100
+ /**
101
+ * The function will return the first element, therefore the first element is stored in the variable, and the first
102
+ * element of the heap is set to the last element of the heap. After that, in order to restore the max-heap
103
+ * property, we percolate down the tree using the function. As a last step, the number of element in the heap is
104
+ * decremented by one.
105
+ * @return The first element
106
+ */
60
107
  delete() {
61
108
  let tmp = this.array[0];
62
109
  this.array[0] = this.array[this.count - 1];
@@ -64,6 +111,12 @@
64
111
  this.count = this.count - 1;
65
112
  return tmp.getData();
66
113
  }
114
+ /**
115
+ * The insertion of a new element to the heap, proceeds from the leaf nodes to the root node. First the new element
116
+ * is added to the end of the heap, then as long as the max-heap property is corrupted, the new element switches
117
+ * place with its parent.
118
+ * @param data New element to be inserted.
119
+ */
67
120
  insert(data) {
68
121
  if (this.count < this.n) {
69
122
  this.count = this.count + 1;
@@ -1 +1 @@
1
- {"version":3,"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AC,CAAC,CAAC,CAAA;YACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;YAC3B,OAAO,GAAG,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;QAED;;;;;WAKG;QACI,MAAM,CAAC,IAAO;YACjB,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,EAAE;gBACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;aAC9B;YACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,mBAAQ,CAAI,IAAI,CAAC,CAAA;YAClD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;QACpC,CAAC;KAEJ;IAnHD,oBAmHC"}
@@ -1,5 +1,13 @@
1
1
  export declare class HeapNode<T> {
2
2
  data: T;
3
+ /**
4
+ * Constructor of HeapNode.
5
+ * @param data Data to be stored in the heap node.
6
+ */
3
7
  constructor(data: T);
8
+ /**
9
+ * Mutator of the data field
10
+ * @return Data
11
+ */
4
12
  getData(): T;
5
13
  }
@@ -11,9 +11,17 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.HeapNode = void 0;
13
13
  class HeapNode {
14
+ /**
15
+ * Constructor of HeapNode.
16
+ * @param data Data to be stored in the heap node.
17
+ */
14
18
  constructor(data) {
15
19
  this.data = data;
16
20
  }
21
+ /**
22
+ * Mutator of the data field
23
+ * @return Data
24
+ */
17
25
  getData() {
18
26
  return this.data;
19
27
  }
@@ -1 +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"}
1
+ {"version":3,"file":"HeapNode.js","sourceRoot":"","sources":["../../source/heap/HeapNode.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,MAAa,QAAQ;QAIjB;;;WAGG;QACH,YAAY,IAAO;YACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QACpB,CAAC;QAED;;;WAGG;QACI,OAAO;YACV,OAAO,IAAI,CAAC,IAAI,CAAA;QACpB,CAAC;KAEJ;IApBD,4BAoBC"}
@@ -1 +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,UAA0C;YAC7D,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"}
1
+ {"version":3,"file":"MaxHeap.js","sourceRoot":"","sources":["../../source/heap/MaxHeap.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,iCAA4B;IAE5B,MAAa,OAAW,SAAQ,WAAO;QAEnC,YAAY,CAAS,EAAE,UAA0C;YAC7D,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,9 @@
1
+ export * from "./CounterHashMap";
2
+ export * from "./LRUCache";
3
+ export * from "./Stack";
4
+ export * from "./tree/BTree";
5
+ export * from "./tree/BTreeNode";
6
+ export * from "./tree/AvlTree";
7
+ export * from "./tree/AvlTreeNode";
8
+ export * from "./tree/Tree";
9
+ export * from "./tree/TreeNode";
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ }) : (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ o[k2] = m[k];
7
+ }));
8
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
9
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
10
+ };
11
+ (function (factory) {
12
+ if (typeof module === "object" && typeof module.exports === "object") {
13
+ var v = factory(require, exports);
14
+ if (v !== undefined) module.exports = v;
15
+ }
16
+ else if (typeof define === "function" && define.amd) {
17
+ define(["require", "exports", "./CounterHashMap", "./LRUCache", "./Stack", "./tree/BTree", "./tree/BTreeNode", "./tree/AvlTree", "./tree/AvlTreeNode", "./tree/Tree", "./tree/TreeNode"], factory);
18
+ }
19
+ })(function (require, exports) {
20
+ "use strict";
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ __exportStar(require("./CounterHashMap"), exports);
23
+ __exportStar(require("./LRUCache"), exports);
24
+ __exportStar(require("./Stack"), exports);
25
+ __exportStar(require("./tree/BTree"), exports);
26
+ __exportStar(require("./tree/BTreeNode"), exports);
27
+ __exportStar(require("./tree/AvlTree"), exports);
28
+ __exportStar(require("./tree/AvlTreeNode"), exports);
29
+ __exportStar(require("./tree/Tree"), exports);
30
+ __exportStar(require("./tree/TreeNode"), exports);
31
+ });
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;IAAA,mDAAgC;IAChC,6CAA0B;IAC1B,0CAAuB;IACvB,+CAA4B;IAC5B,mDAAgC;IAChC,iDAA8B;IAC9B,qDAAkC;IAClC,8CAA2B;IAC3B,kDAA+B"}
@@ -1,12 +1,93 @@
1
1
  import { Tree } from "./Tree";
2
2
  import { AvlTreeNode } from "./AvlTreeNode";
3
+ /**
4
+ * <p>AVL (Adelson-Velskii and Landis) tree is a balanced binary search tree structure. The balance property is very simple
5
+ * and ensures the depth of the tree is in the level of O(log N).</p>
6
+ *
7
+ * <p>In AVL tree, the heights of the left and right subtrees of each node can differ by at most 1. If the heights of the
8
+ * left and right subtrees of a single node differ by more than 1, then that binary search tree is not an AVL tree.</p>
9
+ * @param T Type of the data stored in the tree node.
10
+ */
3
11
  export declare class AvlTree<T> extends Tree<T> {
4
12
  constructor(comparator: <T>(item1: T, item2: T) => number);
5
13
  height(d: AvlTreeNode<T>): number;
14
+ /**
15
+ * In rotate left, we move node k1 one level up, since due to the binary search tree
16
+ * property k2 > k1, we move node k2 one level down. The links updated are:
17
+ * <ul>
18
+ * <li>Since k2 > B > k1, the left child of node k2 is now the old right child of k1</li>
19
+ * <li>The right child of k1 is now k2 </li>
20
+ * </ul>
21
+ * Note that, the root node of the subtree is now k1. In order to modify the parent link of k2, the new root of the
22
+ * subtree is returned by the function.
23
+ * @param k2 Root of the subtree, which does not satisfy the AVL tree property.
24
+ * @return The new root of the subtree
25
+ */
6
26
  private rotateLeft;
27
+ /**
28
+ * In order to restore the AVL tree property, we move node k2 one level up, since due to the binary search tree
29
+ * property k2 > k1, we move node k1 one level down. The links updated are:
30
+ * <ul>
31
+ * <li>Since k2 > B > k1, the right child of node k1 is now the old left child of k2.</li>
32
+ * <li>The left child of k2 is now k1</li>
33
+ * </ul>
34
+ * Note that, the root node of the subtree is now k2. In order to modify the parent link of k1, the new root of the
35
+ * subtree is returned by the function.
36
+ * @param k1 Root of the subtree, which does not satisfy the AVL tree property.
37
+ * @return The new root of the subtree
38
+ */
7
39
  private rotateRight;
40
+ /**
41
+ * <p>In the first phase we will do single right rotation on the subtree rooted with k1. With this rotation, the left
42
+ * child of node k2 will be k1, whereas the right child of node k1 will be B (the old left child of node k2).</p>
43
+ *
44
+ * <p>In the second phase, we will do single left rotation on the subtree rooted with k3. With this rotation, the
45
+ * right child of node k2 will be k3, whereas the left child of node k3 will be C (the old right child of k2).</p>
46
+ *
47
+ * Note that, the new root node of the subtree is now k2. In order to modify the parent link of k3, the new root of
48
+ * the subtree is returned by the function.
49
+ * @param k3 Root of the subtree, which does not satisfy the AVL tree property.
50
+ * @return The new root of the subtree
51
+ */
8
52
  private doubleRotateLeft;
53
+ /**
54
+ * <p>In the first phase we will do single right rotation on the subtree rooted with k3. With this rotation, the right
55
+ * child of node k2 will be k3, whereas the left child of node k3 will be C (the old right child of node k2).</p>
56
+ *
57
+ * <p>In the second phase, we will do single right rotation on the subtree rooted with k1. With this rotation, the left
58
+ * child of node k2 will be k1, whereas the left child of node k1 will be B (the old left child of k2).</p>
59
+ *
60
+ * Note that, the new root node of the subtree is now k2. In order to modify the parent link of k1, the new root of
61
+ * the subtree is returned by the function.
62
+ * @param k1 Root of the subtree, which does not satisfy the AVL tree property.
63
+ * @return The new root of the subtree
64
+ */
9
65
  private doubleRotateRight;
66
+ /**
67
+ * <p>First we will proceed with the stages the same when we add a new node into a binary search tree. For this, we
68
+ * start from the root node and traverse in down manner. The current node we visit is represented with x and the
69
+ * previous node is represented with y. At each time we compare the value of the current node with the value of the
70
+ * new node. If the value of the new node is smaller than the value of the current node, the new node will be
71
+ * inserted into the left subtree of the current node. For this, we will continue with the left child to process. If
72
+ * the reverse is true, that is, if the value of the new node is larger than the value of the current node, the new
73
+ * node will be inserted into the right subtree of the current node. In this case, we will continue with the right
74
+ * child to process. At each step, we store the current node in a separate stack.</p>
75
+ *
76
+ * <p>When we insert a new node into an AVL tree, we need to change the heights of the nodes and check if the AVL tree
77
+ * property is satisfied or not. Only the height of the nodes, which we visit while we are finding the place for the
78
+ * new node, can be changed. So, what we should do is to pop those nodes from the stack one by one and change the
79
+ * heights of those nodes.</p>
80
+ *
81
+ * <p>Similarly, the nodes, which we visit while we are finding the place for the new node, may no longer satisfy the
82
+ * AVL tree property. So what we should do is to pop those nodes from the stack one by one and calculate the
83
+ * difference of the heights of their left and right subtrees. If the height difference is 2, the AVL tree property
84
+ * is not satisfied. If we added the new node into the left subtree of the left child, we need to do left single
85
+ * rotation, if we added into the right subtree of the left child, we need to do left double rotation, if we added
86
+ * into the left subtree of the right child, we need to do right double rotation, if we added into the right subtree
87
+ * of the right child, we need to the right single rotation. Since the root node of the subtree will be changed
88
+ * after a rotation, the new child of y will be the new root node t.</p>
89
+ * @param node Node to be inserted.
90
+ */
10
91
  insert(node: AvlTreeNode<T>): void;
11
92
  insertData(item: T): void;
12
93
  }