Saturday, 15 June 2013

java - Idea for a data structure to store 2D data? -


I have a large 2D grid, X-by-Y. Users of the application will add data about specific points on this grid. Unfortunately, the grid is too big because it can be implemented as a large X-by-Y array because the system on which it is running does not have enough memory.

What is a good way to implement that only the figures that have been added at those points are stored in memory?

My first idea was to make BST of data points

Then I concluded that it is not well balanced, if it is not well balanced, then I came with it Was, as if "(long) x and lt; <32 + y" will be used. The idea of ​​having a BST of comparative BST of the number will be compared to the external BST on the basis of its X values, internal BST. Comparing the internal BST scores will compare their Y values ​​(and they have the same x). So when the programmers want to see what is the point (5,6), then they will ask for the outer BST for 5. If an internal BST is present at that point then the programmer will question the internal BST for 6. Result

Edit: Regarding Hashmaps: Most hashmaps require an array for lookup. Someone says "data [hash (point)] = point ();" To set a point and then look for the pointer to see it swear it. The problem, however, is that the array should be the scope of the scope of the hash function. If this category is less than the total data points, which are added then they will either have no space in an overflow or not. Since I do not know the number of digits that will be added, I have the impression that this number will be less than a certain amount and then the array of that size must be set. Again, this indicates a very large array (although the originality is small if the assumption is that figures will be less than x * y). I want to linearly scale the amount of data like structure and do not take large amounts when empty.

What do I want a spray array, as some have mentioned, have they been implemented just like BST inside BST?

Edit 2: Maps & lt; & Gt; There is an interface if I was using the map so it looks like a trademark; & Gt; The best bet would be so I would end up with the trademark and lt; The tree-map & lt; Point & gt; & Gt ;, similar to map & lt; Click the & lt; Point & gt; & Gt; It is suggested that people have made it, which is basically a BST inside BST. Thanks for the info, however, because I did not know that the trademarks & lt; & Gt; Originally a BST's Java SDK.

Editing 3: For those who may be concerned about this, the selected answer is the best way. First of all, one should make a point square in which (x, y) is included and it implies comparable to the point (((long) x) 32) + y) Can be compared to. Then each point of a data will be TreeMap, it is efficient to search because it is in a balanced tree so that Entry (N) cost user can also query all this data, or Tremap Using the EnterSet () function, it sets the digits along with the data.

Finally, the implementation of this space-efficient and search-efficient sparse array, or in my case, a 2D array, which can also be operated efficiently.

You can use map & lt; Pairs, whatever & gt; (you have to write the add squared). If you need to iterate the data in a certain order, then pair comparative and use NavigableMap

No comments:

Post a Comment