ai.krr.propositions
Class IntEncoding

java.lang.Object
  extended by ai.krr.propositions.IntEncoding

public class IntEncoding
extends java.lang.Object

This class can be used to encode propositional symbols as integers, which have the potential of being processed far more efficiently. A positive Literal +P will be encoded as a positive integer n, its complement -P as the negative integer -n. Thus two encoded Literals are complementary if their absolute value is the same. Note that this also means that no Literal will ever be encoded as zero.

Author:
Gerhard Wickler

Field Summary
protected  NamedSymbol[] decode
           
protected  int[] encInts
           
protected  NamedSymbol[] props
          arrays of symbols and encodings (hashed) and decoding:
 
Constructor Summary
IntEncoding(int capacity)
           This constructor creates a new, empty IntEncoding that has an initial capacity for encoding up to the given number of Literals.
 
Method Summary
protected  java.lang.Object clone()
           This class does not support cloning and an exception will be thrown if this method is called.
 Literal decode(int enci)
           This function can be used to decode the given integer, which must have been the result of a previous encoding.
 int encode(Literal lit)
           This function encodes the given Literal.
 int nrEncoded()
           This function returns the number of Symbols currently encoded.
 java.lang.String toString()
           This function creates a String representation of this IntEncoding.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

props

protected NamedSymbol[] props
arrays of symbols and encodings (hashed) and decoding:


encInts

protected int[] encInts

decode

protected NamedSymbol[] decode
Constructor Detail

IntEncoding

public IntEncoding(int capacity)

This constructor creates a new, empty IntEncoding that has an initial capacity for encoding up to the given number of Literals. If this number will be exceeded a rehashing needs to be performed.

Parameters:
capacity - the initial capacity of this IntEncoding
Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException

This class does not support cloning and an exception will be thrown if this method is called.

Overrides:
clone in class java.lang.Object
Returns:
nothing
Throws:
java.lang.CloneNotSupportedException - will be thrown

encode

public int encode(Literal lit)

This function encodes the given Literal. The returned integer uniquely identifies the given Literal. A positive Literal +P will be encoded as a positive integer n, its complement -P as the negative integer -n. Thus two encoded Literals are complementary if their absolute value is the same. This function never returns zero. Assuming a perfect hash-value for NamedSymbols, encodings should be computed in constant time, unless rehashing is necessary.

Parameters:
lit - the Literal to be encoded as an integer
Returns:
the integer that uniquely represents the given Literal

decode

public Literal decode(int enci)

This function can be used to decode the given integer, which must have been the result of a previous encoding. The given value must not be zero and its absolute value should be less or equal to the number of Symbols encoded here.

Parameters:
the - integer to be decoded
Returns:
a new Literal that, when encoded, results in the given integer

nrEncoded

public int nrEncoded()

This function returns the number of Symbols currently encoded. Note that the number of Literals encoded can be up to twice the returned value.

Returns:
total number of NamedSymbols in this IntEncoding

toString

public java.lang.String toString()

This function creates a String representation of this IntEncoding.

Overrides:
toString in class java.lang.Object
Returns:
an enumeration of the mapped integers