2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.util;
24 public class BitSet64 extends AbstractFixedBitSet implements Cloneable {
26 static final int INDEX_MASK = 0xffffffc0; // ( i>=0 && i<64)
34 public BitSet64 (int i){
38 public BitSet64 (int... idx){
45 public void hash (HashData hd){
50 private final int computeCardinality (){
51 return Long.bitCount(l0);
54 //--- public interface (much like java.util.BitSet)
57 public void set (int i){
58 if ((i & INDEX_MASK) == 0){
59 long bitPattern = (1L << i);
60 if ((l0 & bitPattern) == 0L) {
65 throw new IndexOutOfBoundsException("BitSet64 index out of range: " + i);
70 public void clear (int i){
71 if ((i & INDEX_MASK) == 0){
72 long bitPattern = (1L << i);
73 if ((l0 & bitPattern) != 0L) { // bit is set
78 throw new IndexOutOfBoundsException("BitSet64 index out of range: " + i);
84 public boolean get (int i){
85 if ((i & INDEX_MASK) == 0){
86 long bitPattern = (1L << i);
87 return ((l0 & bitPattern) != 0);
89 throw new IndexOutOfBoundsException("BitSet64 index out of range: " + i);
94 public int capacity(){
99 * number of bits we can store
107 * index of highest set bit + 1
110 public int length() {
111 return 64 - Long.numberOfLeadingZeros(l0);
116 public void clear() {
122 public int nextSetBit (int fromIdx){
123 if ((fromIdx & INDEX_MASK) == 0){
124 //int n = Long.numberOfTrailingZeros(l0 & (0xffffffffffffffffL << fromIdx));
125 int n = Long.numberOfTrailingZeros(l0 >> fromIdx) + fromIdx;
132 //throw new IndexOutOfBoundsException("BitSet64 index out of range: " + fromIdx);
138 public int nextClearBit (int fromIdx){
139 if ((fromIdx & INDEX_MASK) == 0){
140 //int n = Long.numberOfTrailingZeros(~l0 & (0xffffffffffffffffL << fromIdx));
141 int n = Long.numberOfTrailingZeros(~l0 >> fromIdx) + fromIdx;
148 //throw new IndexOutOfBoundsException("BitSet64 index out of range: " + fromIdx);
153 public void and (BitSet64 other){
156 cardinality = computeCardinality();
159 public void andNot (BitSet64 other){
162 cardinality = computeCardinality();
165 public void or (BitSet64 other){
168 cardinality = computeCardinality();
172 public boolean equals (Object o){
173 if (o instanceof BitSet64){
174 BitSet64 other = (BitSet64)o;
175 if (l0 != other.l0) return false;
178 // <2do> we could compare to a normal java.util.BitSet here
185 * answer the same hashCodes as java.util.BitSet
188 public int hashCode() {
191 return (int) ((hc >>32) ^ hc);