All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.facebook.collections.specialized.SampledSet Maven / Gradle / Ivy

There is a newer version: 0.1.32
Show newest version
/*
 * Copyright (C) 2012 Facebook, 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.facebook.collections.specialized;

import com.facebook.collections.SnapshotProvider;
import com.facebook.collections.Trackable;

import javax.annotation.concurrent.ThreadSafe;
import java.util.Set;

/**
 * interface that provides adaptive sampling for set size estimation. The
 * underlying set will contain only sampled values, but methods are available
 * to get the scaled size as well as the size of the sample and the max
 * sample size that can be used.
 * 
 * 
 * 
 * @param  type of element in the set
 */

@ThreadSafe
public interface SampledSet extends Trackable, Set, SnapshotProvider> {
  
  public boolean add(T element);
  public int getMaxSetSize();
  public int getScaledSize();
  public int getSize();
  public int getSampleRate();
  public Set getEntries();

  /**
   * takes a snapshot of the underlying elements in a set.  Also atomically
   * downsamples the snapshot's set if the requested rate is higher than what 
   * is presently stored
   * 
   * @param rate - rate to sample at. Will only use this if it is higher than
   * the existing sample rate (ie, it can't up-sample)
   * @return
   */
  public SampledSetSnapshot sampleAt(int rate);

  /**
   * produces a new sampled set. The set is sampled at the higher rate
   * of the two sets and uses the max set size of the LHS
   * 
   * @param sampledSet 
   * @return
   */
  public SampledSet merge(SampledSet sampledSet);

  /**
   * merges another sampledSet's values into our own. The same semantics
   * as merge() apply with respect to the sampleRate
   * 
   * @param sampledSet 
   * @return true iff the underlying set is changed
   */
  public boolean mergeInPlaceWith(SampledSet sampledSet);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy