How to make BitSet to be not simplified [JAVA]
up vote
3
down vote
favorite
I am using BitSet to represent possible hours where lectures are filled in, the case is that when you put to false the corner bits, they are simplified, this means that they are not anymore in the BitSet. How can I ask BitSet to not simplify?
To make my explanation clearer this is the code:
for(Map.Entry<GrupAssig, BitSet> entry : bitsetPerGrup.entrySet()){
BitSet bitset = entry.getValue();
//n franges per dia
int numFranges = UnitatDocent.getNumFranges();
int indexDia = this.dia.id() * numFranges;
bitset.clear(indexDia, indexDia+numFranges);
}
Imagine that the bitset has 60 bits by default, and numFranges=12 and this.dia.id()=4. This would make the last twelve bits set to 0. The result I get is:
111111111111111111111111111111111111111111111111
But if this.dia.id()=3 I get:
11111111111111111111111111111111111100000000000011111111111
And you can print the BitSet this way:
public static void printBitset(BitSet b) {
StringBuilder s = new StringBuilder();
for( int i = 0; i < b.length(); i++ )
{
s.append( b.get( i ) == true ? 1 : 0 );
}
System.out.println( s );
}
Which demonstrates what I am saying.
Thank you.
java bit bitset
|
show 4 more comments
up vote
3
down vote
favorite
I am using BitSet to represent possible hours where lectures are filled in, the case is that when you put to false the corner bits, they are simplified, this means that they are not anymore in the BitSet. How can I ask BitSet to not simplify?
To make my explanation clearer this is the code:
for(Map.Entry<GrupAssig, BitSet> entry : bitsetPerGrup.entrySet()){
BitSet bitset = entry.getValue();
//n franges per dia
int numFranges = UnitatDocent.getNumFranges();
int indexDia = this.dia.id() * numFranges;
bitset.clear(indexDia, indexDia+numFranges);
}
Imagine that the bitset has 60 bits by default, and numFranges=12 and this.dia.id()=4. This would make the last twelve bits set to 0. The result I get is:
111111111111111111111111111111111111111111111111
But if this.dia.id()=3 I get:
11111111111111111111111111111111111100000000000011111111111
And you can print the BitSet this way:
public static void printBitset(BitSet b) {
StringBuilder s = new StringBuilder();
for( int i = 0; i < b.length(); i++ )
{
s.append( b.get( i ) == true ? 1 : 0 );
}
System.out.println( s );
}
Which demonstrates what I am saying.
Thank you.
java bit bitset
What do you mean by corner bits? The ones at the range extremes? What do you mean by simplify?
– Michael Krause
Nov 10 at 18:27
Why do you care about the implementation details? It doesn't make any difference to the results of the methods you can call.
– Louis Wasserman
Nov 10 at 18:31
Yes, I refer to the range extremes. By simplifying I mean that they are erased, given a bitset of size 60 bits, if you set the first ten bits to false, they are not anymore in the set. But if you set the middle bits to false, they stay there.
– Marc43
Nov 10 at 18:34
Louis, I thought that too, but if you do what I said (setting the ten first bits to false, for example) and the you do:bitset.get(0)
you will get true, and this is not what should happend for what I need.
– Marc43
Nov 10 at 18:39
Posting your code would help. One thing I can say is that the length() method may not do what you think it will do because it's based off of the BitSet's cardinality. In other words, length will look for a 1 at the greatest index to determine length. If all bits are set to false, length() will return 0.
– Michael Krause
Nov 10 at 18:55
|
show 4 more comments
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am using BitSet to represent possible hours where lectures are filled in, the case is that when you put to false the corner bits, they are simplified, this means that they are not anymore in the BitSet. How can I ask BitSet to not simplify?
To make my explanation clearer this is the code:
for(Map.Entry<GrupAssig, BitSet> entry : bitsetPerGrup.entrySet()){
BitSet bitset = entry.getValue();
//n franges per dia
int numFranges = UnitatDocent.getNumFranges();
int indexDia = this.dia.id() * numFranges;
bitset.clear(indexDia, indexDia+numFranges);
}
Imagine that the bitset has 60 bits by default, and numFranges=12 and this.dia.id()=4. This would make the last twelve bits set to 0. The result I get is:
111111111111111111111111111111111111111111111111
But if this.dia.id()=3 I get:
11111111111111111111111111111111111100000000000011111111111
And you can print the BitSet this way:
public static void printBitset(BitSet b) {
StringBuilder s = new StringBuilder();
for( int i = 0; i < b.length(); i++ )
{
s.append( b.get( i ) == true ? 1 : 0 );
}
System.out.println( s );
}
Which demonstrates what I am saying.
Thank you.
java bit bitset
I am using BitSet to represent possible hours where lectures are filled in, the case is that when you put to false the corner bits, they are simplified, this means that they are not anymore in the BitSet. How can I ask BitSet to not simplify?
To make my explanation clearer this is the code:
for(Map.Entry<GrupAssig, BitSet> entry : bitsetPerGrup.entrySet()){
BitSet bitset = entry.getValue();
//n franges per dia
int numFranges = UnitatDocent.getNumFranges();
int indexDia = this.dia.id() * numFranges;
bitset.clear(indexDia, indexDia+numFranges);
}
Imagine that the bitset has 60 bits by default, and numFranges=12 and this.dia.id()=4. This would make the last twelve bits set to 0. The result I get is:
111111111111111111111111111111111111111111111111
But if this.dia.id()=3 I get:
11111111111111111111111111111111111100000000000011111111111
And you can print the BitSet this way:
public static void printBitset(BitSet b) {
StringBuilder s = new StringBuilder();
for( int i = 0; i < b.length(); i++ )
{
s.append( b.get( i ) == true ? 1 : 0 );
}
System.out.println( s );
}
Which demonstrates what I am saying.
Thank you.
java bit bitset
java bit bitset
edited Nov 10 at 19:32
asked Nov 10 at 18:20
Marc43
992310
992310
What do you mean by corner bits? The ones at the range extremes? What do you mean by simplify?
– Michael Krause
Nov 10 at 18:27
Why do you care about the implementation details? It doesn't make any difference to the results of the methods you can call.
– Louis Wasserman
Nov 10 at 18:31
Yes, I refer to the range extremes. By simplifying I mean that they are erased, given a bitset of size 60 bits, if you set the first ten bits to false, they are not anymore in the set. But if you set the middle bits to false, they stay there.
– Marc43
Nov 10 at 18:34
Louis, I thought that too, but if you do what I said (setting the ten first bits to false, for example) and the you do:bitset.get(0)
you will get true, and this is not what should happend for what I need.
– Marc43
Nov 10 at 18:39
Posting your code would help. One thing I can say is that the length() method may not do what you think it will do because it's based off of the BitSet's cardinality. In other words, length will look for a 1 at the greatest index to determine length. If all bits are set to false, length() will return 0.
– Michael Krause
Nov 10 at 18:55
|
show 4 more comments
What do you mean by corner bits? The ones at the range extremes? What do you mean by simplify?
– Michael Krause
Nov 10 at 18:27
Why do you care about the implementation details? It doesn't make any difference to the results of the methods you can call.
– Louis Wasserman
Nov 10 at 18:31
Yes, I refer to the range extremes. By simplifying I mean that they are erased, given a bitset of size 60 bits, if you set the first ten bits to false, they are not anymore in the set. But if you set the middle bits to false, they stay there.
– Marc43
Nov 10 at 18:34
Louis, I thought that too, but if you do what I said (setting the ten first bits to false, for example) and the you do:bitset.get(0)
you will get true, and this is not what should happend for what I need.
– Marc43
Nov 10 at 18:39
Posting your code would help. One thing I can say is that the length() method may not do what you think it will do because it's based off of the BitSet's cardinality. In other words, length will look for a 1 at the greatest index to determine length. If all bits are set to false, length() will return 0.
– Michael Krause
Nov 10 at 18:55
What do you mean by corner bits? The ones at the range extremes? What do you mean by simplify?
– Michael Krause
Nov 10 at 18:27
What do you mean by corner bits? The ones at the range extremes? What do you mean by simplify?
– Michael Krause
Nov 10 at 18:27
Why do you care about the implementation details? It doesn't make any difference to the results of the methods you can call.
– Louis Wasserman
Nov 10 at 18:31
Why do you care about the implementation details? It doesn't make any difference to the results of the methods you can call.
– Louis Wasserman
Nov 10 at 18:31
Yes, I refer to the range extremes. By simplifying I mean that they are erased, given a bitset of size 60 bits, if you set the first ten bits to false, they are not anymore in the set. But if you set the middle bits to false, they stay there.
– Marc43
Nov 10 at 18:34
Yes, I refer to the range extremes. By simplifying I mean that they are erased, given a bitset of size 60 bits, if you set the first ten bits to false, they are not anymore in the set. But if you set the middle bits to false, they stay there.
– Marc43
Nov 10 at 18:34
Louis, I thought that too, but if you do what I said (setting the ten first bits to false, for example) and the you do:
bitset.get(0)
you will get true, and this is not what should happend for what I need.– Marc43
Nov 10 at 18:39
Louis, I thought that too, but if you do what I said (setting the ten first bits to false, for example) and the you do:
bitset.get(0)
you will get true, and this is not what should happend for what I need.– Marc43
Nov 10 at 18:39
Posting your code would help. One thing I can say is that the length() method may not do what you think it will do because it's based off of the BitSet's cardinality. In other words, length will look for a 1 at the greatest index to determine length. If all bits are set to false, length() will return 0.
– Michael Krause
Nov 10 at 18:55
Posting your code would help. One thing I can say is that the length() method may not do what you think it will do because it's based off of the BitSet's cardinality. In other words, length will look for a 1 at the greatest index to determine length. If all bits are set to false, length() will return 0.
– Michael Krause
Nov 10 at 18:55
|
show 4 more comments
1 Answer
1
active
oldest
votes
up vote
3
down vote
Here's the documentation for BitSet.length:
length()
Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one.
If you need to print out a certain number of bits (e.g. 60) then use a constant instead of ".length()" for your loop. You can call ".get(index)" on any index regardless of the length and it will give you the result for that bit.
For instance the following code produces "0000011000":
import java.util.BitSet;
public class Main {
public static void main(String args) {
BitSet bits = new BitSet();
bits.set(5);
bits.set(6);
StringBuilder bitString = new StringBuilder();
for (int i = 0; i < 10; i++) {
bitString.append(bits.get(i) ? "1" : "0");
}
System.out.println(bitString.toString());
}
}
Then imagine that the problem happens for the first bits, this would not work
– Marc43
Nov 10 at 22:18
1
I worked pretty heavily with the BitSet class a few years ago, and I don't believe that this problem exists for the first bits. If you think it does, please show a simple example that demonstrates this.
– Ryan C
Nov 10 at 22:21
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Here's the documentation for BitSet.length:
length()
Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one.
If you need to print out a certain number of bits (e.g. 60) then use a constant instead of ".length()" for your loop. You can call ".get(index)" on any index regardless of the length and it will give you the result for that bit.
For instance the following code produces "0000011000":
import java.util.BitSet;
public class Main {
public static void main(String args) {
BitSet bits = new BitSet();
bits.set(5);
bits.set(6);
StringBuilder bitString = new StringBuilder();
for (int i = 0; i < 10; i++) {
bitString.append(bits.get(i) ? "1" : "0");
}
System.out.println(bitString.toString());
}
}
Then imagine that the problem happens for the first bits, this would not work
– Marc43
Nov 10 at 22:18
1
I worked pretty heavily with the BitSet class a few years ago, and I don't believe that this problem exists for the first bits. If you think it does, please show a simple example that demonstrates this.
– Ryan C
Nov 10 at 22:21
add a comment |
up vote
3
down vote
Here's the documentation for BitSet.length:
length()
Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one.
If you need to print out a certain number of bits (e.g. 60) then use a constant instead of ".length()" for your loop. You can call ".get(index)" on any index regardless of the length and it will give you the result for that bit.
For instance the following code produces "0000011000":
import java.util.BitSet;
public class Main {
public static void main(String args) {
BitSet bits = new BitSet();
bits.set(5);
bits.set(6);
StringBuilder bitString = new StringBuilder();
for (int i = 0; i < 10; i++) {
bitString.append(bits.get(i) ? "1" : "0");
}
System.out.println(bitString.toString());
}
}
Then imagine that the problem happens for the first bits, this would not work
– Marc43
Nov 10 at 22:18
1
I worked pretty heavily with the BitSet class a few years ago, and I don't believe that this problem exists for the first bits. If you think it does, please show a simple example that demonstrates this.
– Ryan C
Nov 10 at 22:21
add a comment |
up vote
3
down vote
up vote
3
down vote
Here's the documentation for BitSet.length:
length()
Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one.
If you need to print out a certain number of bits (e.g. 60) then use a constant instead of ".length()" for your loop. You can call ".get(index)" on any index regardless of the length and it will give you the result for that bit.
For instance the following code produces "0000011000":
import java.util.BitSet;
public class Main {
public static void main(String args) {
BitSet bits = new BitSet();
bits.set(5);
bits.set(6);
StringBuilder bitString = new StringBuilder();
for (int i = 0; i < 10; i++) {
bitString.append(bits.get(i) ? "1" : "0");
}
System.out.println(bitString.toString());
}
}
Here's the documentation for BitSet.length:
length()
Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one.
If you need to print out a certain number of bits (e.g. 60) then use a constant instead of ".length()" for your loop. You can call ".get(index)" on any index regardless of the length and it will give you the result for that bit.
For instance the following code produces "0000011000":
import java.util.BitSet;
public class Main {
public static void main(String args) {
BitSet bits = new BitSet();
bits.set(5);
bits.set(6);
StringBuilder bitString = new StringBuilder();
for (int i = 0; i < 10; i++) {
bitString.append(bits.get(i) ? "1" : "0");
}
System.out.println(bitString.toString());
}
}
edited Nov 10 at 22:29
answered Nov 10 at 19:57
Ryan C
644110
644110
Then imagine that the problem happens for the first bits, this would not work
– Marc43
Nov 10 at 22:18
1
I worked pretty heavily with the BitSet class a few years ago, and I don't believe that this problem exists for the first bits. If you think it does, please show a simple example that demonstrates this.
– Ryan C
Nov 10 at 22:21
add a comment |
Then imagine that the problem happens for the first bits, this would not work
– Marc43
Nov 10 at 22:18
1
I worked pretty heavily with the BitSet class a few years ago, and I don't believe that this problem exists for the first bits. If you think it does, please show a simple example that demonstrates this.
– Ryan C
Nov 10 at 22:21
Then imagine that the problem happens for the first bits, this would not work
– Marc43
Nov 10 at 22:18
Then imagine that the problem happens for the first bits, this would not work
– Marc43
Nov 10 at 22:18
1
1
I worked pretty heavily with the BitSet class a few years ago, and I don't believe that this problem exists for the first bits. If you think it does, please show a simple example that demonstrates this.
– Ryan C
Nov 10 at 22:21
I worked pretty heavily with the BitSet class a few years ago, and I don't believe that this problem exists for the first bits. If you think it does, please show a simple example that demonstrates this.
– Ryan C
Nov 10 at 22:21
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242039%2fhow-to-make-bitset-to-be-not-simplified-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by corner bits? The ones at the range extremes? What do you mean by simplify?
– Michael Krause
Nov 10 at 18:27
Why do you care about the implementation details? It doesn't make any difference to the results of the methods you can call.
– Louis Wasserman
Nov 10 at 18:31
Yes, I refer to the range extremes. By simplifying I mean that they are erased, given a bitset of size 60 bits, if you set the first ten bits to false, they are not anymore in the set. But if you set the middle bits to false, they stay there.
– Marc43
Nov 10 at 18:34
Louis, I thought that too, but if you do what I said (setting the ten first bits to false, for example) and the you do:
bitset.get(0)
you will get true, and this is not what should happend for what I need.– Marc43
Nov 10 at 18:39
Posting your code would help. One thing I can say is that the length() method may not do what you think it will do because it's based off of the BitSet's cardinality. In other words, length will look for a 1 at the greatest index to determine length. If all bits are set to false, length() will return 0.
– Michael Krause
Nov 10 at 18:55