LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A data structure problem (https://www.linuxquestions.org/questions/programming-9/a-data-structure-problem-608877/)

Asuralm 12-24-2007 07:23 AM

A data structure problem
 
Dear All:

I want to build a 3D Euclidean space by using an index accessible class like
Code:

3DSpace<T*> my_space[1000][1000][1000];
my_space[100][50][25] = ....;

The space should be able to contain more than 1 million gridpoints although most of them will be NULL. Here I am looking for a method which can allocate memory for the gridpoints with content and meantime do not allocate memory for those gridpoints which are NULL. As this is probably the only way to hold such a large data space. For example:

Code:

T* grid_point;
my_space[100][50][25] = grid_point;
T* get_point = my_space[0][0][0];
// here get_point should give a NULL pointer. As (0,0,0) is not given a value.

I tried the STL library hash_map, but the drawback of the hash_map is:
Code:

hash_map<int, float> my_hash;
my_hash[0] = 10.5;
cout << "size of my_hash=" << my_hash.size() << endl;
// This gives: size of my_hash=1;
float get_number = my_hash[10];
// obviously this should throw an exception as my_hash[10] is not given a value.
// But the hash_map doesn't throw an exception and increases the size of the container
cout << "size of my_hash=" << my_hash.size() << endl;
// this gives: size of my_hash=2;

This is a really bizarre behaviour which is definitely not what I wanted.
Does anyone have any idea to help me with this problem please?

Thanks
Merry Christmas!!!

[/code]

PTrenholme 12-24-2007 07:49 AM

1) Look at "sparse matrix" libraries.
2) Consider using a tree list where the "leaf" is your data and the address your coordinates, and your "look up" process process does a search in the tree for the coordinate token. If you keep the tree sorted, or hashed, or both, the look-up should be fairly fast.


All times are GMT -5. The time now is 07:29 AM.