data-structure-typed 1.12.21 → 1.15.0

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.
Files changed (42) hide show
  1. package/README.md +278 -179
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +46 -1
  3. package/dist/data-structures/binary-tree/binary-tree.js +67 -0
  4. package/dist/data-structures/binary-tree/segment-tree.d.ts +29 -0
  5. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  6. package/dist/data-structures/graph/abstract-graph.d.ts +40 -5
  7. package/dist/data-structures/graph/abstract-graph.js +47 -7
  8. package/dist/data-structures/graph/directed-graph.d.ts +8 -0
  9. package/dist/data-structures/graph/directed-graph.js +14 -2
  10. package/dist/data-structures/graph/undirected-graph.d.ts +10 -0
  11. package/dist/data-structures/graph/undirected-graph.js +23 -1
  12. package/dist/data-structures/hash/coordinate-map.d.ts +7 -1
  13. package/dist/data-structures/hash/coordinate-map.js +16 -0
  14. package/dist/data-structures/hash/coordinate-set.d.ts +7 -1
  15. package/dist/data-structures/hash/coordinate-set.js +16 -0
  16. package/dist/data-structures/heap/heap.d.ts +16 -0
  17. package/dist/data-structures/heap/heap.js +38 -0
  18. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +30 -7
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +71 -4
  20. package/dist/data-structures/linked-list/singly-linked-list.d.ts +262 -328
  21. package/dist/data-structures/linked-list/singly-linked-list.js +258 -273
  22. package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -1
  23. package/dist/data-structures/priority-queue/priority-queue.js +18 -2
  24. package/dist/data-structures/queue/deque.d.ts +18 -7
  25. package/dist/data-structures/queue/deque.js +50 -3
  26. package/dist/data-structures/types/abstract-graph.d.ts +2 -2
  27. package/package.json +2 -2
  28. package/src/data-structures/binary-tree/aa-tree.ts +1 -1
  29. package/src/data-structures/binary-tree/binary-tree.ts +84 -14
  30. package/src/data-structures/binary-tree/segment-tree.ts +45 -13
  31. package/src/data-structures/graph/abstract-graph.ts +58 -15
  32. package/src/data-structures/graph/directed-graph.ts +14 -5
  33. package/src/data-structures/graph/undirected-graph.ts +23 -6
  34. package/src/data-structures/hash/coordinate-map.ts +13 -1
  35. package/src/data-structures/hash/coordinate-set.ts +13 -1
  36. package/src/data-structures/heap/heap.ts +31 -0
  37. package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
  38. package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
  39. package/src/data-structures/priority-queue/priority-queue.ts +15 -2
  40. package/src/data-structures/queue/deque.ts +38 -8
  41. package/src/data-structures/types/abstract-graph.ts +3 -3
  42. package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
@@ -40,17 +40,26 @@ export class DirectedEdge extends AbstractEdge {
40
40
  get src(): VertexId {
41
41
  return this._src;
42
42
  }
43
-
43
+ /**
44
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
45
+ */
46
+ getSrc(): VertexId {
47
+ return this._src;
48
+ }
44
49
  set src(v: VertexId) {
45
50
  this._src = v;
46
51
  }
47
52
 
48
-
49
53
  private _dest: VertexId;
50
54
  get dest(): VertexId {
51
55
  return this._dest;
52
56
  }
53
-
57
+ /**
58
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
59
+ */
60
+ getDest(): VertexId {
61
+ return this._dest;
62
+ }
54
63
  set dest(v: VertexId) {
55
64
  this._dest = v;
56
65
  }
@@ -101,7 +110,7 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
101
110
  * graph, and `false` if either the source or destination vertices of the edge are not present in the graph.
102
111
  */
103
112
  addEdge(edge: E): boolean {
104
- if (!(this.containsVertex(edge.src) && this.containsVertex(edge.dest))) {
113
+ if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
105
114
  return false;
106
115
  }
107
116
 
@@ -401,7 +410,7 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
401
410
  * returns null.
402
411
  */
403
412
  getEndsOfEdge(edge: E): [V, V] | null {
404
- if (!this.containsEdge(edge.src, edge.dest)) {
413
+ if (!this.hasEdge(edge.src, edge.dest)) {
405
414
  return null;
406
415
  }
407
416
  const v1 = this.getVertex(edge.src);
@@ -35,21 +35,38 @@ export class UndirectedEdge extends AbstractEdge {
35
35
  }
36
36
 
37
37
  private _vertices: [VertexId, VertexId];
38
-
39
- public get vertices() {
38
+ get vertices() {
40
39
  return this._vertices;
41
40
  }
42
-
43
- public set vertices(v: [VertexId, VertexId]) {
41
+ /**
42
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
43
+ */
44
+ getVertices() {
45
+ return this._vertices;
46
+ }
47
+ set vertices(v: [VertexId, VertexId]) {
44
48
  this._vertices = v;
45
49
  }
46
50
  }
47
51
 
48
52
  export class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
49
- protected _edges: Map<V, E[]> = new Map();
53
+ protected _edges: Map<V, E[]>;
54
+ get edges(): Map<V, E[]> {
55
+ return this._edges;
56
+ }
57
+ /**
58
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
59
+ */
60
+ getEdges(): Map<V, E[]> {
61
+ return this._edges;
62
+ }
63
+ protected set edges(v: Map<V, E[]>) {
64
+ this._edges = v;
65
+ }
50
66
 
51
67
  constructor() {
52
68
  super();
69
+ this._edges = new Map<V, E[]>();
53
70
  }
54
71
 
55
72
  /**
@@ -223,7 +240,7 @@ export class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdg
223
240
  * `null`.
224
241
  */
225
242
  getEndsOfEdge(edge: E): [V, V] | null {
226
- if (!this.containsEdge(edge.vertices[0], edge.vertices[1])) {
243
+ if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
227
244
  return null;
228
245
  }
229
246
  const v1 = this.getVertex(edge.vertices[0]);
@@ -6,7 +6,19 @@
6
6
  * @license MIT License
7
7
  */
8
8
  export class CoordinateMap<V> extends Map<any, V> {
9
- private readonly _joint: string = '_';
9
+ protected _joint: string = '_';
10
+ get joint(): string {
11
+ return this._joint;
12
+ }
13
+ /**
14
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
15
+ */
16
+ getJoint(): string {
17
+ return this._joint;
18
+ }
19
+ protected set joint(v: string) {
20
+ this._joint = v;
21
+ }
10
22
 
11
23
  constructor(joint?: string) {
12
24
  super();
@@ -6,7 +6,19 @@
6
6
  * @license MIT License
7
7
  */
8
8
  export class CoordinateSet extends Set {
9
- private readonly _joint: string = '_';
9
+ protected _joint: string = '_';
10
+ get joint(): string {
11
+ return this._joint;
12
+ }
13
+ /**
14
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
15
+ */
16
+ getJoint(): string {
17
+ return this._joint;
18
+ }
19
+ protected set joint(v: string) {
20
+ this._joint = v;
21
+ }
10
22
 
11
23
  constructor(joint?: string) {
12
24
  super();
@@ -10,7 +10,32 @@ import type {HeapItem, HeapOptions} from '../types';
10
10
 
11
11
  export abstract class Heap<T> {
12
12
  protected abstract _pq: PriorityQueue<HeapItem<T>>;
13
+ get pq() {
14
+ return this._pq;
15
+ }
16
+ /**
17
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
18
+ */
19
+ getPq() {
20
+ return this._pq;
21
+ }
22
+ protected set pq(v: PriorityQueue<HeapItem<T>>) {
23
+ this._pq = v;
24
+ }
25
+
13
26
  protected _priorityCb: (element: T) => number;
27
+ get priorityCb() {
28
+ return this._priorityCb;
29
+ }
30
+ /**
31
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
32
+ */
33
+ getPriorityCb() {
34
+ return this._priorityCb;
35
+ }
36
+ protected set priorityCb(v: (element: T) => number) {
37
+ this._priorityCb = v;
38
+ }
14
39
 
15
40
  /**
16
41
  * The function is a constructor for a class that initializes a priority callback function based on the
@@ -36,6 +61,12 @@ export abstract class Heap<T> {
36
61
  get size(): number {
37
62
  return this._pq.size;
38
63
  }
64
+ /**
65
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
66
+ */
67
+ getSize(): number {
68
+ return this._pq.size;
69
+ }
39
70
 
40
71
  /**
41
72
  * The function checks if a priority queue is empty.
@@ -8,29 +8,86 @@
8
8
  import type {DoublyLinkedListGetBy} from '../types';
9
9
 
10
10
  export class DoublyLinkedListNode<T> {
11
- val: T;
12
- next: DoublyLinkedListNode<T> | null;
13
- prev: DoublyLinkedListNode<T> | null;
11
+ protected _val: T;
12
+ get val(): T {
13
+ return this._val;
14
+ }
15
+ set val(v: T) {
16
+ this._val = v;
17
+ }
18
+
19
+ protected _next: DoublyLinkedListNode<T> | null;
20
+ get next(): DoublyLinkedListNode<T> | null {
21
+ return this._next;
22
+ }
23
+ set next(v: DoublyLinkedListNode<T> | null) {
24
+ this._next = v;
25
+ }
26
+
27
+ protected _prev: DoublyLinkedListNode<T> | null;
28
+ get prev(): DoublyLinkedListNode<T> | null {
29
+ return this._prev;
30
+ }
31
+ set prev(v: DoublyLinkedListNode<T> | null) {
32
+ this._prev = v;
33
+ }
14
34
 
15
35
  constructor(nodeValue: T) {
16
- this.val = nodeValue;
17
- this.next = null;
18
- this.prev = null;
36
+ this._val = nodeValue;
37
+ this._next = null;
38
+ this._prev = null;
19
39
  }
20
40
  }
21
41
 
22
42
  export class DoublyLinkedList<T> {
23
- private _first: DoublyLinkedListNode<T> | null = null;
24
- private _last: DoublyLinkedListNode<T> | null = null;
25
- private _size = 0;
43
+ protected _first: DoublyLinkedListNode<T> | null;
44
+ get first(): DoublyLinkedListNode<T> | null {
45
+ return this._first;
46
+ }
47
+ /**
48
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
49
+ */
50
+ getFirst(): DoublyLinkedListNode<T> | null {
51
+ return this._first;
52
+ }
53
+ protected set first(v: DoublyLinkedListNode<T> | null) {
54
+ this._first = v;
55
+ }
56
+
57
+ protected _last: DoublyLinkedListNode<T> | null;
58
+ get last(): DoublyLinkedListNode<T> | null {
59
+ return this._last;
60
+ }
61
+ /**
62
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
63
+ */
64
+ getLast(): DoublyLinkedListNode<T> | null {
65
+ return this._last;
66
+ }
67
+ protected set last(v: DoublyLinkedListNode<T> | null) {
68
+ this._last = v;
69
+ }
70
+
71
+ protected _size: number;
26
72
  get size(): number {
27
73
  return this._size;
28
74
  }
29
-
30
- set size(v: number) {
75
+ /**
76
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
77
+ */
78
+ getSize(): number {
79
+ return this._size;
80
+ }
81
+ protected set size(v: number) {
31
82
  this._size = v;
32
83
  }
33
84
 
85
+ constructor() {
86
+ this._first = null;
87
+ this._last = null;
88
+ this._size = 0;
89
+ }
90
+
34
91
  /**
35
92
  * The function adds a new node with a given value to the beginning of a doubly linked list.
36
93
  * @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of