doubly-linked-list-typed
Version:
Doubly Linked List
111 lines (110 loc) • 6.2 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapGraph = exports.MapEdge = exports.MapVertex = void 0;
const directed_graph_1 = require("./directed-graph");
class MapVertex extends directed_graph_1.DirectedVertex {
/**
* The constructor function initializes an object with an key, latitude, longitude, and an optional value.
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
* @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
* that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
* values representing points north of the equator and negative values representing points south of the equator.
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
* values ranging from -180 to 180.
* @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
* creating an instance of the class.
*/
constructor(key, value, lat, long) {
super(key, value);
this.lat = lat;
this.long = long;
}
}
exports.MapVertex = MapVertex;
class MapEdge extends directed_graph_1.DirectedEdge {
/**
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
* value.
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
* @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
* information or data associated with the edge.
*/
constructor(src, dest, weight, value) {
super(src, dest, weight, value);
}
}
exports.MapEdge = MapEdge;
/**
*
*/
class MapGraph extends directed_graph_1.DirectedGraph {
/**
* The constructor function initializes the originCoord and bottomRight properties of a MapGraphCoordinate object.
* @param {MapGraphCoordinate} originCoord - The `originCoord` parameter is a `MapGraphCoordinate` object that represents the
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
* graph.
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
* it will default to `undefined`.
*/
constructor(originCoord, bottomRight) {
super();
this._originCoord = [0, 0];
this._originCoord = originCoord;
this._bottomRight = bottomRight;
}
get originCoord() {
return this._originCoord;
}
get bottomRight() {
return this._bottomRight;
}
/**
* The function creates a new vertex with the given key, value, latitude, and longitude.
* @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
* be a string or a number depending on how you define it in your code.
* @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
* is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
* @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
* position of the vertex on the Earth's surface in the north-south direction.
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
*/
createVertex(key, value, lat = this.originCoord[0], long = this.originCoord[1]) {
return new MapVertex(key, value, lat, long);
}
/**
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
* created.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
* If the weight is not provided, it can be set to a default value or left undefined.
* @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
* depending on the specific implementation of the `MapEdge` class.
* @returns a new instance of the `MapEdge` class, cast as type `EO`.
*/
createEdge(src, dest, weight, value) {
return new MapEdge(src, dest, weight, value);
}
/**
* The override function is used to override the default behavior of a function.
* In this case, we are overriding the clone() function from Graph<V, E>.
* The clone() function returns a new graph that is an exact copy of the original graph.
*
* @return A mapgraph<v, e, vo, eo>
*/
clone() {
const cloned = new MapGraph(this.originCoord, this.bottomRight);
cloned.vertexMap = new Map(this.vertexMap);
cloned.inEdgeMap = new Map(this.inEdgeMap);
cloned.outEdgeMap = new Map(this.outEdgeMap);
return cloned;
}
}
exports.MapGraph = MapGraph;
;