9 namespace datastructure {
43 string()) :
Element<E>(val, lab) {
54 SLelement(
const E& val = E(),
const string& lab =
string())
63 return "SinglyLinkedList";
91 this->
links.erase(next);
104 virtual const string getDataStructureRepresentation()
const override {
106 vector<const SLelement<E>*> nodes;
113 throw "Max allowed elements(for visualization) exceeded.. " +
114 to_string(nodes.size()) +
" Must be less than " +
118 pair<string, string> json_nodes_links =
generateJSON(nodes);
120 string sl_list_json =
141 unordered_map<const SLelement*, int> node_map { {
nullptr, -1} };
143 string nodes_JSON, links_JSON;
146 for (
const auto* e : nodes) {
147 if (node_map.emplace(e, i).second) {
150 nodes_JSON += e->getElementRepresentation() +
COMMA;
154 node_map.erase(
nullptr);
155 if (nodes_JSON.size()) {
156 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
159 for (
unsigned int k = 0; k < nodes.size(); k++) {
160 if (nodes[k]->next !=
nullptr) {
162 to_string(node_map[nodes[k]]),
163 to_string(node_map[nodes[k]->next]) ) +
COMMA;
168 if (links_JSON.size()) {
169 links_JSON = links_JSON.erase(links_JSON.size() - 1);
172 return pair<string, string> (nodes_JSON, links_JSON);
183 unordered_set<const SLelement<E>*> visited;
188 while (it !=
nullptr && visited.emplace(it).second) {
216 return this->current != it.current;
266 return this->current != it.current;
Definition: SLelement.h:257
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:44
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
static const string getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest)
Definition: Element.h:256
constexpr int MAX_ELEMENTS_ALLOWED
Definition: DataStructure.h:61
bool operator!=(const iterator &it) const
Definition: SLelement.h:265
typename SLelement< E >::SLelement_constlisthelper SLelement_ConstList
Definition: SLelement.h:294
iterator begin()
Definition: SLelement.h:238
virtual const pair< string, string > generateJSON(vector< const SLelement< E > *> nodes) const
Definition: SLelement.h:136
E const & operator*() const
Definition: SLelement.h:219
const string COLON
Definition: DataStructure.h:51
E const & getValue() const
Definition: Element.h:195
iterator(typename bridges::datastructure::SLelement< E > const *c)
Definition: SLelement.h:261
SLelement * next
Definition: SLelement.h:30
SLelement_listhelper(typename bridges::datastructure::SLelement< E > *s)
Definition: SLelement.h:204
const string OPEN_BOX
Definition: DataStructure.h:54
iterator(typename bridges::datastructure::SLelement< E > *c)
Definition: SLelement.h:211
const string CLOSE_CURLY
Definition: DataStructure.h:53
virtual const SLelement * getNext() const
Definition: SLelement.h:79
these are helper classes for SLelement for easy iteration in a range for loop. It is not meant to be ...
Definition: SLelement.h:249
iterator begin()
Definition: SLelement.h:279
virtual void getListElements(vector< const SLelement< E > *> &nodes) const
Definition: SLelement.h:180
The singly linked list element, derived from Element.
Definition: SLelement.h:27
bool operator!=(const iterator &it) const
Definition: SLelement.h:215
iterator end()
Definition: SLelement.h:283
SLelement_constlisthelper(typename bridges::datastructure::SLelement< E > const *s)
Definition: SLelement.h:253
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
Definition: SLelement.h:208
const string CLOSE_BOX
Definition: DataStructure.h:55
typename SLelement< E >::SLelement_listhelper SLelement_List
Definition: SLelement.h:292
virtual SLelement * getNext()
Definition: SLelement.h:70
these are helper classes for SLelement for easy iteration in a range for loop. It is not meant to be ...
Definition: SLelement.h:200
SLelement(const E &val=E(), const string &lab=string())
Definition: SLelement.h:54
E const & operator*() const
Definition: SLelement.h:269
unordered_map< Element *, LinkVisualizer > links
Definition: Element.h:87
virtual const string getDStype() const override
Definition: SLelement.h:62
iterator end()
Definition: SLelement.h:242
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
SLelement(SLelement *next, const E &val=E(), const string &lab=string())
Definition: SLelement.h:42
iterator & operator++()
Definition: SLelement.h:227
void setNext(SLelement *n)
Definition: SLelement.h:88
iterator & operator++()
Definition: SLelement.h:273