min-heap-typed 1.40.0-rc → 1.40.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.
- package/.dependency-cruiser.js +422 -422
- package/.eslintrc.js +59 -59
- package/.prettierrc.js +14 -14
- package/README.md +20 -3
- package/coverage/clover.xml +11 -7
- package/coverage/coverage-final.json +95 -1
- package/coverage/coverage-summary.json +59 -2
- package/coverage/lcov-report/base.css +278 -99
- package/coverage/lcov-report/index.html +69 -65
- package/coverage/lcov-report/index.ts.html +36 -35
- package/coverage/lcov-report/sorter.js +15 -5
- package/dist/data-structures/binary-tree/avl-tree.d.ts +106 -0
- package/dist/data-structures/binary-tree/avl-tree.js +347 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +355 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1115 -0
- package/dist/data-structures/binary-tree/bst.d.ts +167 -0
- package/dist/data-structures/binary-tree/bst.js +512 -0
- package/dist/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/data-structures/binary-tree/index.js +23 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +11 -0
- package/dist/data-structures/binary-tree/rb-tree.js +21 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
- package/dist/data-structures/binary-tree/segment-tree.js +180 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +126 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +355 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +313 -0
- package/dist/data-structures/graph/abstract-graph.js +884 -0
- package/dist/data-structures/graph/directed-graph.d.ts +194 -0
- package/dist/data-structures/graph/directed-graph.js +404 -0
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/index.js +20 -0
- package/dist/data-structures/graph/map-graph.d.ts +73 -0
- package/dist/data-structures/graph/map-graph.js +93 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +120 -0
- package/dist/data-structures/graph/undirected-graph.js +239 -0
- package/dist/data-structures/hash/coordinate-map.d.ts +44 -0
- package/dist/data-structures/hash/coordinate-map.js +62 -0
- package/dist/data-structures/hash/coordinate-set.d.ts +36 -0
- package/dist/data-structures/hash/coordinate-set.js +52 -0
- package/dist/data-structures/hash/hash-map.d.ts +50 -0
- package/dist/data-structures/hash/hash-map.js +153 -0
- package/dist/data-structures/hash/hash-table.d.ts +103 -0
- package/dist/data-structures/hash/hash-table.js +236 -0
- package/dist/data-structures/hash/index.d.ts +6 -0
- package/dist/data-structures/hash/index.js +22 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.js +6 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.js +6 -0
- package/dist/data-structures/heap/heap.d.ts +235 -0
- package/dist/data-structures/heap/heap.js +515 -0
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/index.js +19 -0
- package/dist/data-structures/heap/max-heap.d.ts +15 -0
- package/dist/data-structures/heap/max-heap.js +26 -0
- package/dist/data-structures/heap/min-heap.d.ts +15 -0
- package/dist/data-structures/heap/min-heap.js +26 -0
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/index.js +27 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +569 -0
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/index.js +19 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +232 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +533 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +80 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +187 -0
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/index.js +20 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +28 -0
- package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
- package/dist/data-structures/matrix/matrix2d.js +199 -0
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +106 -0
- package/dist/data-structures/matrix/vector2d.d.ts +200 -0
- package/dist/data-structures/matrix/vector2d.js +290 -0
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/index.js +19 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/priority-queue.js +17 -0
- package/dist/data-structures/queue/deque.d.ts +161 -0
- package/dist/data-structures/queue/deque.js +264 -0
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/index.js +18 -0
- package/dist/data-structures/queue/queue.d.ts +122 -0
- package/dist/data-structures/queue/queue.js +187 -0
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/index.js +17 -0
- package/dist/data-structures/stack/stack.d.ts +64 -0
- package/dist/data-structures/stack/stack.js +94 -0
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +8 -0
- package/dist/data-structures/tree/tree.js +40 -0
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/index.js +17 -0
- package/dist/data-structures/trie/trie.d.ts +79 -0
- package/dist/data-structures/trie/trie.js +251 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +18 -4
- package/dist/interfaces/binary-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.js +2 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/doubly-linked-list.js +2 -0
- package/dist/interfaces/graph.d.ts +5 -0
- package/dist/interfaces/graph.js +2 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/heap.js +2 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/index.js +24 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/navigator.js +2 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/priority-queue.js +2 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/segment-tree.js +2 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
- package/dist/types/data-structures/binary-tree/bst.js +2 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/index.js +22 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
- package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
- package/dist/types/data-structures/graph/abstract-graph.js +2 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/graph/directed-graph.js +9 -0
- package/dist/types/data-structures/graph/index.d.ts +3 -0
- package/dist/types/data-structures/graph/index.js +19 -0
- package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/map-graph.js +2 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/undirected-graph.js +2 -0
- package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-map.js +2 -0
- package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-set.js +2 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-map.js +2 -0
- package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-table.js +2 -0
- package/dist/types/data-structures/hash/index.d.ts +1 -0
- package/dist/types/data-structures/hash/index.js +2 -0
- package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-map.js +2 -0
- package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-set.js +2 -0
- package/dist/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/data-structures/heap/heap.js +2 -0
- package/dist/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/data-structures/heap/index.js +17 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/max-heap.js +2 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/min-heap.js +2 -0
- package/dist/types/data-structures/index.d.ts +11 -0
- package/dist/types/data-structures/index.js +27 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/types/data-structures/linked-list/index.js +18 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +17 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix.js +2 -0
- package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix2d.js +2 -0
- package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/data-structures/matrix/navigator.js +2 -0
- package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/vector2d.js +2 -0
- package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/types/data-structures/priority-queue/index.js +19 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
- package/dist/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/types/data-structures/queue/deque.js +2 -0
- package/dist/types/data-structures/queue/index.d.ts +2 -0
- package/dist/types/data-structures/queue/index.js +18 -0
- package/dist/types/data-structures/queue/queue.d.ts +1 -0
- package/dist/types/data-structures/queue/queue.js +2 -0
- package/dist/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/data-structures/stack/index.js +17 -0
- package/dist/types/data-structures/stack/stack.d.ts +1 -0
- package/dist/types/data-structures/stack/stack.js +2 -0
- package/dist/types/data-structures/tree/index.d.ts +1 -0
- package/dist/types/data-structures/tree/index.js +17 -0
- package/dist/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/data-structures/tree/tree.js +2 -0
- package/dist/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/data-structures/trie/index.js +17 -0
- package/dist/types/data-structures/trie/trie.d.ts +1 -0
- package/dist/types/data-structures/trie/trie.js +2 -0
- package/dist/types/helpers.d.ts +8 -0
- package/dist/types/helpers.js +9 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.js +18 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/utils.js +2 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/validate-type.js +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.js +73 -0
- package/jest.config.js +6 -6
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +350 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1262 -0
- package/src/data-structures/binary-tree/bst.ts +522 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/rb-tree.ts +358 -0
- package/src/data-structures/binary-tree/segment-tree.ts +190 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +379 -0
- package/src/data-structures/graph/abstract-graph.ts +1000 -0
- package/src/data-structures/graph/directed-graph.ts +449 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +106 -0
- package/src/data-structures/graph/undirected-graph.ts +259 -0
- package/src/data-structures/hash/coordinate-map.ts +63 -0
- package/src/data-structures/hash/coordinate-set.ts +52 -0
- package/src/data-structures/hash/hash-map.ts +185 -0
- package/src/data-structures/hash/hash-table.ts +268 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/tree-map.ts +2 -0
- package/src/data-structures/hash/tree-set.ts +2 -0
- package/src/data-structures/heap/heap.ts +589 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +26 -0
- package/src/data-structures/heap/min-heap.ts +26 -0
- package/src/data-structures/index.ts +11 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +605 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +576 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +221 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +211 -0
- package/src/data-structures/matrix/navigator.ts +121 -0
- package/src/data-structures/matrix/vector2d.ts +315 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/priority-queue.ts +16 -0
- package/src/data-structures/queue/deque.ts +282 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +209 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +102 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +41 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +262 -0
- package/src/index.ts +4 -1
- package/src/interfaces/binary-tree.ts +10 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/graph.ts +7 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
- package/src/types/data-structures/binary-tree/bst.ts +11 -0
- package/src/types/data-structures/binary-tree/index.ts +6 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
- package/src/types/data-structures/graph/abstract-graph.ts +11 -0
- package/src/types/data-structures/graph/directed-graph.ts +8 -0
- package/src/types/data-structures/graph/index.ts +3 -0
- package/src/types/data-structures/graph/map-graph.ts +1 -0
- package/src/types/data-structures/graph/undirected-graph.ts +1 -0
- package/src/types/data-structures/hash/coordinate-map.ts +1 -0
- package/src/types/data-structures/hash/coordinate-set.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +1 -0
- package/src/types/data-structures/hash/hash-table.ts +1 -0
- package/src/types/data-structures/hash/index.ts +1 -0
- package/src/types/data-structures/hash/tree-map.ts +1 -0
- package/src/types/data-structures/hash/tree-set.ts +1 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/heap/index.ts +1 -0
- package/src/types/data-structures/heap/max-heap.ts +1 -0
- package/src/types/data-structures/heap/min-heap.ts +1 -0
- package/src/types/data-structures/index.ts +11 -0
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/index.ts +2 -0
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +1 -0
- package/src/types/data-structures/matrix/matrix2d.ts +1 -0
- package/src/types/data-structures/matrix/navigator.ts +14 -0
- package/src/types/data-structures/matrix/vector2d.ts +1 -0
- package/src/types/data-structures/priority-queue/index.ts +3 -0
- package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/data-structures/queue/deque.ts +1 -0
- package/src/types/data-structures/queue/index.ts +2 -0
- package/src/types/data-structures/queue/queue.ts +1 -0
- package/src/types/data-structures/stack/index.ts +1 -0
- package/src/types/data-structures/stack/stack.ts +1 -0
- package/src/types/data-structures/tree/index.ts +1 -0
- package/src/types/data-structures/tree/tree.ts +1 -0
- package/src/types/data-structures/trie/index.ts +1 -0
- package/src/types/data-structures/trie/trie.ts +1 -0
- package/src/types/helpers.ts +11 -0
- package/src/types/index.ts +3 -0
- package/src/types/utils/index.ts +2 -0
- package/src/types/utils/utils.ts +6 -0
- package/src/types/utils/validate-type.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +86 -0
- package/tsconfig.json +1 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { MapGraphCoordinate, VertexKey } from '../../types';
|
|
2
|
+
import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
|
|
3
|
+
export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
4
|
+
lat: number;
|
|
5
|
+
long: number;
|
|
6
|
+
/**
|
|
7
|
+
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
|
|
8
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
|
|
9
|
+
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
|
|
10
|
+
* that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
|
|
11
|
+
* values representing points north of the equator and negative values representing points south of the equator.
|
|
12
|
+
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
13
|
+
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
14
|
+
* values ranging from -180 to 180.
|
|
15
|
+
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
|
|
16
|
+
* creating an instance of the class.
|
|
17
|
+
*/
|
|
18
|
+
constructor(key: VertexKey, value: V, lat: number, long: number);
|
|
19
|
+
}
|
|
20
|
+
export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
21
|
+
/**
|
|
22
|
+
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
|
|
23
|
+
* value.
|
|
24
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
25
|
+
* a graph.
|
|
26
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
27
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
28
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
29
|
+
* information or data associated with the edge.
|
|
30
|
+
*/
|
|
31
|
+
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
32
|
+
}
|
|
33
|
+
export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
|
|
34
|
+
/**
|
|
35
|
+
* The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
|
|
36
|
+
* @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
|
|
37
|
+
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
|
|
38
|
+
* graph.
|
|
39
|
+
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
|
|
40
|
+
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
|
|
41
|
+
* it will default to `undefined`.
|
|
42
|
+
*/
|
|
43
|
+
constructor(origin: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
|
|
44
|
+
protected _origin: MapGraphCoordinate;
|
|
45
|
+
get origin(): MapGraphCoordinate;
|
|
46
|
+
protected _bottomRight: MapGraphCoordinate | undefined;
|
|
47
|
+
get bottomRight(): MapGraphCoordinate | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
50
|
+
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
51
|
+
* be a string or a number depending on how you define it in your code.
|
|
52
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
53
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
54
|
+
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
55
|
+
* position of the vertex on the Earth's surface in the north-south direction.
|
|
56
|
+
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
57
|
+
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
58
|
+
*/
|
|
59
|
+
createVertex(key: VertexKey, value?: V, lat?: number, long?: number): VO;
|
|
60
|
+
/**
|
|
61
|
+
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
62
|
+
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
63
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
|
|
64
|
+
* created.
|
|
65
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
66
|
+
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
67
|
+
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
68
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
69
|
+
* depending on the specific implementation of the `MapEdge` class.
|
|
70
|
+
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
71
|
+
*/
|
|
72
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
73
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapGraph = exports.MapEdge = exports.MapVertex = void 0;
|
|
4
|
+
const directed_graph_1 = require("./directed-graph");
|
|
5
|
+
class MapVertex extends directed_graph_1.DirectedVertex {
|
|
6
|
+
/**
|
|
7
|
+
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
|
|
8
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
|
|
9
|
+
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
|
|
10
|
+
* that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
|
|
11
|
+
* values representing points north of the equator and negative values representing points south of the equator.
|
|
12
|
+
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
|
|
13
|
+
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
|
|
14
|
+
* values ranging from -180 to 180.
|
|
15
|
+
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
|
|
16
|
+
* creating an instance of the class.
|
|
17
|
+
*/
|
|
18
|
+
constructor(key, value, lat, long) {
|
|
19
|
+
super(key, value);
|
|
20
|
+
this.lat = lat;
|
|
21
|
+
this.long = long;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.MapVertex = MapVertex;
|
|
25
|
+
class MapEdge extends directed_graph_1.DirectedEdge {
|
|
26
|
+
/**
|
|
27
|
+
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
|
|
28
|
+
* value.
|
|
29
|
+
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
30
|
+
* a graph.
|
|
31
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
32
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
33
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
|
|
34
|
+
* information or data associated with the edge.
|
|
35
|
+
*/
|
|
36
|
+
constructor(src, dest, weight, value) {
|
|
37
|
+
super(src, dest, weight, value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.MapEdge = MapEdge;
|
|
41
|
+
class MapGraph extends directed_graph_1.DirectedGraph {
|
|
42
|
+
/**
|
|
43
|
+
* The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
|
|
44
|
+
* @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
|
|
45
|
+
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
|
|
46
|
+
* graph.
|
|
47
|
+
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
|
|
48
|
+
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
|
|
49
|
+
* it will default to `undefined`.
|
|
50
|
+
*/
|
|
51
|
+
constructor(origin, bottomRight) {
|
|
52
|
+
super();
|
|
53
|
+
this._origin = [0, 0];
|
|
54
|
+
this._origin = origin;
|
|
55
|
+
this._bottomRight = bottomRight;
|
|
56
|
+
}
|
|
57
|
+
get origin() {
|
|
58
|
+
return this._origin;
|
|
59
|
+
}
|
|
60
|
+
get bottomRight() {
|
|
61
|
+
return this._bottomRight;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The function creates a new vertex with the given key, value, latitude, and longitude.
|
|
65
|
+
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
|
|
66
|
+
* be a string or a number depending on how you define it in your code.
|
|
67
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
|
|
68
|
+
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
|
|
69
|
+
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
|
|
70
|
+
* position of the vertex on the Earth's surface in the north-south direction.
|
|
71
|
+
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
72
|
+
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
73
|
+
*/
|
|
74
|
+
createVertex(key, value, lat = this.origin[0], long = this.origin[1]) {
|
|
75
|
+
return new MapVertex(key, value, lat, long);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
79
|
+
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
80
|
+
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
|
|
81
|
+
* created.
|
|
82
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
83
|
+
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
84
|
+
* If the weight is not provided, it can be set to a default value or left undefined.
|
|
85
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
|
|
86
|
+
* depending on the specific implementation of the `MapEdge` class.
|
|
87
|
+
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
|
|
88
|
+
*/
|
|
89
|
+
createEdge(src, dest, weight, value) {
|
|
90
|
+
return new MapEdge(src, dest, weight, value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.MapGraph = MapGraph;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
2
|
+
import type { VertexKey } from '../../types';
|
|
3
|
+
import { IGraph } from '../../interfaces';
|
|
4
|
+
export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
|
|
5
|
+
/**
|
|
6
|
+
* The constructor function initializes a vertex with an optional value.
|
|
7
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
8
|
+
* used to uniquely identify the vertex within a graph or network.
|
|
9
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
10
|
+
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
11
|
+
*/
|
|
12
|
+
constructor(key: VertexKey, value?: V);
|
|
13
|
+
}
|
|
14
|
+
export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
15
|
+
vertices: [VertexKey, VertexKey];
|
|
16
|
+
/**
|
|
17
|
+
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
18
|
+
* value.
|
|
19
|
+
* @param {VertexKey} v1 - The first vertex ID of the edge.
|
|
20
|
+
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
|
|
21
|
+
* graph edge.
|
|
22
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
23
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
|
|
24
|
+
* with the edge.
|
|
25
|
+
*/
|
|
26
|
+
constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E);
|
|
27
|
+
}
|
|
28
|
+
export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
|
|
29
|
+
/**
|
|
30
|
+
* The constructor initializes a new Map object to store edges.
|
|
31
|
+
*/
|
|
32
|
+
constructor();
|
|
33
|
+
protected _edges: Map<VO, EO[]>;
|
|
34
|
+
get edges(): Map<VO, EO[]>;
|
|
35
|
+
/**
|
|
36
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
37
|
+
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
38
|
+
* vertex from another in the graph.
|
|
39
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
40
|
+
* it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
|
|
41
|
+
* the vertex.
|
|
42
|
+
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
|
|
43
|
+
*/
|
|
44
|
+
createVertex(key: VertexKey, value?: VO['value']): VO;
|
|
45
|
+
/**
|
|
46
|
+
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
47
|
+
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
48
|
+
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
49
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
50
|
+
* no weight is provided, it defaults to 1.
|
|
51
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
52
|
+
* is used to store additional information or data associated with the edge.
|
|
53
|
+
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
|
|
54
|
+
*/
|
|
55
|
+
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
|
|
56
|
+
/**
|
|
57
|
+
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
58
|
+
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
59
|
+
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
60
|
+
* @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
61
|
+
* object), `null`, or `VertexKey` (vertex ID).
|
|
62
|
+
* @returns an edge (EO) or null.
|
|
63
|
+
*/
|
|
64
|
+
getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null;
|
|
65
|
+
/**
|
|
66
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
67
|
+
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
68
|
+
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
69
|
+
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
70
|
+
* @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
|
|
71
|
+
*/
|
|
72
|
+
deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | null;
|
|
73
|
+
/**
|
|
74
|
+
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
75
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
76
|
+
* @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
|
|
77
|
+
*/
|
|
78
|
+
deleteEdge(edge: EO): EO | null;
|
|
79
|
+
/**
|
|
80
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
81
|
+
* vertex.
|
|
82
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
83
|
+
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
84
|
+
* edges connected to that vertex.
|
|
85
|
+
*/
|
|
86
|
+
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
87
|
+
/**
|
|
88
|
+
* The function returns the edges of a given vertex or vertex ID.
|
|
89
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
90
|
+
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
91
|
+
* @returns an array of edges.
|
|
92
|
+
*/
|
|
93
|
+
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
94
|
+
/**
|
|
95
|
+
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
96
|
+
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
97
|
+
*/
|
|
98
|
+
edgeSet(): EO[];
|
|
99
|
+
/**
|
|
100
|
+
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
101
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
102
|
+
* (`VertexKey`).
|
|
103
|
+
* @returns an array of vertices (VO[]).
|
|
104
|
+
*/
|
|
105
|
+
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
106
|
+
/**
|
|
107
|
+
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
108
|
+
* it returns null.
|
|
109
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
110
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
111
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
112
|
+
*/
|
|
113
|
+
getEndsOfEdge(edge: EO): [VO, VO] | null;
|
|
114
|
+
/**
|
|
115
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
116
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
117
|
+
* @returns a boolean value.
|
|
118
|
+
*/
|
|
119
|
+
protected _addEdgeOnly(edge: EO): boolean;
|
|
120
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const abstract_graph_1 = require("./abstract-graph");
|
|
13
|
+
class UndirectedVertex extends abstract_graph_1.AbstractVertex {
|
|
14
|
+
/**
|
|
15
|
+
* The constructor function initializes a vertex with an optional value.
|
|
16
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
17
|
+
* used to uniquely identify the vertex within a graph or network.
|
|
18
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
|
|
19
|
+
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
20
|
+
*/
|
|
21
|
+
constructor(key, value) {
|
|
22
|
+
super(key, value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.UndirectedVertex = UndirectedVertex;
|
|
26
|
+
class UndirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
27
|
+
/**
|
|
28
|
+
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
29
|
+
* value.
|
|
30
|
+
* @param {VertexKey} v1 - The first vertex ID of the edge.
|
|
31
|
+
* @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
|
|
32
|
+
* graph edge.
|
|
33
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
34
|
+
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
|
|
35
|
+
* with the edge.
|
|
36
|
+
*/
|
|
37
|
+
constructor(v1, v2, weight, value) {
|
|
38
|
+
super(weight, value);
|
|
39
|
+
this.vertices = [v1, v2];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.UndirectedEdge = UndirectedEdge;
|
|
43
|
+
class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
44
|
+
/**
|
|
45
|
+
* The constructor initializes a new Map object to store edges.
|
|
46
|
+
*/
|
|
47
|
+
constructor() {
|
|
48
|
+
super();
|
|
49
|
+
this._edges = new Map();
|
|
50
|
+
}
|
|
51
|
+
get edges() {
|
|
52
|
+
return this._edges;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
56
|
+
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
57
|
+
* vertex from another in the graph.
|
|
58
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
59
|
+
* it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
|
|
60
|
+
* the vertex.
|
|
61
|
+
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
|
|
62
|
+
*/
|
|
63
|
+
createVertex(key, value) {
|
|
64
|
+
return new UndirectedVertex(key, value !== null && value !== void 0 ? value : key);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
68
|
+
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
69
|
+
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
70
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
71
|
+
* no weight is provided, it defaults to 1.
|
|
72
|
+
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
73
|
+
* is used to store additional information or data associated with the edge.
|
|
74
|
+
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
|
|
75
|
+
*/
|
|
76
|
+
createEdge(v1, v2, weight, value) {
|
|
77
|
+
return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, value);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
81
|
+
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
82
|
+
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
83
|
+
* @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
84
|
+
* object), `null`, or `VertexKey` (vertex ID).
|
|
85
|
+
* @returns an edge (EO) or null.
|
|
86
|
+
*/
|
|
87
|
+
getEdge(v1, v2) {
|
|
88
|
+
var _a;
|
|
89
|
+
let edges = [];
|
|
90
|
+
if (v1 !== null && v2 !== null) {
|
|
91
|
+
const vertex1 = this._getVertex(v1);
|
|
92
|
+
const vertex2 = this._getVertex(v2);
|
|
93
|
+
if (vertex1 && vertex2) {
|
|
94
|
+
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.key));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return edges ? edges[0] || null : null;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
101
|
+
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
102
|
+
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
103
|
+
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
104
|
+
* @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
|
|
105
|
+
*/
|
|
106
|
+
deleteEdgeBetween(v1, v2) {
|
|
107
|
+
const vertex1 = this._getVertex(v1);
|
|
108
|
+
const vertex2 = this._getVertex(v2);
|
|
109
|
+
if (!vertex1 || !vertex2) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const v1Edges = this._edges.get(vertex1);
|
|
113
|
+
let removed = null;
|
|
114
|
+
if (v1Edges) {
|
|
115
|
+
removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertices.includes(vertex2.key))[0] || null;
|
|
116
|
+
}
|
|
117
|
+
const v2Edges = this._edges.get(vertex2);
|
|
118
|
+
if (v2Edges) {
|
|
119
|
+
(0, utils_1.arrayRemove)(v2Edges, (e) => e.vertices.includes(vertex1.key));
|
|
120
|
+
}
|
|
121
|
+
return removed;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
125
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
126
|
+
* @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
|
|
127
|
+
*/
|
|
128
|
+
deleteEdge(edge) {
|
|
129
|
+
return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
133
|
+
* vertex.
|
|
134
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
135
|
+
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
136
|
+
* edges connected to that vertex.
|
|
137
|
+
*/
|
|
138
|
+
degreeOf(vertexOrKey) {
|
|
139
|
+
var _a;
|
|
140
|
+
const vertex = this._getVertex(vertexOrKey);
|
|
141
|
+
if (vertex) {
|
|
142
|
+
return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The function returns the edges of a given vertex or vertex ID.
|
|
150
|
+
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
151
|
+
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
152
|
+
* @returns an array of edges.
|
|
153
|
+
*/
|
|
154
|
+
edgesOf(vertexOrKey) {
|
|
155
|
+
const vertex = this._getVertex(vertexOrKey);
|
|
156
|
+
if (vertex) {
|
|
157
|
+
return this._edges.get(vertex) || [];
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
165
|
+
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
166
|
+
*/
|
|
167
|
+
edgeSet() {
|
|
168
|
+
const edgeSet = new Set();
|
|
169
|
+
this._edges.forEach(edges => {
|
|
170
|
+
edges.forEach(edge => {
|
|
171
|
+
edgeSet.add(edge);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
return [...edgeSet];
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
178
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
179
|
+
* (`VertexKey`).
|
|
180
|
+
* @returns an array of vertices (VO[]).
|
|
181
|
+
*/
|
|
182
|
+
getNeighbors(vertexOrKey) {
|
|
183
|
+
const neighbors = [];
|
|
184
|
+
const vertex = this._getVertex(vertexOrKey);
|
|
185
|
+
if (vertex) {
|
|
186
|
+
const neighborEdges = this.edgesOf(vertex);
|
|
187
|
+
for (const edge of neighborEdges) {
|
|
188
|
+
const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.key)[0]);
|
|
189
|
+
if (neighbor) {
|
|
190
|
+
neighbors.push(neighbor);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return neighbors;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
198
|
+
* it returns null.
|
|
199
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
200
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
201
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
202
|
+
*/
|
|
203
|
+
getEndsOfEdge(edge) {
|
|
204
|
+
if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
const v1 = this._getVertex(edge.vertices[0]);
|
|
208
|
+
const v2 = this._getVertex(edge.vertices[1]);
|
|
209
|
+
if (v1 && v2) {
|
|
210
|
+
return [v1, v2];
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
218
|
+
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
219
|
+
* @returns a boolean value.
|
|
220
|
+
*/
|
|
221
|
+
_addEdgeOnly(edge) {
|
|
222
|
+
for (const end of edge.vertices) {
|
|
223
|
+
const endVertex = this._getVertex(end);
|
|
224
|
+
if (endVertex === null)
|
|
225
|
+
return false;
|
|
226
|
+
if (endVertex) {
|
|
227
|
+
const edges = this._edges.get(endVertex);
|
|
228
|
+
if (edges) {
|
|
229
|
+
edges.push(edge);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this._edges.set(endVertex, [edge]);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.UndirectedGraph = UndirectedGraph;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
export declare class CoordinateMap<V> extends Map<any, V> {
|
|
9
|
+
constructor(joint?: string);
|
|
10
|
+
protected _joint: string;
|
|
11
|
+
get joint(): string;
|
|
12
|
+
/**
|
|
13
|
+
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
14
|
+
* key array with a specified delimiter.
|
|
15
|
+
* @param {number[]} key - The parameter "key" is an array of numbers.
|
|
16
|
+
* @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
|
|
17
|
+
* (`super.has`) with the `key` array joined together using the `_joint` property.
|
|
18
|
+
*/
|
|
19
|
+
has(key: number[]): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The function overrides the set method of a Map object to convert the key from an array to a string using a specified
|
|
22
|
+
* delimiter before calling the original set method.
|
|
23
|
+
* @param {number[]} key - The key parameter is an array of numbers.
|
|
24
|
+
* @param {V} value - The value parameter is the value that you want to associate with the specified key.
|
|
25
|
+
* @returns The `set` method is returning the result of calling the `set` method of the superclass
|
|
26
|
+
* (`super.set(key.join(this._joint), value)`).
|
|
27
|
+
*/
|
|
28
|
+
set(key: number[], value: V): this;
|
|
29
|
+
/**
|
|
30
|
+
* The function overrides the get method to join the key array with a specified joint and then calls the super get
|
|
31
|
+
* method.
|
|
32
|
+
* @param {number[]} key - An array of numbers
|
|
33
|
+
* @returns The code is returning the value associated with the specified key in the map.
|
|
34
|
+
*/
|
|
35
|
+
get(key: number[]): V | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The function overrides the delete method and joins the key array using a specified joint character before calling
|
|
38
|
+
* the super delete method.
|
|
39
|
+
* @param {number[]} key - An array of numbers that represents the key to be deleted.
|
|
40
|
+
* @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
|
|
41
|
+
* `key` array joined together using the `_joint` property.
|
|
42
|
+
*/
|
|
43
|
+
delete(key: number[]): boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoordinateMap = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
11
|
+
class CoordinateMap extends Map {
|
|
12
|
+
constructor(joint) {
|
|
13
|
+
super();
|
|
14
|
+
this._joint = '_';
|
|
15
|
+
if (joint !== undefined)
|
|
16
|
+
this._joint = joint;
|
|
17
|
+
}
|
|
18
|
+
get joint() {
|
|
19
|
+
return this._joint;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
23
|
+
* key array with a specified delimiter.
|
|
24
|
+
* @param {number[]} key - The parameter "key" is an array of numbers.
|
|
25
|
+
* @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
|
|
26
|
+
* (`super.has`) with the `key` array joined together using the `_joint` property.
|
|
27
|
+
*/
|
|
28
|
+
has(key) {
|
|
29
|
+
return super.has(key.join(this._joint));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The function overrides the set method of a Map object to convert the key from an array to a string using a specified
|
|
33
|
+
* delimiter before calling the original set method.
|
|
34
|
+
* @param {number[]} key - The key parameter is an array of numbers.
|
|
35
|
+
* @param {V} value - The value parameter is the value that you want to associate with the specified key.
|
|
36
|
+
* @returns The `set` method is returning the result of calling the `set` method of the superclass
|
|
37
|
+
* (`super.set(key.join(this._joint), value)`).
|
|
38
|
+
*/
|
|
39
|
+
set(key, value) {
|
|
40
|
+
return super.set(key.join(this._joint), value);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The function overrides the get method to join the key array with a specified joint and then calls the super get
|
|
44
|
+
* method.
|
|
45
|
+
* @param {number[]} key - An array of numbers
|
|
46
|
+
* @returns The code is returning the value associated with the specified key in the map.
|
|
47
|
+
*/
|
|
48
|
+
get(key) {
|
|
49
|
+
return super.get(key.join(this._joint));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The function overrides the delete method and joins the key array using a specified joint character before calling
|
|
53
|
+
* the super delete method.
|
|
54
|
+
* @param {number[]} key - An array of numbers that represents the key to be deleted.
|
|
55
|
+
* @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
|
|
56
|
+
* `key` array joined together using the `_joint` property.
|
|
57
|
+
*/
|
|
58
|
+
delete(key) {
|
|
59
|
+
return super.delete(key.join(this._joint));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.CoordinateMap = CoordinateMap;
|