8 namespace datastructure {
44 string()) :
Element<E>(val, lab) {
58 SLelement(
const E& val = E(),
const string& lab =
string())
67 return "SinglyLinkedList";
95 this->
links.erase(next);
108 virtual const string getDataStructureRepresentation()
const override {
109 vector<const SLelement<E>*> nodes;
116 throw "Max allowed elements(for visualization) exceeded.. " +
117 to_string(nodes.size()) +
" Must be less than " +
121 pair<string, string> json_nodes_links =
generateJSON(nodes);
123 string sl_list_json =
170 unordered_map<const SLelement*, int> node_map { {
nullptr, -1} };
172 string nodes_JSON, links_JSON;
175 for (
const auto * e : nodes) {
176 if (node_map.emplace(e, i).second) {
179 nodes_JSON += e->getElementRepresentation() +
COMMA;
183 node_map.erase(
nullptr);
184 if (nodes_JSON.size()) {
185 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
188 for (
unsigned int k = 0; k < nodes.size(); k++) {
189 if (nodes[k]->
next !=
nullptr) {
191 to_string(node_map[nodes[k]]),
192 to_string(node_map[nodes[k]->
next]) ) +
COMMA;
197 if (links_JSON.size()) {
198 links_JSON = links_JSON.erase(links_JSON.size() - 1);
201 return pair<string, string> (nodes_JSON, links_JSON);
263 unordered_set<const SLelement<E>*> visited;
268 while (it !=
nullptr && visited.emplace(it).second) {
302 return this->current != it.current;
359 return this->current != it.current;
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:74
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:51
static const string getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest)
Definition: Element.h:310
unordered_map< Element *, LinkVisualizer > links
Definition: Element.h:92
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:207
Definition: SLelement.h:350
iterator & operator++()
Definition: SLelement.h:366
iterator(typename bridges::datastructure::SLelement< E > const *c)
Definition: SLelement.h:354
bool operator!=(const iterator &it) const
Definition: SLelement.h:358
E const & operator*() const
Definition: SLelement.h:362
These are helper classes for SLelement for easy iteration.
Definition: SLelement.h:342
iterator begin()
Definition: SLelement.h:372
iterator end()
Definition: SLelement.h:376
SLelement_constlisthelper(typename bridges::datastructure::SLelement< E > const *s)
Definition: SLelement.h:346
Definition: SLelement.h:294
iterator(typename bridges::datastructure::SLelement< E > *c)
Definition: SLelement.h:297
E const & operator*() const
Definition: SLelement.h:305
bool operator!=(const iterator &it) const
Definition: SLelement.h:301
iterator & operator++()
Definition: SLelement.h:313
These are helper classes for SLelement for easy iteration.
Definition: SLelement.h:286
iterator begin()
Definition: SLelement.h:324
iterator end()
Definition: SLelement.h:328
SLelement_listhelper(typename bridges::datastructure::SLelement< E > *s)
Definition: SLelement.h:290
The singly linked list element, derived from Element.
Definition: SLelement.h:26
SLelement(const E &val=E(), const string &lab=string())
Constructs an slelement with the provided value.
Definition: SLelement.h:58
virtual const string getDStype() const override
Returns the data structure name.
Definition: SLelement.h:66
virtual const SLelement * getNext() const
Returns the next element in the list - Constant version.
Definition: SLelement.h:83
virtual const pair< string, string > generateJSON(vector< const SLelement< E > * > nodes) const
Generates the JSON representation of the element.
Definition: SLelement.h:165
SLelement(SLelement *next, const E &val=E(), const string &lab=string())
Constructs an slelement with the provided value.
Definition: SLelement.h:43
void setNext(SLelement *n)
Definition: SLelement.h:92
virtual void getListElements(vector< const SLelement< E > * > &nodes) const
Get the list of nodes.
Definition: SLelement.h:260
virtual SLelement * getNext()
Returns the next element in the list.
Definition: SLelement.h:74
SLelement * next
Definition: SLelement.h:29
typename SLelement< E >::SLelement_listhelper SLelement_List
Definition: SLelement.h:384
constexpr int MAX_ELEMENTS_ALLOWED
Definition: DataStructure.h:62
typename SLelement< E >::SLelement_constlisthelper SLelement_ConstList
Definition: SLelement.h:386
Support for drawing Bar charts.
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50