Loading src/edu/bu/ec504/hw1p1/DistinctCounter.java 0 → 100644 +60 −0 Original line number Diff line number Diff line package edu.bu.ec504.hw1p1; /** * Attempts to approximate the number of distinct elements seen so far. */ public abstract class DistinctCounter { // CONSTRUCTORS /** * This constructor cannot be used. */ private DistinctCounter() { state = new Integer[0]; }; /** * Constructs an object backed by a given memory size. * @param stateSize The size of the memory backing, in number of integers. */ public DistinctCounter(int stateSize) { state =new Integer[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]; for (int ii=0; ii<initialState.length; ii++) state[ii]=initialState[ii]; } // OPERATIONAL /** * Log a new element that is seen. * @param newElement The element that was seen. */ abstract void see(String newElement); /** * * @return A guess of the number of distinct elements that were seen. */ abstract Integer numDistinct(); // INFORMATIONAL /** * outputs the current state of the DistinctCounter * */ public Integer[] currentState() { return state; } // FIELD final private Integer[] state; } src/edu/bu/ec504/hw1p1/Main.java +2 −1 Original line number Diff line number Diff line package edu.bu.ec504.hw1p1; import java.util.Arrays; public class Main { public static void main(String[] args) { // write your code here } } Loading
src/edu/bu/ec504/hw1p1/DistinctCounter.java 0 → 100644 +60 −0 Original line number Diff line number Diff line package edu.bu.ec504.hw1p1; /** * Attempts to approximate the number of distinct elements seen so far. */ public abstract class DistinctCounter { // CONSTRUCTORS /** * This constructor cannot be used. */ private DistinctCounter() { state = new Integer[0]; }; /** * Constructs an object backed by a given memory size. * @param stateSize The size of the memory backing, in number of integers. */ public DistinctCounter(int stateSize) { state =new Integer[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]; for (int ii=0; ii<initialState.length; ii++) state[ii]=initialState[ii]; } // OPERATIONAL /** * Log a new element that is seen. * @param newElement The element that was seen. */ abstract void see(String newElement); /** * * @return A guess of the number of distinct elements that were seen. */ abstract Integer numDistinct(); // INFORMATIONAL /** * outputs the current state of the DistinctCounter * */ public Integer[] currentState() { return state; } // FIELD final private Integer[] state; }
src/edu/bu/ec504/hw1p1/Main.java +2 −1 Original line number Diff line number Diff line package edu.bu.ec504.hw1p1; import java.util.Arrays; public class Main { public static void main(String[] args) { // write your code here } }