I just came up with a crazy idea to represent a 2D array using a tree or a map:
struct 2DArrayIndex { int x, y; ... };
class 2DArray : public QHash<2DArrayIndex, int> {
//...
};
struct 2DArrayIndex { int x, y; ... };
class 2DArray : public QHash<2DArrayIndex, int> {
//...
};
To copy to clipboard, switch view to plain text mode
One would need a custom method to access the data, so that it returned some default value if the item under specified coordinates would not be present, but apart from that we'd have a nice representation of a sparse 2D array. It wouldn't make sense to do it this way with dense arrays though...
Bookmarks