Best way to store a BitSet array in a database?

I have a java.util.BitSet array that I want to store in my database, but I don't know how best to do this. To be precise, I got x*y true or false for every record I want to keep. I hardt java.util.BitSet is a good call, but I really don't know how I can store it in the database.

I am using a MySQL database with hibernation (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 data set, and the problem is that I have tons of these "2-dimensional arrays", and one part is about 360 * 180.

I also tried to make an image from it, to make a simple monochrome pbm file. But still, the data is not in the database, and every time the processing of the saved “image” file is redundant, I think it is a slow process.

+4
source share
1 answer

you may have an int column (or any other equivalent) in your database.

If you have 2 columns and it is assumed that each column is 32 bits, you can enter row 1 col 1 32 bits, then row 1 col 2 next 32, then you go to row 2 col 1 and start over, etc.

Is there any correlation between these bits that you can use? Or is it just a big dump?

Note. I used this method for packing / compressing data so that it cannot exactly match you.

EDIT:
I am thinking of storing an raw blob and keeping track of changed bits, storing them in a separate object (new table or more columns) You have a raw blob, then displaying BitIndex:BitNewValue .
A more suitable structure for this is now to reduce the map . But I see how managing something like this can be a huge headache if a lot of bits change.

+2
source

Source: https://habr.com/ru/post/1402451/


All Articles