// Path: src/main/java/org/rakam/cache/hazelcast/hyperloglog/operations/HyperLogLogSerializerFactory.java
// public final class HyperLogLogSerializerFactory implements DataSerializableFactory {
// 
//     public static final int F_ID = 100;
// 
//     public static final int ADD = 0;
//     public static final int ADD_BACKUP = 1;
//     public static final int ADD_ALL = 2;
//     public static final int ADD_ALL_BACKUP = 3;
//     public static final int CARDINALITY = 4;
//     public static final int UNION = 5;
//     public static final int UNION_BACKUP = 6;
//     public static final int REPLICATION = 7;
//     public static final int RESET = 8;
//     public static final int RESET_BACKUP = 9;
// 
//     @Override
//     public IdentifiedDataSerializable create(int typeId) {
//         switch (typeId) {
//             case ADD_BACKUP:
//                 return new AddBackupOperation();
//             case ADD:
//                 return new ResetOperation();
//             case ADD_ALL_BACKUP:
//                 return new AddAllBackupOperation();
//             case ADD_ALL:
//                 return new AddAllOperation();
//             case CARDINALITY:
//                 return new CardinalityOperation();
//             case UNION_BACKUP:
//                 return new UnionBackupOperation();
//             case UNION:
//                 return new UnionOperation();
//             case REPLICATION:
//                 return new HyperLogLogReplicationOperation();
//             default:
//                 return null;
//         }
//     }
// }
// 
// Path: src/main/java/org/rakam/util/HLLWrapper.java
// public class HLLWrapper {
//     final private static int SEED = 123456;
//     private HLL hll;
// 
//     public HLLWrapper() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// 
//     public HLLWrapper(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public long cardinality() {
//         return hll.cardinality();
//     }
// 
//     public void union(HLLWrapper hll) {
//         this.hll.union(hll.hll);
//     }
// 
//     public void addAll(Collection<String> coll) {
//         for (String a : coll) {
//             byte[] s = a.getBytes();
//             hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//         }
//     }
// 
//     public void add(String obj) {
//         if (obj == null)
//             throw new IllegalArgumentException();
//         byte[] s = obj.getBytes();
// 
//         hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//     }
// 
//     public void set(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public byte[] bytes() {
//         return hll.toBytes();
//     }
// 
//     public void reset() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// }


import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.spi.Operation;
import com.hazelcast.spi.PartitionAwareOperation;
import org.rakam.cache.hazelcast.hyperloglog.operations.HyperLogLogSerializerFactory;
import org.rakam.util.HLLWrapper;
import java.io.IOException;
/**
 * Created by buremba <Burak Emre Kabakcı> on 10/07/14.
 */

package org.rakam.cache.hazelcast.hyperloglog;



public abstract class HyperLogLogBaseOperation extends Operation implements PartitionAwareOperation, IdentifiedDataSerializable {

    protected String name;

    public HyperLogLogBaseOperation() {
    }

    public HyperLogLogBaseOperation(String name) {
        this.name = name;
    }

    public HLLWrapper getHLL() {
        HyperLogLogService service = getService();
        return service.getHLL(name);
    }

    @Override
    public int getFactoryId() {
// Path: src/main/java/org/rakam/cache/hazelcast/hyperloglog/operations/HyperLogLogSerializerFactory.java
// public final class HyperLogLogSerializerFactory implements DataSerializableFactory {
// 
//     public static final int F_ID = 100;
// 
//     public static final int ADD = 0;
//     public static final int ADD_BACKUP = 1;
//     public static final int ADD_ALL = 2;
//     public static final int ADD_ALL_BACKUP = 3;
//     public static final int CARDINALITY = 4;
//     public static final int UNION = 5;
//     public static final int UNION_BACKUP = 6;
//     public static final int REPLICATION = 7;
//     public static final int RESET = 8;
//     public static final int RESET_BACKUP = 9;
// 
//     @Override
//     public IdentifiedDataSerializable create(int typeId) {
//         switch (typeId) {
//             case ADD_BACKUP:
//                 return new AddBackupOperation();
//             case ADD:
//                 return new ResetOperation();
//             case ADD_ALL_BACKUP:
//                 return new AddAllBackupOperation();
//             case ADD_ALL:
//                 return new AddAllOperation();
//             case CARDINALITY:
//                 return new CardinalityOperation();
//             case UNION_BACKUP:
//                 return new UnionBackupOperation();
//             case UNION:
//                 return new UnionOperation();
//             case REPLICATION:
//                 return new HyperLogLogReplicationOperation();
//             default:
//                 return null;
//         }
//     }
// }
// 
// Path: src/main/java/org/rakam/util/HLLWrapper.java
// public class HLLWrapper {
//     final private static int SEED = 123456;
//     private HLL hll;
// 
//     public HLLWrapper() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// 
//     public HLLWrapper(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public long cardinality() {
//         return hll.cardinality();
//     }
// 
//     public void union(HLLWrapper hll) {
//         this.hll.union(hll.hll);
//     }
// 
//     public void addAll(Collection<String> coll) {
//         for (String a : coll) {
//             byte[] s = a.getBytes();
//             hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//         }
//     }
// 
//     public void add(String obj) {
//         if (obj == null)
//             throw new IllegalArgumentException();
//         byte[] s = obj.getBytes();
// 
//         hll.addRaw(MurmurHash3.murmurhash3x8632(s, 0, s.length, SEED));
//     }
// 
//     public void set(byte[] bytes) {
//         hll = HLL.fromBytes(bytes);
//     }
// 
//     public byte[] bytes() {
//         return hll.toBytes();
//     }
// 
//     public void reset() {
//         hll = new HLL(13/*log2m*/, 5/*registerWidth*/);
//     }
// }


// Path: src/main/java/org/rakam/cache/hazelcast/hyperloglog/HyperLogLogBaseOperation.java
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.spi.Operation;
import com.hazelcast.spi.PartitionAwareOperation;
import org.rakam.cache.hazelcast.hyperloglog.operations.HyperLogLogSerializerFactory;
import org.rakam.util.HLLWrapper;
import java.io.IOException;

/**
 * Created by buremba <Burak Emre Kabakcı> on 10/07/14.
 */

package org.rakam.cache.hazelcast.hyperloglog;



public abstract class HyperLogLogBaseOperation extends Operation implements PartitionAwareOperation, IdentifiedDataSerializable {

    protected String name;

    public HyperLogLogBaseOperation() {
    }

    public HyperLogLogBaseOperation(String name) {
        this.name = name;
    }

    public HLLWrapper getHLL() {
        HyperLogLogService service = getService();
        return service.getHLL(name);
    }

    @Override
    public int getFactoryId() {
        return HyperLogLogSerializerFactory.F_ID;