Package cnuphys.snr
Class ExtendedWord
java.lang.Object
cnuphys.snr.ExtendedWord
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long[]
Holds the composite words. words[0] is least significant. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty extended word.ExtendedWord
(int bitsNeeded) Creates an extended word made up of an array of longs.ExtendedWord
(long[] words) Create using words -
Method Summary
Modifier and TypeMethodDescriptionCreate a binary string representation.int
bitCount()
Count all the on bits in the extended word.static void
bitwiseAnd
(ExtendedWord u, ExtendedWord v, ExtendedWord result) Perform a bitwise and on two extended words.static void
bitwiseOr
(ExtendedWord u, ExtendedWord v, ExtendedWord result) Perform a bitwise or on two extended words.static void
bitwiseXor
(ExtendedWord u, ExtendedWord v, ExtendedWord result) Perform a bitwise xor on two extended words.void
bleedLeft
(int n) Bleed the specified number of bits left.void
bleedRight
(int n) Bleed the specified number of bits right.boolean
checkBit
(int bit) Check if a given bit is on,void
clear()
Zero all the bitsvoid
clearBit
(int bit) Clear the bit at a given locationstatic void
copy
(ExtendedWord src, ExtendedWord dest) Copy value from one extended word to another.static int
countCommonBits
(ExtendedWord a, ExtendedWord b, ExtendedWord work1, ExtendedWord work2, ExtendedWord work3) static String
encode62
(long num) Encode a long into a base 62 String.boolean
equals
(ExtendedWord ew) Test for equality with another wordvoid
fill()
Set all bits to 1static ExtendedWord
Convert back to an ExtendedWord from a hash keystatic ExtendedWord
fromHash62
(String hash) Convert back to an ExtendedWord from a hash keylong[]
getWords()
Get the underlying wordshashKey()
Hash this ExtendedWord into a StringHash this ExtendedWord into a String in base 62boolean
isZero()
See if this extended word is zerostatic void
Main program for testingvoid
negate()
Toggle all the bits in an ExtendedWord.void
OLDbleedLeft
(int n) Bleed the specified number of bits left.void
OLDbleedRight
(int n) Bleed the specified number of bits right.static ExtendedWord
randomWord
(int bitsNeeded, Random rand, float setProb) Create a random wordvoid
setBit
(int bit) Set the bit at a given locationvoid
shiftLeft
(int n) Shift the extended word left.shiftLeftAndOr
(int n) Shift the extended word left and or with self.void
shiftRight
(int n) Shift the extended word right.shiftRightAndOr
(int n) Shift the extended word right and or with self.toString()
Create a string representation.
-
Field Details
-
words
protected long[] wordsHolds 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
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
Copy value from one extended word to another.- Parameters:
src
-dest
-
-
negate
public void negate()Toggle all the bits in an ExtendedWord. -
bitwiseAnd
Perform a bitwise and on two extended words. They are assumed to be of the same size.- Parameters:
u
- one of the extended wordsv
- the other extended word.result
- where the result is stored. Can be u or v.
-
bitwiseOr
Perform a bitwise or on two extended words. They are assumed to be of the same size.- Parameters:
u
- one of the extended wordsv
- the other extended word.result
- where the result is stored. Can be u or v.
-
bitwiseXor
Perform a bitwise xor on two extended words. They are assumed to be of the same size.- Parameters:
u
- one of the extended wordsv
- 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
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
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
Create a binary string representation.- Returns:
-
toString
Create 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
Hash this ExtendedWord into a String- Returns:
- a String suitable as a hash or map key
-
hashKey62
Hash this ExtendedWord into a String in base 62- Returns:
- a String suitable as a hash or map key
-
fromHash
Convert back to an ExtendedWord from a hash key- Parameters:
hash
- the key- Returns:
- the equivalent ExtendedWord
-
fromHash62
Convert back to an ExtendedWord from a hash key- Parameters:
hash
- the key- Returns:
- the equivalent ExtendedWord
-
encode62
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
Create a random word- Parameters:
bitsNeeded
- the number of bits needeedrand
- the random number generatorsetProb
- the probability that w bit will be set- Returns:
- a random word
-
main
Main program for testing- Parameters:
arg
-
-