Re: Are there any databases that can store multidiimensional boolean arrays?
- From: "Rhino" <no.offline.contact.please@xxxxxxxxxx>
- Date: Tue, 4 Jul 2006 15:11:54 -0400
"Robert Klemme" <bob.news@xxxxxxx> wrote in message
news:4gvjchF1pc7ubU1@xxxxxxxxxxxxxxxxx
Rhino wrote:Okay, that's useful to know. And thanks VERY much for the sample code!
If you don't need these booleans for querying (i.e. as selectionI'd never noticed the BitSet class before in several years of coding Java
criteria)
the simplest solution is probably to serialize these arrays into a BLOB
column. You could also convert them to a BitSet before insertion.
but I just took a look at it in the API. Is there any particular reason
why
it is better than just turning a boolean array into a String of T's and
F's.
I assume it uses less space since bits are smaller than Strings but
wouldn't
it get a bit cumbersome to have to have a Bitset within a Bitset within a
Bitset within a Bitset just to represent this array?
No, convert them to a *single* BitSet - I didn't mention hieararchies of
BitSet (which is impossible btw). If dimensions can vary it's easy to
write a wrapper class that holds dimension info plus the single BitSet
and also does all the conversion stuff.
I'll ask. Thanks for mentioning the possibility. It never occurred to meIf you need to use boolean values from the array as select criteria itAs I said, I'm helping someone else and I don't know if they want to use
gets more complicated. One thing you *could* do is to have a table with
idx_1, idx_2, idx_2, bool, i.e. store the indexes in the table. But
this
will burn a lot of mem.
these booleans as search criteria or not.
You gotta find out. :-)
that he might mean the booleans to be search conditions and it should have!
--
Rhino
--------------------------------------------------------------------------------
package bits;
import java.io.Serializable;
import java.util.BitSet;
public class BoolArrayWrapper implements Serializable {
private BitSet data;
private int dim1, dim2, dim3;
public BoolArrayWrapper( boolean[][][] bits ) {
dim1 = bits.length;
dim2 = bits[0].length;
dim3 = bits[0][0].length;
BitSet tmp = new BitSet( dim1 * dim2 * dim3 );
for ( int i1 = 0; i1 < dim1; ++i1 ) {
for ( int i2 = 0; i2 < dim2; ++i2 ) {
for ( int i3 = 0; i3 < dim3; ++i3 ) {
tmp.set( i1 + dim1 * ( i2 + dim2 * i3 ),
bits[i1][i2][i3] );
}
}
}
data = tmp;
}
public boolean[][][] toBooleanArray() {
boolean[][][] bits = new boolean[dim1][dim2][dim3];
for ( int i1 = 0; i1 < dim1; ++i1 ) {
for ( int i2 = 0; i2 < dim2; ++i2 ) {
for ( int i3 = 0; i3 < dim3; ++i3 ) {
bits[i1][i2][i3] = data.get( i1 + dim1 * ( i2 + dim2 *
i3 ) );
}
}
}
return bits;
}
public static void main( String args[] ) {
boolean bits[][][] = { { { true, true }, { true, true }, { true,
true } },
{ { false, false }, { false, false }, { false, false }
},
};
BoolArrayWrapper wr = new BoolArrayWrapper(bits);
boolean bits2[][][] = wr.toBooleanArray();
System.out.println("done");
}
}
.
- References:
- Are there any databases that can store multidiimensional boolean arrays?
- From: Rhino
- Re: Are there any databases that can store multidiimensional boolean arrays?
- From: Robert Klemme
- Re: Are there any databases that can store multidiimensional boolean arrays?
- From: Rhino
- Re: Are there any databases that can store multidiimensional boolean arrays?
- From: Robert Klemme
- Are there any databases that can store multidiimensional boolean arrays?
- Prev by Date: Re: Are there any databases that can store multidiimensional boolean arrays?
- Next by Date: Re: Are there any databases that can store multidiimensional boolean arrays?
- Previous by thread: Re: Are there any databases that can store multidiimensional boolean arrays?
- Next by thread: Re: Are there any databases that can store multidiimensional boolean arrays?
- Index(es):
Relevant Pages
|
|