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;
21 import gov.nasa.jpf.JPFException;
22 import java.util.NoSuchElementException;
25 * BitSet like interface for fixed size bit sets
27 * We keep this as an interface so that we can have java.util.BitSet
28 * subclasses as implementations
30 public interface FixedBitSet extends Cloneable, IntSet {
33 void set (int i, boolean val);
37 int nextClearBit (int fromIndex);
38 int nextSetBit (int fromIndex);
49 void hash (HashData hd);
55 * this is the base class for our non java.util.BitSet based FixedBitSet implementations
57 abstract class AbstractFixedBitSet implements FixedBitSet {
59 class SetBitIterator implements IntIterator {
64 public void remove() {
71 public boolean hasNext() {
72 return nBits < cardinality;
77 if (nBits < cardinality){
78 int idx = nextSetBit(cur);
86 throw new NoSuchElementException();
92 protected int cardinality;
95 public AbstractFixedBitSet clone(){
97 return (AbstractFixedBitSet) super.clone();
98 } catch (CloneNotSupportedException ex) {
99 throw new JPFException("BitSet64 clone failed");
104 public void set (int i, boolean val){
113 public int cardinality() {
118 public boolean isEmpty() {
119 return (cardinality == 0);
123 public String toString() {
124 StringBuilder sb = new StringBuilder();
127 boolean first = true;
128 for (int i=nextSetBit(0); i>= 0; i = nextSetBit(i+1)){
139 return sb.toString();
142 //--- IntSet interface
146 public boolean add(int i) {
156 public boolean remove(int i) {
166 public boolean contains(int i) {
171 public IntIterator intIterator() {
172 return new SetBitIterator();