1 19 20 21 26 27 package soot.util; 28 29 import java.util.*; 30 import soot.util.*; 31 32 33 38 public class BitSetIterator { 39 40 long[] bits; int index; long save = 0; 44 46 final static int[] lookup = {-1, 0, 1, 39, 2, 15, 40, 23, 3, 12, 16, 47 59, 41, 19, 24, 54, 4, -1, 13, 10, 17, 48 62, 60, 28, 42, 30, 20, 51, 25, 44, 55, 49 47, 5, 32, -1, 38, 14, 22, 11, 58, 18, 50 53, -1, 9, 61, 27, 29, 50, 43, 46, 31, 51 37, 21, 57, 52, 8, 26, 49, 45, 36, 56, 52 7, 48, 35, 6, 34, 33}; 53 54 55 BitSetIterator(long[] bits) { 56 this.bits = bits; 59 index = 0; 60 61 62 while (index < bits.length && bits[index]==0L) 63 index++; 64 if (index < bits.length) 65 save = bits[index]; 66 } 67 68 69 public boolean hasNext() { 70 return index < bits.length; 71 } 72 73 75 public int next() { 76 if (index >= bits.length) 77 throw new NoSuchElementException(); 78 79 long k = (save & (save-1)); long diff = save ^ k; save = k; 82 83 int result = (diff < 0) ? 64 * index + 63 : 64 * index + lookup[(int)(diff%67)]; 85 86 if (save == 0) { 87 index++; 88 while (index < bits.length && bits[index]==0L) 89 index++; 90 if (index < bits.length) 91 save = bits[index]; 92 } 93 return result; 94 } 95 } 96 | Popular Tags |