예제 #1
0
 public boolean add(final Iterable<Integer> ns) {
   final List<Integer> elems = Lists.newArrayList(ns);
   final SparseBitmap oldMap = sparseBitmap();
   final SparseBitmap newMap = new SparseBitmap(oldMap.buffer.length);
   boolean added = false;
   Collections.sort(elems);
   if (0 == oldMap.cardinality) {
     for (int n : elems) {
       newMap.set(n);
     }
   } else {
     for (int n : elems) {
       for (int i : oldMap) {
         if (i == n) {
           return true;
         } else if (!added && i > n) {
           newMap.set(n);
           added = true;
           newMap.set(i);
         } else {
           newMap.set(i);
         }
       }
     }
   }
   reflect(newMap);
   return false;
 }
예제 #2
0
 protected SparseBitmap sparseBitmap() {
   final SparseBitmap sparseBitmap = new SparseBitmap();
   sparseBitmap.buffer = buffer;
   sparseBitmap.wordusage = wordusage;
   sparseBitmap.sizeinwords = sizeinword;
   sparseBitmap.cardinality = cardinality;
   return sparseBitmap;
 }
예제 #3
0
 public boolean remove(final int n) {
   final SparseBitmap oldMap = sparseBitmap();
   final SparseBitmap newMap = new SparseBitmap(oldMap.buffer.length);
   boolean removed = false;
   for (int i : oldMap) {
     if (i == n) {
       removed = true;
     } else {
       newMap.set(i);
     }
   }
   reflect(newMap);
   return removed;
 }