Package cnuphys.snr

Class ExtendedWord

java.lang.Object
cnuphys.snr.ExtendedWord

public class ExtendedWord extends Object
  • Field Details

    • words

      protected long[] words
      Holds the composite words. words[0] is least significant.
  • Constructor Details

    • ExtendedWord

      public ExtendedWord(int bitsNeeded)
      Creates an extended word made up of an array of longs. Note that in JAVA a long is always 64 bits, independent of machine.
      Parameters:
      bitsNeeded - the number of bits needed.
    • ExtendedWord

      public ExtendedWord()
      Creates an empty extended word.
    • ExtendedWord

      public ExtendedWord(long[] words)
      Create using words
      Parameters:
      words - the words
  • Method Details

    • equals

      public boolean equals(ExtendedWord ew)
      Test for equality with another word
      Parameters:
      ew - the test word
      Returns:
      true if the two words have the same value
    • setBit

      public void setBit(int bit)
      Set the bit at a given location
      Parameters:
      bit - the bit to set.
    • clearBit

      public void clearBit(int bit)
      Clear the bit at a given location
      Parameters:
      bit - the bit to clear.
    • checkBit

      public boolean checkBit(int bit)
      Check if a given bit is on,
      Parameters:
      bit - the bit to check.
      Returns:
      true if the bit is set.
    • clear

      public void clear()
      Zero all the bits
    • fill

      public void fill()
      Set all bits to 1
    • isZero

      public boolean isZero()
      See if this extended word is zero
      Returns:
      if this extended word is zero
    • bitCount

      public int bitCount()
      Count all the on bits in the extended word.
      Returns:
      count of all the on bits in the extended word.
    • copy

      public static void copy(ExtendedWord src, ExtendedWord dest)
      Copy value from one extended word to another.
      Parameters:
      src -
      dest -
    • negate

      public void negate()
      Toggle all the bits in an ExtendedWord.
    • bitwiseAnd

      public static void bitwiseAnd(ExtendedWord u, ExtendedWord v, ExtendedWord result)
      Perform a bitwise and on two extended words. They are assumed to be of the same size.
      Parameters:
      u - one of the extended words
      v - the other extended word.
      result - where the result is stored. Can be u or v.
    • bitwiseOr

      public static void bitwiseOr(ExtendedWord u, ExtendedWord v, ExtendedWord result)
      Perform a bitwise or on two extended words. They are assumed to be of the same size.
      Parameters:
      u - one of the extended words
      v - the other extended word.
      result - where the result is stored. Can be u or v.
    • bitwiseXor

      public static void bitwiseXor(ExtendedWord u, ExtendedWord v, ExtendedWord result)
      Perform a bitwise xor on two extended words. They are assumed to be of the same size.
      Parameters:
      u - one of the extended words
      v - the other extended word.
      result - where the result is stored. Can be u or v.
    • shiftRight

      public void shiftRight(int n)
      Shift the extended word right. CURRENT LIMITATION: can only shift up to 64 bits.
      Parameters:
      n - the number of places to shift.
    • shiftRightAndOr

      public ExtendedWord shiftRightAndOr(int n)
      Shift the extended word right and or with self. CURRENT LIMITATION: can only shift up to 64 bits.
      Parameters:
      n - the number of places to shift.
    • shiftLeftAndOr

      public ExtendedWord shiftLeftAndOr(int n)
      Shift the extended word left and or with self. CURRENT LIMITATION: can only shift up to 64 bits.
      Parameters:
      n - the number of places to shift.
    • shiftLeft

      public void shiftLeft(int n)
      Shift the extended word left. CURRENT LIMITATION: can only shift up to 64 bits.
      Parameters:
      n - the number of places to shift.
    • OLDbleedRight

      public void OLDbleedRight(int n)
      Bleed the specified number of bits right.
      Parameters:
      n - the number of bits to bleed right.
    • bleedLeft

      public void bleedLeft(int n)
      Bleed the specified number of bits left.
      Parameters:
      n - the number of bits to bleed left.
    • bleedRight

      public void bleedRight(int n)
      Bleed the specified number of bits right.
      Parameters:
      n - the number of bits to bleed right.
    • OLDbleedLeft

      public void OLDbleedLeft(int n)
      Bleed the specified number of bits left.
      Parameters:
      n - the number of bits to bleed left.
    • binaryString

      public String binaryString()
      Create a binary string representation.
      Returns:
    • toString

      public String toString()
      Create a string representation.
      Overrides:
      toString in class Object
      Returns:
      a string representation.
    • getWords

      public long[] getWords()
      Get the underlying words
      Returns:
      the words
    • countCommonBits

      public static int countCommonBits(ExtendedWord a, ExtendedWord b, ExtendedWord work1, ExtendedWord work2, ExtendedWord work3)
    • hashKey

      public String hashKey()
      Hash this ExtendedWord into a String
      Returns:
      a String suitable as a hash or map key
    • hashKey62

      public String hashKey62()
      Hash this ExtendedWord into a String in base 62
      Returns:
      a String suitable as a hash or map key
    • fromHash

      public static ExtendedWord fromHash(String hash)
      Convert back to an ExtendedWord from a hash key
      Parameters:
      hash - the key
      Returns:
      the equivalent ExtendedWord
    • fromHash62

      public static ExtendedWord fromHash62(String hash)
      Convert back to an ExtendedWord from a hash key
      Parameters:
      hash - the key
      Returns:
      the equivalent ExtendedWord
    • encode62

      public static String encode62(long num)
      Encode a long into a base 62 String. Based on the toString implementation in the Java Long class.
      Parameters:
      number - the number to encode
      Returns:
      a base 62 number
    • randomWord

      public static ExtendedWord randomWord(int bitsNeeded, Random rand, float setProb)
      Create a random word
      Parameters:
      bitsNeeded - the number of bits needeed
      rand - the random number generator
      setProb - the probability that w bit will be set
      Returns:
      a random word
    • main

      public static void main(String[] arg)
      Main program for testing
      Parameters:
      arg -