Best way to store an array of BitSet in database?

萝らか妹 提交于 2020-01-14 12:36:31

问题


I got an array of java.util.BitSet that i want to persist in my database, but i don't know whats the best way to do it. To be precise i got x*y true or false value for every entry that i want to store. I tought java.util.BitSet is a good call to try, but i dont really know how could i store it in database.

I'm using MySQL database with hibernate(with annotation).

This is how i initialize my map:

 Bitset[] map = new BitSet[x];
 for (int i = 0; i < x; i++) {
     map[i] = new BitSet(y);
 }

Update:

There is no relation in this dataset, and the problem is that i have tons of these "2 dimensional arrays" and one piece is around 360*180 in size.

I also tried to make an image out of it, a monochrome pbm file is easy to make. But still the data is not in the database and every time processing the saved "image" file is overkill i think and kinda slow.


回答1:


you could have column of ints (or whatever the equivalent is)in your database.

If you have 2 columns and assuming each column is 32 bits, you can put in row 1 col 1 32 bits, then row 1 col 2 the next 32, then you go to row 2 col 1 and start over and so on.

Is there any relationship between these bits that you can exploit? Or it's just a big dump?

Note: I used this technique to pack/compress data so it might not be exactly what you need.

EDIT:
I'm thinking of storing the raw blob and tracking the modified bits by storing them in a separate entity (new table or more columns) You have the raw blob, then a mapping of BitIndex:BitNewValue.
A more appropriate framework for this is now map reduce. But I can see how managing something like this can become a huge headache if many bits are changed.



来源:https://stackoverflow.com/questions/9788689/best-way-to-store-an-array-of-bitset-in-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!