From f3b2398d203b02a71d09a00d5eabd08670e53144 Mon Sep 17 00:00:00 2001 From: Revone Date: Thu, 7 Sep 2023 21:00:10 +0800 Subject: [PATCH] [BinaryTree] isMergeDuplicatedNodeById removed, [MapGraph] MapGraph added --- LICENSE | 0 src/data-structures/graph/map-graph.ts | 39 ++++++++++++++++++++++++++ src/data-structures/types/map-graph.ts | 1 + 3 files changed, 40 insertions(+) create mode 100644 LICENSE create mode 100644 src/data-structures/graph/map-graph.ts create mode 100644 src/data-structures/types/map-graph.ts diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/src/data-structures/graph/map-graph.ts b/src/data-structures/graph/map-graph.ts new file mode 100644 index 0000000..eae7e7e --- /dev/null +++ b/src/data-structures/graph/map-graph.ts @@ -0,0 +1,39 @@ +import {MapGraphCoordinate, VertexId } from '../types'; +import {DirectedEdge, DirectedGraph, DirectedVertex} from './directed-graph'; + +export class MapVertex extends DirectedVertex { + + constructor(id: VertexId, lat: number, long: number, val?: T) { + super(id, val); + this.lat = lat; + this.long = long; + } + lat: number; + long: number; +} + +export class MapEdge extends DirectedEdge { + constructor(src: VertexId, dest: VertexId, weight?: number, val?: T) { + super(src, dest, weight, val); + } +} + + +export class MapGraph = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph { + constructor(topLeft: MapGraphCoordinate, bottomRight: MapGraphCoordinate) { + super(); + this.topLeft = topLeft; + this.bottomRight = bottomRight; + } + + topLeft: MapGraphCoordinate; + bottomRight: MapGraphCoordinate; + + override createVertex(id: VertexId, val?: V['val'], lat: number = this.topLeft[0], long: number = this.topLeft[1]): V { + return new MapVertex(id, lat, long, val) as V; + } + + override createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E { + return new MapEdge(src, dest, weight, val) as E; + } +} \ No newline at end of file diff --git a/src/data-structures/types/map-graph.ts b/src/data-structures/types/map-graph.ts new file mode 100644 index 0000000..b3a672c --- /dev/null +++ b/src/data-structures/types/map-graph.ts @@ -0,0 +1 @@ +export type MapGraphCoordinate = [number, number]; \ No newline at end of file