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

com.simiacryptus.bitset.BitsCollection Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package com.simiacryptus.bitset;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import com.simiacryptus.binary.BitInputStream;
import com.simiacryptus.binary.BitOutputStream;
import com.simiacryptus.binary.Bits;
import com.simiacryptus.collections.CountCollection;

public abstract class BitsCollection>
    extends CountCollection
{
  
  public enum CodeType
  {
    Terminal, Prefix, Unknown
  }
  
  public final Integer bitDepth;
  
  public BitsCollection(final C collection)
  {
    super(collection);
    this.bitDepth = null;
  }
  
  public BitsCollection(final int bitDepth, final C collection)
  {
    super(collection);
    this.bitDepth = bitDepth;
  }
  
  public CodeType getType(final Bits bits)
  {
    if (null != this.bitDepth)
    {
      if (bits.bitLength == this.bitDepth) { return CodeType.Terminal; }
      if (bits.bitLength < this.bitDepth) { return CodeType.Prefix; }
      throw new IllegalArgumentException();
    }
    return CodeType.Unknown;
  }
  
  public abstract void read(BitInputStream in) throws IOException;
  
  public abstract void write(BitOutputStream out) throws IOException;
  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy