Bridges-C++  3.4.1
Bridges(C++API)
GraphAdjList.h
Go to the documentation of this file.
1 #ifndef GRAPH_ADJ_LIST
2 #define GRAPH_ADJ_LIST
3 
4 #include <stdexcept>
5 #include <sstream>
6 #include <unordered_map>
7 #include <JSONutil.h>
8 
9 
10 using namespace std;
11 
12 #include "SLelement.h"
13 #include "Edge.h"
14 
15 namespace bridges {
16  namespace datastructure {
110  template<typename K, typename E1 = K, typename E2 = E1>
111  class GraphAdjList : public DataStructure {
112  private:
113  // list of graph vertices
114  // maintained as a map to accommodate strings
115  unordered_map<K, Element<E1>* > vertices;
116  // adjacency lists
117  unordered_map<K, SLelement<Edge<K, E2> >*> adj_list;
118 
119  // large graph related
120  static const int LargeGraphVertSize = 2000;
121 
122  bool forceLargeViz = false;
123  bool forceSmallViz = false;
124 
125 
126  GraphAdjList(const GraphAdjList& gr) = delete; //would not be correct
127  const GraphAdjList& operator= (const GraphAdjList& gr) = delete; //would not be correct
128  public:
129 
130  GraphAdjList() = default;
131  GraphAdjList(GraphAdjList&& gr) = default;
132 
133  virtual ~GraphAdjList() override {
134  for (auto& v : vertices) {
135  if (adj_list[v.first]) {
136  // discard the edges in the adj. list
137  SLelement<Edge<K, E2>> *tmp;
138  for (SLelement<Edge<K, E2>> *sle =
139  adj_list[v.first]; sle != nullptr; ) {
140  tmp = sle;
141  sle = sle->getNext();
142  delete tmp;
143  }
144  adj_list[v.first] = nullptr;
145  }
146  delete vertices[v.first]; // free the element at v
147  vertices[v.first] = nullptr;
148 
149  }
150  }
156  virtual const string getDStype() const override {
157  if (forceLargeViz || (!forceSmallViz &&
158  vertices.size() > LargeGraphVertSize &&
159  areAllVerticesLocated())) {
160  return "largegraph";
161  }
162  return "GraphAdjacencyList";
163  }
164 
177  void addVertex(const K& k, const E1& e = E1()) {
178  stringstream conv;
179  conv << k;
180  if (vertices.find(k) == vertices.end()) {
181  // vertex does not exist, create one
182  vertices[k] = new Element<E1>(e, conv.str());
183  adj_list[k] = nullptr;
184  }
185  }
200  void addEdge(const K& src, const K& dest, const E2& data = E2()) {
201  try {
202  vertices.at(src);
203  vertices.at(dest);
204  // links structure is redundant and needs
205  // to be removed in future implementations!
206  vertices[src]->links[vertices.at(dest)]; //In C++ this creates the linkvisualizer
207 
208  stringstream conv;
209  conv << dest;
210  // add the edge
211  adj_list.at(src) =
212  new SLelement<Edge<K, E2> > (adj_list.at(src),
213  Edge<K, E2> (src, dest, &(vertices[src]->links[vertices.at(dest)]), data), conv.str());
214 
215  }
216  catch ( const out_of_range& ) {
217  cerr << "addEdge(): Nonexistent vertex?" << endl <<
218  "Create vertices first prior to adding edges that use that vertex" << endl
219  << "Cannot add edge between non-existent verticies"
220  << endl;
221  throw;
222  }
223  }
231  bool isEdge(const K& src, const K& dest) {
232  try {
233  vertices.at(src);
234  vertices.at(dest);
235  for (auto& e : outgoingEdgeSetOf(src))
236  if (e.to() == dest) { // found it
237  cout << "found it!" << src << "," << dest << endl;
238  return true;
239  }
240  }
241  catch ( const out_of_range& ) {
242  return false;
243  }
244  return false;
245  }
253  const E1& getVertexData (const K& src)& {
254  try {
255  Element<E1> *el = vertices.at(src);
256  return (vertices.at(src))->getValue();
257  }
258  catch ( const out_of_range& ) {
259  cerr << "getVertexData(): vertex not found" << endl;
260  throw;
261  }
262  // should never reach here
263  throw "getVertexData(): vertex not found";
264  }
272  void setVertexData (const K& vertID, E1 const & data) {
273  try {
274  Element<E1> *el = vertices.at(vertID);
275  el->setValue (data);
276  }
277  catch ( const out_of_range& ) {
278  cerr << "setVertexData(): Nonexistent vertex" << endl;
279  throw;
280  }
281  catch (const char* msg) {
282  cerr << msg << endl;
283  }
284  }
293  E2& getEdgeData (const K& src, const K& dest) {
294  try {
295  vertices.at(src);
296  vertices.at(dest);
297  SLelement<Edge<K, E2> > *sle = adj_list.at(src);
298  while (sle) {
299  Edge<K, E2> ed = sle->getValue();
300  if (ed.to() == dest) { //edge exists
301  return ed.getEdgeData();
302  }
303  sle = sle->getNext();
304  }
305  throw "Edge not found!";
306  }
307  catch ( const out_of_range& ) {
308  cerr << "getEdgeData(): Edge not found" << endl;
309  throw;
310  }
311  catch (const char* msg) {
312  cerr << msg << endl;
313  }
314  // should never reach here
315  throw "getEdgeData(): Edge not found";
316  }
325  E2 const& getEdgeData (const K& src, const K& dest) const {
326  try {
327  vertices.at(src);
328  vertices.at(dest);
329  SLelement<Edge<K, E2> > *sle = adj_list.at(src);
330  while (sle) {
331  Edge<K, E2> ed = sle->getValue();
332  if (ed.getVertex() == dest) { //edge exists
333  return ed.getEdgeData();
334  }
335  sle = sle->getNext();
336  }
337  throw "Edge not found!";
338  }
339  catch ( const out_of_range& ) {
340  cerr << "getEdgeData(): Edge not found" << endl;
341  throw;
342  }
343  catch (const char* msg) {
344  cerr << msg << endl;
345  }
346  // should never reach here
347  throw "getEdgeData(): Edge not found";
348  }
349 
350 
359  void setEdgeData (const K& src, const K& dest, E2& data) {
360  try {
361  vertices.at(src);
362  vertices.at(dest);
363  SLelement<Edge<K, E2> > *sle = adj_list.at(src);
364  while (sle) {
365  Edge<K, E2> ed = sle->getValue();
366  if (ed.getVertex() == dest) { //edge exists
367  ed.setEdgeData(data); //change edge data
368  sle->setValue(ed); //change slelement data
369  return;
370  }
371  sle = sle->getNext();
372  }
373  throw "getEdgeData(): Edge not found!";
374  }
375  catch ( const out_of_range& ) {
376  cerr << "setEdgeData(): Nonexistent vertices or " <<
377  " edge not found" << endl;
378  throw;
379  }
380  catch (const char* msg) {
381  cerr << msg << endl;
382  }
383  // will never reach here, but avoids compiler warnings
384  throw "getEdgeData(): Edge not found";
385  }
391  unordered_map<K, Element<E1>*>* getVertices() {
392  return &vertices;
393  }
394 
400  const unordered_map<K, Element<E1>*>* getVertices() const {
401  return &vertices;
402  }
408  const Element<E1>* getVertex(const K& key) const {
409  try {
410  return vertices.at(key);
411  }
412  catch (const std::out_of_range& oor) {
413  /* std::cerr << "Out of Range error: " << oor.what() */
414  /* << "returning null pointer\n"; */
415  return nullptr;
416  }
417  }
418 
419 
425  Element<E1>* getVertex(const K& key) {
426  try {
427  return vertices.at(key);
428  }
429  catch (const std::out_of_range& oor) {
430  /* std::cerr << "Out of Range error: " << oor.what() */
431  /* << "returning null pointer\n"; */
432  return nullptr;
433  }
434  }
435 
443  Edge<K, E2> getEdge(const K& src, const K& dest) {
444  // check to see if the two vertices exist, else
445  // return null
446  try {
447  // look for the edge
448  SLelement<Edge<K, E2>> *sle = adj_list[src];
449  while (sle != nullptr) {
450  K edge_dest = ((Edge<K, E2>) sle->getValue()).to();
451  if (edge_dest == dest) // found
452  return sle->getValue();
453  sle = sle->getNext();
454  }
455  }
456  catch (const std::out_of_range& oor) {
457  // one or both vertices doesnt exist
458  std::cout << "one or both vertices are likely missing from graph\n";
459  throw;
460  }
461  throw "Edge not found";
462  }
463 
468  const unordered_map<K, SLelement<Edge<K, E2> >*>&
470  return adj_list;
471  }
472 
482  try {
483  return adj_list.at(k);
484  }
485  catch (const out_of_range& ) {
486  cerr << "Cannot get adjacencyList of a non-existent vertex -- " << k << "\n";
487  throw;
488  }
489  }
490 
499  const SLelement<Edge<K, E2> >* getAdjacencyList(const K& k) const {
500  try {
501  return adj_list.at(k);
502  }
503  catch (const out_of_range& ) {
504  cerr << "Cannot getAdjacencyList() of a non-existent vertex!"
505  << endl;
506  throw;
507  }
508  }
509 
510 
520  try {
521  Element<E1> *el = vertices.at(k);
522 
523  return el->getVisualizer();
524  }
525  catch (const out_of_range& ) {
526  cerr << "Graph vertex " << k << " not found in graph!" << endl;
527  throw;
528  }
529  }
540  LinkVisualizer *getLinkVisualizer (const K& k1, const K& k2) {
541  try {
542  return getEdge(k1, k2).getLinkVisualizer();
543  }
544  catch (const out_of_range& ) {
545  cerr << "Either source or destination node not found in graph!\n";
546  throw;
547  }
548  }
549  private:
555  virtual const string getDataStructureRepresentation() const override {
557 
558  // map the nodes to a sequence of ids, 0...N-1
559  // then get the JSON string for nodes placeholder
560  // nullptr prevents insertion of other nullptrs
561 
562  // check for large graph
563  if (forceLargeViz ||
564  (!forceSmallViz &&
565  vertices.size() > LargeGraphVertSize &&
566  areAllVerticesLocated())) {
567  return getDataStructureRepresentationLargeGraph();
568  }
569 
570  unordered_map<K, int> node_map;
571  int i = 0;
572  string nodes_JSON = "", links_JSON = "";
573 
574  for (const auto& v : vertices) {
575  if (node_map.emplace(v.first, i).second) {
576  i++;
577  nodes_JSON += v.second->getElementRepresentation() + COMMA;
578  }
579  }
580 
581  //Remove trailing comma and nullptr entry
582 
583  if (nodes_JSON.size()) {
584  nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
585  }
586 
587  // iterate through the vertices and form the links JSON
588 
589  for (const auto& v : vertices) {
590  // get adj. list
591  Element<E1>* src_vert = vertices.at(v.first);
592  // iterate through list and form links
593  for (SLelement<Edge<K, E2>>* it = adj_list.at(v.first); it != nullptr;
594  it = it->getNext()) {
595  Element<E1>* dest_vert = vertices.at(it->getValue().to() );
596  links_JSON += src_vert->getLinkRepresentation(
597  *(src_vert->getLinkVisualizer(dest_vert)),
598  JSONencode(node_map.at(v.first)),
599  JSONencode(node_map.at(it->getValue().to())) ) + COMMA;
600  }
601  }
602 
603  //Remove trailing comma
604  if (links_JSON.size()) {
605  links_JSON = links_JSON.erase(links_JSON.size() - 1);
606  }
607 
608  string graph_alist_json =
609  QUOTE + "nodes" + QUOTE + COLON +
610  OPEN_BOX + nodes_JSON + CLOSE_BOX + COMMA +
611  QUOTE + "links" + QUOTE + COLON + OPEN_BOX +
612  links_JSON + CLOSE_BOX +
613  CLOSE_CURLY;
614 
615 
616  return graph_alist_json;
617  }
628  string getDataStructureRepresentationLargeGraph () const {
629 
631  // map the nodes to a sequence of ids, 0...N-1
632  // then get the JSON string for nodes placeholder
633  // nullptr prevents insertion of other nullptrs
634 
635  unordered_map<K, int> node_map;
636  int i = 0;
637  string nodes_JSON = "";
638 
639  for (const auto& v : vertices) {
640  if (node_map.emplace(v.first, i).second) {
641  i++;
642  const ElementVisualizer *elvis =
643  vertices.at(v.first)->getVisualizer();
644  string loc_str = "";
645  if ( (elvis->getLocationX() != INFINITY) &&
646  (elvis->getLocationY() != INFINITY) ) {
647  loc_str =
648  OPEN_BOX +
649  JSONencode(elvis->getLocationX()) + COMMA +
650  JSONencode(elvis->getLocationY()) +
651  CLOSE_BOX + COMMA;
652  }
653  nodes_JSON += OPEN_BOX + loc_str +
654  elvis->getColor().getCSSRepresentation() +
655  CLOSE_BOX + COMMA;
656  }
657  }
658 
659  //Remove trailing comma and nullptr entry
660 
661  if (nodes_JSON.size()) {
662  nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
663  }
664 
665  // next link information
666  string links_JSON = "";
667  for (const auto& v : vertices) {
668  // get adj. list
669  Element<E1>* src_vert = vertices.at(v.first);
670  // iterate through list and form links
671  for (SLelement<Edge<K, E2>>* it = adj_list.at(v.first); it != nullptr;
672  it = it->getNext()) {
673  Element<E1>* dest_vert = vertices.at(it->getValue().to() );
674  LinkVisualizer *lv = src_vert->getLinkVisualizer(dest_vert);
675  string src = JSONencode(node_map.at(v.first));
676  string dest = JSONencode(node_map.at(it->getValue().to()));
677  links_JSON += OPEN_BOX +
678  src + COMMA +
679  dest + COMMA +
680  lv->getColor().getCSSRepresentation() +
681  CLOSE_BOX + COMMA;
682 
683  }
684  }
685  //Remove trailing comma
686  if (links_JSON.size())
687  links_JSON = links_JSON.erase(links_JSON.size() - 1);
688 
689  string graph_alist_json =
690  QUOTE + "nodes" + QUOTE + COLON +
691  OPEN_BOX + nodes_JSON + CLOSE_BOX + COMMA +
692  QUOTE + "links" + QUOTE + COLON +
693  OPEN_BOX + links_JSON + CLOSE_BOX +
694  CLOSE_CURLY;
695 
696  return graph_alist_json;
697 
698  }
702  bool areAllVerticesLocated() const {
703  for (const auto& v : vertices) {
704  ElementVisualizer *elvis = v.second->getVisualizer();
705  if (elvis->getLocationX() == INFINITY
706  || elvis->getLocationY() == INFINITY)
707  return false;
708  }
709  return true;
710  }
711 
712 
713  public:
714 
731  void forceLargeVisualization(bool f) {
732  if (f) {
733  forceLargeViz = true;
734  forceSmallViz = false;
735  }
736  else {
737  forceLargeViz = false;
738  }
739  }
740 
757  void forceSmallVisualization(bool f) {
758  if (f) {
759  forceSmallViz = true;
760  forceLargeViz = false;
761  }
762  else {
763  forceSmallViz = false;
764  }
765  }
766 
767  // @brief This is a helper class to return sets of vertices
768  // in a way that are iterable with range for loops.
769  // Students should not have to use this directly.
771  std::unordered_map<K, Element<E1>* > const & underlying_map;
772 
773  public:
774  KeySet_helper (std::unordered_map<K, Element<E1>* > const & um)
775  : underlying_map(um)
776  {}
777 
779  typename std::unordered_map<K, Element<E1>* >::const_iterator it;
780  public:
781  const_iterator(typename std::unordered_map<K, Element<E1>* >::const_iterator i )
782  : it(i)
783  {}
784 
785  bool operator!=(const const_iterator& it) const {
786  return this->it != it.it;
787  }
788 
789  const K& operator*() const {
790  return it->first;
791  }
792 
794  it ++;
795  return *this;
796  }
797  };
798 
800  return const_iterator(underlying_map.begin());
801  }
802 
803  const_iterator end() const {
804  return const_iterator(underlying_map.end());
805  }
806  };
807 
818  return KeySet_helper(this->vertices);
819  }
820 
825  typename SLelement<Edge<K, E2>>::SLelement_listhelper
826  outgoingEdgeSetOf(K const & k) {
827  return typename SLelement<Edge<K, E2>>::SLelement_listhelper(getAdjacencyList(k));
828  }
829 
834  typename SLelement<Edge<K, E2>>::SLelement_constlisthelper
835  outgoingEdgeSetOf(K const & k) const {
836  return typename SLelement<Edge<K, E2>>::SLelement_constlisthelper(getAdjacencyList(k));
837  }
838 
839 
846  typename std::unordered_map<K, Element<E1>* > & underlying_map;
847 
848  public:
849  VertexElementSet_listhelper (std::unordered_map<K, Element<E1>* > & um)
850  : underlying_map(um)
851  {}
852 
858  class iterator {
859  typename std::unordered_map<K, Element<E1>* >::iterator it;
860  public:
861  iterator(typename std::unordered_map<K, Element<E1>* >::iterator i )
862  : it(i)
863  {}
864 
865  bool operator!=(const iterator& it) const {
866  return this->it != it.it;
867  }
868 
869  Element<E1>* operator*() {
870  return it->second;
871  }
872 
874  it ++;
875  return *this;
876  }
877  };
878 
885  typename std::unordered_map<K, Element<E1>* >::const_iterator it;
886  public:
887  const_iterator(typename std::unordered_map<K, Element<E1>* >::const_iterator i )
888  : it(i)
889  {}
890 
891  bool operator!=(const const_iterator& it) const {
892  return this->it != it.it;
893  }
894 
895  Element<E1> const* operator*() const {
896  return it->second;
897  }
898 
900  it ++;
901  return *this;
902  }
903  };
904 
905 
907  return iterator(underlying_map.begin());
908  }
909 
911  return iterator(underlying_map.end());
912  }
913 
915  return const_iterator(underlying_map.begin());
916  }
917 
918  const_iterator end() const {
919  return const_iterator(underlying_map.end());
920  }
921 
922  };
923 
929  return VertexElementSet_listhelper(vertices);
930  }
931 
932 
939  typename std::unordered_map<K, Element<E1>* > const & underlying_map;
940 
941  public:
942  constVertexElementSet_listhelper (std::unordered_map<K, Element<E1>* > const& um)
943  : underlying_map(um)
944  {}
945 
948  typename std::unordered_map<K, Element<E1>* >::const_iterator it;
949  public:
950  const_iterator(typename std::unordered_map<K, Element<E1>* >::const_iterator i )
951  : it(i)
952  {}
953 
954  bool operator!=(const const_iterator& it) const {
955  return this->it != it.it;
956  }
957 
958  Element<E1> const* operator*() const {
959  return it->second;
960  }
961 
963  it ++;
964  return *this;
965  }
966  };
967 
969  return const_iterator(underlying_map.begin());
970  }
971 
972  const_iterator end() const {
973  return const_iterator(underlying_map.begin());
974  }
975  };
981  return constVertexElementSet_listhelper(vertices);
982  }
983  };
984 
985  //end of GraphAdjList class
986  }
987 }//end of bridges namespace
988 #endif
VertexElementSet_listhelper vertexSet()
Definition: GraphAdjList.h:928
void forceSmallVisualization(bool f)
Force the rendering engine to use small graph visualization.
Definition: GraphAdjList.h:757
This is a helper class to return sets of vertices in a way that are iterable with range for loops....
Definition: GraphAdjList.h:858
void setValue(const E &val)
Sets generic object to "val".
Definition: Element.h:229
const K & to() const
Destination vertex accessor.
Definition: Edge.h:86
This is a helper class to return sets of vertices ina way that are iterable with range for loops....
Definition: GraphAdjList.h:947
void setEdgeData(const E2 &data)
Sets edge data to "data".
Definition: Edge.h:94
ElementVisualizer * getVisualizer(const K &k)
Returns the visualizer corresponding to a graph vertex. convenient method to set attributes of the gr...
Definition: GraphAdjList.h:519
bool operator!=(const const_iterator &it) const
Definition: GraphAdjList.h:891
E2 & getEdgeData(const K &src, const K &dest)
Gets edge data for the edge from "src" to "dest".
Definition: GraphAdjList.h:293
SLelement< Edge< K, E2 > > * getAdjacencyList(const K &k)
Returns adjacency list of a vertex with name k.
Definition: GraphAdjList.h:481
const string COLON
Definition: DataStructure.h:51
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:210
iterator(typename std::unordered_map< K, Element< E1 > * >::iterator i)
Definition: GraphAdjList.h:861
constVertexElementSet_listhelper(std::unordered_map< K, Element< E1 > * > const &um)
Definition: GraphAdjList.h:942
SLelement< Edge< K, E2 > >::SLelement_listhelper outgoingEdgeSetOf(K const &k)
This method is useful for iterating through a set of outgoing edges from a vertex.
Definition: GraphAdjList.h:826
This class maintains the visual properties of the a Bridges element.
Definition: ElementVisualizer.h:31
const string OPEN_BOX
Definition: DataStructure.h:54
const_iterator end() const
Definition: GraphAdjList.h:972
const_iterator(typename std::unordered_map< K, Element< E1 > * >::const_iterator i)
Definition: GraphAdjList.h:950
const_iterator begin() const
Definition: GraphAdjList.h:799
const_iterator(typename std::unordered_map< K, Element< E1 > * >::const_iterator i)
Definition: GraphAdjList.h:887
const string CLOSE_CURLY
Definition: DataStructure.h:53
const Element< E1 > * getVertex(const K &key) const
Return the vertex corresponding to a key.
Definition: GraphAdjList.h:408
const E1 & getVertexData(const K &src) &
Gets vertex data for a graph vertex.
Definition: GraphAdjList.h:253
const_iterator end() const
Definition: GraphAdjList.h:803
Element< E1 > * getVertex(const K &key)
Definition: GraphAdjList.h:425
The singly linked list element, derived from Element.
Definition: SLelement.h:27
This is a helper class to return sets of vertices in a way that are iterable with range for loops....
Definition: GraphAdjList.h:884
const_iterator end() const
Definition: GraphAdjList.h:918
void forceLargeVisualization(bool f)
Force the rendering engine to use large graph visualization.
Definition: GraphAdjList.h:731
void addVertex(const K &k, const E1 &e=E1())
Adds a vertex to the graph.
Definition: GraphAdjList.h:177
const_iterator(typename std::unordered_map< K, Element< E1 > * >::const_iterator i)
Definition: GraphAdjList.h:781
bool operator!=(const iterator &it) const
Definition: GraphAdjList.h:865
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const_iterator begin() const
Definition: GraphAdjList.h:968
virtual const string getDStype() const override
Get the string representation of this data structure type.
Definition: GraphAdjList.h:156
const string CLOSE_BOX
Definition: DataStructure.h:55
bool operator!=(const const_iterator &it) const
Definition: GraphAdjList.h:954
const E2 & getEdgeData() const
Return the edge data.
Definition: Edge.h:102
bool operator!=(const const_iterator &it) const
Definition: GraphAdjList.h:785
This is a helper class to return sets of vertices in a way that are iterable with range for loops....
Definition: GraphAdjList.h:938
const_iterator begin() const
Definition: GraphAdjList.h:914
KeySet_helper(std::unordered_map< K, Element< E1 > * > const &um)
Definition: GraphAdjList.h:774
unordered_map< K, Element< E1 > * > * getVertices()
Return the graph nodes.
Definition: GraphAdjList.h:391
constVertexElementSet_listhelper vertexSet() const
Definition: GraphAdjList.h:980
Edge< K, E2 > getEdge(const K &src, const K &dest)
Get the edge between src and dest vertices.
Definition: GraphAdjList.h:443
const_iterator & operator++()
Definition: GraphAdjList.h:793
void setVertexData(const K &vertID, E1 const &data)
Loads vertex specific information for a graph vertex.
Definition: GraphAdjList.h:272
virtual SLelement * getNext()
Returns the next element in the list.
Definition: SLelement.h:75
const unordered_map< K, Element< E1 > * > * getVertices() const
Return the graph nodes - const version.
Definition: GraphAdjList.h:400
This is a helper class to return sets of vertices in a way that are iterable with range for loops....
Definition: GraphAdjList.h:845
const SLelement< Edge< K, E2 > > * getAdjacencyList(const K &k) const
Definition: GraphAdjList.h:499
VertexElementSet_listhelper(std::unordered_map< K, Element< E1 > * > &um)
Definition: GraphAdjList.h:849
KeySet_helper keySet() const
Definition: GraphAdjList.h:817
virtual ~GraphAdjList() override
Definition: GraphAdjList.h:133
ElementVisualizer * getVisualizer()
Get the element visualizer object.
Definition: Element.h:144
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
bool isEdge(const K &src, const K &dest)
Definition: GraphAdjList.h:231
const unordered_map< K, SLelement< Edge< K, E2 > > * > & getAdjacencyList() const
Return the adjacency list.
Definition: GraphAdjList.h:469
LinkVisualizer * getLinkVisualizer(const K &k1, const K &k2)
Returns the link visualizer corresponding to an edge. Returns the link visualizer corresponding to tw...
Definition: GraphAdjList.h:540
SLelement< Edge< K, E2 > >::SLelement_constlisthelper outgoingEdgeSetOf(K const &k) const
This method is useful for iterating through a set of outgoing edges from a vertex - const version.
Definition: GraphAdjList.h:835
E2 const & getEdgeData(const K &src, const K &dest) const
Gets edge data for the edge from "src" to "dest" - const version.
Definition: GraphAdjList.h:325
void addEdge(const K &src, const K &dest, const E2 &data=E2())
Definition: GraphAdjList.h:200
This helper class is used by the graph classes - GraphAdjList , GraphAdjMatrix - to keep track of edg...
Definition: Edge.h:36
void setEdgeData(const K &src, const K &dest, E2 &data)
Loads edge specific information for the edge from "src" to "dest".
Definition: GraphAdjList.h:359
std::string JSONencode(const T &d)
Definition: JSONutil.h:37