Commit 9ab8d4af authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

inital

parent 298a2e89
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ public abstract class DistinctCounter {
     * This constructor cannot be used.
     */
    private DistinctCounter() {
        state = new Integer[0];
        state = new Byte[0];
    };

    /**
@@ -19,15 +19,15 @@ public abstract class DistinctCounter {
     * @param stateSize The size of the memory backing, in number of integers.
     */
    public DistinctCounter(int stateSize) {
        state =new Integer[stateSize];
        state = new Byte[stateSize];
    }

    /**
     * Creates a DistinctCounter object from a given initial state.
     * @param initialState The output of a call to {@link #currentState()} on some DistinctCounter object.
     */
    public DistinctCounter(Integer[] initialState) {
        state = new Integer[initialState.length];
    public DistinctCounter(Byte[] initialState) {
        state = new Byte[initialState.length];
        for (int ii=0; ii<initialState.length; ii++)
            state[ii]=initialState[ii];
    }
@@ -50,11 +50,11 @@ public abstract class DistinctCounter {
    /**
     * outputs the current state of the DistinctCounter
     * */
    public Integer[] currentState() {
    public Byte[] currentState() {
        return state;
    }


    // FIELD
    final private Integer[] state;
    final private Byte[] state;
}
+11 −0
Original line number Diff line number Diff line
@@ -5,5 +5,16 @@ import java.util.Arrays;
public class Main {

    public static void main(String[] args) {
        String[] testStrings = {"Bravo", "Alfa", "Charlie", "Kilo", "Charlie", "Alfa", "Bravo"};

        myDistinctCounter foo = new myDistinctCounter(10);
        for (String test: testStrings) {
            foo.see(test);
        }

        Byte[] savedState = foo.currentState();

        myDistinctCounter newFoo = new myDistinctCounter(savedState);
        System.out.println(newFoo.numDistinct());
    }
}