9 namespace datastructure {
45 string()) :
Element<E>(val, lab) {
59 SLelement(
const E& val = E(),
const string& lab =
string())
68 return "SinglyLinkedList";
96 this->
links.erase(next);
109 virtual const string getDataStructureRepresentation()
const override {
111 vector<const SLelement<E>*> nodes;
118 throw "Max allowed elements(for visualization) exceeded.. " +
119 to_string(nodes.size()) +
" Must be less than " +
123 pair<string, string> json_nodes_links =
generateJSON(nodes);
125 string sl_list_json =
148 unordered_map<const SLelement*, int> node_map { {
nullptr, -1} };
150 string nodes_JSON, links_JSON;
153 for (
const auto* e : nodes) {
154 if (node_map.emplace(e, i).second) {
157 nodes_JSON += e->getElementRepresentation() +
COMMA;
161 node_map.erase(
nullptr);
162 if (nodes_JSON.size()) {
163 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
166 for (
unsigned int k = 0; k < nodes.size(); k++) {
167 if (nodes[k]->next !=
nullptr) {
169 to_string(node_map[nodes[k]]),
170 to_string(node_map[nodes[k]->next]) ) +
COMMA;
175 if (links_JSON.size()) {
176 links_JSON = links_JSON.erase(links_JSON.size() - 1);
179 return pair<string, string> (nodes_JSON, links_JSON);
190 unordered_set<const SLelement<E>*> visited;
195 while (it !=
nullptr && visited.emplace(it).second) {
229 return this->current != it.current;
287 return this->current != it.current;
Definition: SLelement.h:278
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:52
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:273
constexpr int MAX_ELEMENTS_ALLOWED
Definition: DataStructure.h:61
bool operator!=(const iterator &it) const
Definition: SLelement.h:286
typename SLelement< E >::SLelement_constlisthelper SLelement_ConstList
Definition: SLelement.h:315
iterator begin()
Definition: SLelement.h:251
virtual const pair< string, string > generateJSON(vector< const SLelement< E > *> nodes) const
Generates the JSON representation of the element.
Definition: SLelement.h:143
E const & operator*() const
Definition: SLelement.h:232
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 bridges::datastructure::SLelement< E > const *c)
Definition: SLelement.h:282
SLelement * next
Definition: SLelement.h:30
SLelement_listhelper(typename bridges::datastructure::SLelement< E > *s)
Definition: SLelement.h:217
const string OPEN_BOX
Definition: DataStructure.h:54
iterator(typename bridges::datastructure::SLelement< E > *c)
Definition: SLelement.h:224
const string CLOSE_CURLY
Definition: DataStructure.h:53
virtual const SLelement * getNext() const
Returns the next element in the list - Constant version.
Definition: SLelement.h:84
These are helper classes for SLelement for easy iteration.
Definition: SLelement.h:270
iterator begin()
Definition: SLelement.h:300
virtual void getListElements(vector< const SLelement< E > *> &nodes) const
Get the list of nodes.
Definition: SLelement.h:187
The singly linked list element, derived from Element.
Definition: SLelement.h:27
bool operator!=(const iterator &it) const
Definition: SLelement.h:228
iterator end()
Definition: SLelement.h:304
SLelement_constlisthelper(typename bridges::datastructure::SLelement< E > const *s)
Definition: SLelement.h:274
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:221
const string CLOSE_BOX
Definition: DataStructure.h:55
typename SLelement< E >::SLelement_listhelper SLelement_List
Definition: SLelement.h:313
virtual SLelement * getNext()
Returns the next element in the list.
Definition: SLelement.h:75
These are helper classes for SLelement for easy iteration.
Definition: SLelement.h:213
SLelement(const E &val=E(), const string &lab=string())
Constructs an slelement with the provided value.
Definition: SLelement.h:59
E const & operator*() const
Definition: SLelement.h:290
unordered_map< Element *, LinkVisualizer > links
Definition: Element.h:95
virtual const string getDStype() const override
Returns the data structure name.
Definition: SLelement.h:67
iterator end()
Definition: SLelement.h:255
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())
Constructs an slelement with the provided value.
Definition: SLelement.h:44
iterator & operator++()
Definition: SLelement.h:240
void setNext(SLelement *n)
Definition: SLelement.h:93
iterator & operator++()
Definition: SLelement.h:294