Re: Are there any databases that can store multidiimensional boolean arrays?




"Robert Klemme" <bob.news@xxxxxxx> wrote in message
news:4gvjchF1pc7ubU1@xxxxxxxxxxxxxxxxx
Rhino wrote:
If you don't need these booleans for querying (i.e. as selection
criteria)
the simplest solution is probably to serialize these arrays into a BLOB
column. You could also convert them to a BitSet before insertion.

I'd never noticed the BitSet class before in several years of coding Java
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.

Okay, that's useful to know. And thanks VERY much for the sample code!

If you need to use boolean values from the array as select criteria it
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.

As I said, I'm helping someone else and I don't know if they want to use
these booleans as search criteria or not.

You gotta find out. :-)

I'll ask. Thanks for mentioning the possibility. It never occurred to me
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");
}
}



.



Relevant Pages

  • Re: Pascal-like set class
    ... > membership seem odd, because I pronounce the code "If element e is equal ... the reason I wrote it was because I wanted low-level control of the ... answer to your question is they wouldn't, except when the array is only one ... bitset, then the answer is pascal_set is more typesafe then bitset and I ...
    (comp.lang.cpp)
  • Re: Are there any databases that can store multidiimensional boolean arrays?
    ... the simplest solution is probably to serialize these arrays into a BLOB column. ... I'd never noticed the BitSet class before in several years of coding Java 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? ...
    (comp.lang.java.databases)
  • Re: Are there any databases that can store multidiimensional boolean arrays?
    ... This person wants to store a four dimensional boolean array, ... I'd never noticed the BitSet class before in several years of coding Java ...
    (comp.lang.java.databases)
  • Re: algorithm help
    ... i added a larger range 1000..5000 to the test set which should come ... closer to ara's problem at hand. ... Interestingly this brings the bitset approach back in play, ... Your approach has a clear advantage if ranges are fairly large compared to the overall number of elements in the array. ...
    (comp.lang.ruby)
  • Using <bitset>
    ... Is there a way to use <bitset> on an external array of bits (rather than ... bitset's built in _Array)? ...
    (microsoft.public.vc.stl)