/*
 * ARX: Efficient, Stable and Optimal Data Anonymization
 * Copyright (C) 2012 - 2013 Florian Kohlmayer, Fabian Prasser
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package org.deidentifier.arx;


/**
 * A set of rows
 * 
 * @author Prasser, Kohlmayer
 */
public class RowSet {

    private final long[]       array;
    private final int          length;
    private static final int   ADDRESS_BITS_PER_UNIT = 6;
    protected static final int BITS_PER_UNIT         = 64;
    private static final int   BIT_INDEX_MASK        = 63;
    private int size;

    public static RowSet create(Data data){
        return new RowSet(data);
    }
    
    private RowSet(Data data) {
        this.length = data.getHandle().getNumRows();
        int chunks = (int) (Math.ceil((double) this.length / 64d));
        array = new long[chunks];
    }

    public void add(int bit) {
        int offset = bit >> ADDRESS_BITS_PER_UNIT;
        long temp = array[offset];
        array[offset] |= 1L << (bit & BIT_INDEX_MASK);
        size += array[offset] != temp ? 1 : 0; 
    }

    public boolean contains(int bit) {
        return ((array[bit >> ADDRESS_BITS_PER_UNIT] & (1L << (bit & BIT_INDEX_MASK))) != 0);
    }

    public int length() {
        return this.length;
    }
    
    public int size() {
        return this.size;
    }
}

@@ -1463,27 +1463,32 @@
 oid add(int 
-bit
+rowIndex
 ) %7B%0A        
@@ -1500,19 +1500,24 @@
 ffset = 
-bit
+rowIndex
  %3E%3E ADDR
@@ -1598,27 +1598,282 @@
 %5D %7C= 1L %3C%3C (
-bit
+rowIndex & BIT_INDEX_MASK);%0A        size += array%5Boffset%5D != temp ? 1 : 0; %0A    %7D%0A    %0A    public void remove(int rowIndex)%7B%0A        int offset = rowIndex %3E%3E ADDRESS_BITS_PER_UNIT;%0A        long temp = array%5Boffset%5D;%0A        array%5Boffset%5D &= ~(1L %3C%3C (rowIndex
  & BIT_INDEX
@@ -1870,32 +1870,33 @@
  BIT_INDEX_MASK)
+)
 ;%0A        size +
@@ -1886,33 +1886,33 @@
 );%0A        size 
-+
+-
 = array%5Boffset%5D 
@@ -1968,19 +1968,24 @@
 ins(int 
-bit
+rowIndex
 ) %7B%0A    
@@ -2003,19 +2003,24 @@
 ((array%5B
-bit
+rowIndex
  %3E%3E ADDR
@@ -2052,11 +2052,16 @@
 %3C%3C (
-bit
+rowIndex
  & B

Allow removing rows from a RowSet