简体   繁体   English

在数据库中存储BitSet数组的最佳方法?

[英]Best way to store an array of BitSet in database?

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. 我有一个要保留在数据库中的java.util.BitSet数组,但是我不知道什么是最好的方法。 To be precise i got x*y true or false value for every entry that i want to store. 准确地说,对于每个要存储的条目,我都有x*y true or false值。 I tought java.util.BitSet is a good call to try, but i dont really know how could i store it in database. 我强壮java.util.BitSet是一个很好的尝试,但我真的不知道如何将其存储在数据库中。

I'm using MySQL database with hibernate(with annotation). 我正在使用带有休眠(带有注释)的MySQL数据库。

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. 这个数据集中没有任何关系,问题是我有大量的“二维数组”,其中一个的大小约为360 * 180。

I also tried to make an image out of it, a monochrome pbm file is easy to make. 我还尝试用它制作图像,单色pbm文件很容易制作。 But still the data is not in the database and every time processing the saved "image" file is overkill i think and kinda slow. 但是仍然数据不在数据库中,我认为每次处理保存的“图像”文件都是过大的,而且有点慢。

you could have column of ints (or whatever the equivalent is)in your database. 您可以在数据库中包含ints列(或任何等效的列)。

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. 如果您有2列,并且假设每一列都是32位,则可以在第1行col 1 32位中输入,然后在第1行col 2中输入下32位,然后转到第2行col 1并重新开始,依此类推。

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 . 我正在考虑存储原始blob,并通过将修改后的位存储在单独的实体(新表或更多列)中来跟踪已修改的位。您有原始blob,然后是BitIndex:BitNewValue的映射。
A more appropriate framework for this is now map reduce . 现在,一个更合适的框架是map reduce But I can see how managing something like this can become a huge headache if many bits are changed. 但是我可以看到,如果更改很多内容,如何管理这样的事情将变得非常头疼。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM