-
Notifications
You must be signed in to change notification settings - Fork 1
DWGraph_DS
LielVaknin edited this page Dec 20, 2020
·
16 revisions
This class included in the api package and implements the directed_weighted_graph interface.
It represents a directed weighted graph.
-
int MC (Mode Count) - Counts changes in the graph
-
int nodeSize - Represents the number of nodes in the graph.
-
int edgeSize - Represents the number of directional edges in the graph.
-
HashMap<Integer, node_data> nodes - Represents a list of all nodes in the graph.
-
HashMap<Integer, HashMap<Integer, edge_data>> edges - A list of all nodes that each one contains its list of neighbors and each neighbor contains the data of the directional edge between the node itself and the neighbor node.
Both lists which mentioned above implemented in a data structure - HashMap.
The first one implemented with a HashMap and the second with a HashMap in a HashMap.
The reason for using this data structure is because operations like adding / removing / searching executes at time complexity O(1).
-
Constructors -
-
Default constructor: DWGraph_DS().
-
Copy constructor: DWGraph_DS(directed_weighted_graph graph) - Performs a deep copy of a given graph.
- node_data getNode(int key) - Returns the node_data by the node_id.
- edge_data getEdge(int src, int dest) - Returns the data of the edge between src to dest, null if none.
- void addNode(node_data n) - Adds a new node to the graph with a given node_data.
- void connect(int src, int dest, double w) - Connects an edge with weight w between node src to node dest.
- Collection<node_data> getV() - Returns a pointer (shallow copy) for the collection representing all the nodes in the graph.
- Collection<edge_data> getE(int node_id) - Returns a pointer (shallow copy) for the collection representing all the edges getting out of the given node (all the edges starting (source) at the given node).
- node_data removeNode(int key) - Deletes the node (with the given ID) from the graph and removes all edges which starts or ends at this node.
- edge_data removeEdge(int src, int dest) - Deletes from the graph the directed edge between src to dest.
- int nodeSize() - Returns the number of vertices (nodes) in the graph.
- int edgeSize() - Returns the number of directional edges in the graph.
- int getMC() - Returns the Mode Count - for testing changes in the graph.
- String toString() - String which represents all the nodes in this graph by their keys and the edges which connected to each one of them (the neighbor and the edge's weight).