mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 04:44:04 +00:00
[BinaryTree] isMergeDuplicatedNodeById removed, [MapGraph] MapGraph added
This commit is contained in:
parent
6f86f71cdd
commit
f3b2398d20
39
src/data-structures/graph/map-graph.ts
Normal file
39
src/data-structures/graph/map-graph.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import {MapGraphCoordinate, VertexId } from '../types';
|
||||
import {DirectedEdge, DirectedGraph, DirectedVertex} from './directed-graph';
|
||||
|
||||
export class MapVertex<T = any> extends DirectedVertex<T> {
|
||||
|
||||
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<T = any> extends DirectedEdge<T> {
|
||||
constructor(src: VertexId, dest: VertexId, weight?: number, val?: T) {
|
||||
super(src, dest, weight, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class MapGraph<V extends MapVertex<V['val']> = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph<V, E> {
|
||||
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;
|
||||
}
|
||||
}
|
1
src/data-structures/types/map-graph.ts
Normal file
1
src/data-structures/types/map-graph.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export type MapGraphCoordinate = [number, number];
|
Loading…
Reference in a new issue