9 namespace datastructure {
32 : array_data(nullptr), num_dims(0), dims{0, 0, 0}, size(0) {
36 if (array_data !=
nullptr)
46 : array_data(nullptr) {
47 int dim[] = {1, 1, sz};
58 if (dim[0] <= 0 || dim[1] <= 0 || dim[2] <= 0) {
59 cout <<
"Dimensions of array must be positive!" << endl
60 <<
"\tProvided dimensions: " << dim[0]
61 <<
"," << dim[1] <<
"," << dim[2] << endl;
68 size = dim[0] * dim[1] * dim[2];
71 if (array_data !=
nullptr)
109 return array_data[index];
120 return array_data[index];
130 array_data[ind] = el;
145 vector<const Element<E>*> nodes;
147 for (
int k = 0; k < size; k++) {
148 nodes.push_back(&array_data[k]);
161 generateJSON(nodes) +
171 const string generateJSON(
const vector<
const Element<E>*>& nodes)
const {
174 throw "Max allowed elements(for visualization) exceeded.. " +
175 to_string(nodes.size()) +
" Must be less than " +
181 unordered_map<const Element<E>*,
int> map{{
nullptr, -1}};
186 for (
const auto * e : nodes) {
187 if (map.emplace(e, i).second && ++i) {
190 nodes_JSON += e->getElementRepresentation() +
COMMA;
194 if (nodes_JSON.size()) {
195 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
The foundation of BRIDGES array types. It is not meant to be used directly by students.
Definition: Array.h:21
void setElement(int ind, Element< E > el)
Set the Element at index ind - 1D array.
Definition: Array.h:129
virtual const string getDataStructureRepresentation() const override final
Definition: Array.h:142
Array()
Definition: Array.h:31
void setSize(int nd, int *dim)
Set the size of the array.
Definition: Array.h:57
virtual const string getDStype() const override
Definition: Array.h:138
virtual ~Array()
Definition: Array.h:35
Array & operator=(const Array &)=delete
int const * getDimensions() const
Definition: Array.h:97
void getDimensions(int *dim)
Get the dimensions of the array.
Definition: Array.h:80
Element< E > & getElement(int index)
Definition: Array.h:108
Array(const Array &)=delete
Element< E > const & getElement(int index) const
Get the object at index index - 1D array.
Definition: Array.h:119
Array(int sz)
builds an array given the size
Definition: Array.h:45
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
std::string JSONencode(const T &d)
Definition: JSONutil.h:38
constexpr int MAX_ELEMENTS_ALLOWED
Definition: DataStructure.h:62
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