com.clearspring.analytics.stream.cardinality.CountThenEstimate Maven / Gradle / Ivy
/*
* Copyright (C) 2011 Clearspring Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.clearspring.analytics.stream.cardinality;
import java.io.ByteArrayInputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.clearspring.analytics.util.ExternalizableUtil;
import com.clearspring.analytics.util.IBuilder;
/**
* Exact -> Estimator cardinality counting
*
*
* Avoids allocating a large block of memory for cardinality estimation until
* a specified "tipping point" cardinality is reached.
*
*/
public class CountThenEstimate implements ICardinality, Externalizable {
protected final static byte LC = 1;
protected final static byte AC = 2;
protected final static byte HLC = 3;
protected final static byte LLC = 4;
protected final static byte HLPC = 5;
/**
* Cardinality after which exact counting gives way to estimation
*/
protected int tippingPoint;
/**
* True after switching to estimation
*/
protected boolean tipped = false;
/**
* Factory for instantiating estimator after the tipping point is reached
*/
protected IBuilder builder;
/**
* Cardinality estimator
* Null until tipping point is reached
*/
protected ICardinality estimator;
/**
* Cardinality counter
* Null after tipping point is reached
*/
protected Set
© 2015 - 2024 Weber Informatics LLC | Privacy Policy