Package cnuphys.snr
Class ExtendedWord
java.lang.Object
cnuphys.snr.ExtendedWord
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected long[]Holds the composite words. words[0] is least significant.
- 
Constructor SummaryConstructorsConstructorDescriptionCreates 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 SummaryModifier and TypeMethodDescriptionCreate a binary string representation.intbitCount()Count all the on bits in the extended word.static voidbitwiseAnd(ExtendedWord u, ExtendedWord v, ExtendedWord result) Perform a bitwise and on two extended words.static voidbitwiseOr(ExtendedWord u, ExtendedWord v, ExtendedWord result) Perform a bitwise or on two extended words.static voidbitwiseXor(ExtendedWord u, ExtendedWord v, ExtendedWord result) Perform a bitwise xor on two extended words.voidbleedLeft(int n) Bleed the specified number of bits left.voidbleedRight(int n) Bleed the specified number of bits right.booleancheckBit(int bit) Check if a given bit is on,voidclear()Zero all the bitsvoidclearBit(int bit) Clear the bit at a given locationstatic voidcopy(ExtendedWord src, ExtendedWord dest) Copy value from one extended word to another.static intcountCommonBits(ExtendedWord a, ExtendedWord b, ExtendedWord work1, ExtendedWord work2, ExtendedWord work3) static Stringencode62(long num) Encode a long into a base 62 String.booleanequals(ExtendedWord ew) Test for equality with another wordvoidfill()Set all bits to 1static ExtendedWordConvert back to an ExtendedWord from a hash keystatic ExtendedWordfromHash62(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 62booleanisZero()See if this extended word is zerostatic voidMain program for testingvoidnegate()Toggle all the bits in an ExtendedWord.voidOLDbleedLeft(int n) Bleed the specified number of bits left.voidOLDbleedRight(int n) Bleed the specified number of bits right.static ExtendedWordrandomWord(int bitsNeeded, Random rand, float setProb) Create a random wordvoidsetBit(int bit) Set the bit at a given locationvoidshiftLeft(int n) Shift the extended word left.shiftLeftAndOr(int n) Shift the extended word left and or with self.voidshiftRight(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- 
wordsprotected long[] wordsHolds the composite words. words[0] is least significant.
 
- 
- 
Constructor Details- 
ExtendedWordpublic 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.
 
- 
ExtendedWordpublic ExtendedWord()Creates an empty extended word.
- 
ExtendedWordpublic ExtendedWord(long[] words) Create using words- Parameters:
- words- the words
 
 
- 
- 
Method Details- 
equalsTest for equality with another word- Parameters:
- ew- the test word
- Returns:
- trueif the two words have the same value
 
- 
setBitpublic void setBit(int bit) Set the bit at a given location- Parameters:
- bit- the bit to set.
 
- 
clearBitpublic void clearBit(int bit) Clear the bit at a given location- Parameters:
- bit- the bit to clear.
 
- 
checkBitpublic boolean checkBit(int bit) Check if a given bit is on,- Parameters:
- bit- the bit to check.
- Returns:
- trueif the bit is set.
 
- 
clearpublic void clear()Zero all the bits
- 
fillpublic void fill()Set all bits to 1
- 
isZeropublic boolean isZero()See if this extended word is zero- Returns:
- if this extended word is zero
 
- 
bitCountpublic int bitCount()Count all the on bits in the extended word.- Returns:
- count of all the on bits in the extended word.
 
- 
copyCopy value from one extended word to another.- Parameters:
- src-
- dest-
 
- 
negatepublic void negate()Toggle all the bits in an ExtendedWord.
- 
bitwiseAndPerform 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.
 
- 
bitwiseOrPerform 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.
 
- 
bitwiseXorPerform 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.
 
- 
shiftRightpublic 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.
 
- 
shiftRightAndOrShift 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.
 
- 
shiftLeftAndOrShift 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.
 
- 
shiftLeftpublic 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.
 
- 
OLDbleedRightpublic void OLDbleedRight(int n) Bleed the specified number of bits right.- Parameters:
- n- the number of bits to bleed right.
 
- 
bleedLeftpublic void bleedLeft(int n) Bleed the specified number of bits left.- Parameters:
- n- the number of bits to bleed left.
 
- 
bleedRightpublic void bleedRight(int n) Bleed the specified number of bits right.- Parameters:
- n- the number of bits to bleed right.
 
- 
OLDbleedLeftpublic void OLDbleedLeft(int n) Bleed the specified number of bits left.- Parameters:
- n- the number of bits to bleed left.
 
- 
binaryStringCreate a binary string representation.- Returns:
 
- 
toStringCreate a string representation.
- 
getWordspublic long[] getWords()Get the underlying words- Returns:
- the words
 
- 
countCommonBitspublic static int countCommonBits(ExtendedWord a, ExtendedWord b, ExtendedWord work1, ExtendedWord work2, ExtendedWord work3) 
- 
hashKeyHash this ExtendedWord into a String- Returns:
- a String suitable as a hash or map key
 
- 
hashKey62Hash this ExtendedWord into a String in base 62- Returns:
- a String suitable as a hash or map key
 
- 
fromHashConvert back to an ExtendedWord from a hash key- Parameters:
- hash- the key
- Returns:
- the equivalent ExtendedWord
 
- 
fromHash62Convert back to an ExtendedWord from a hash key- Parameters:
- hash- the key
- Returns:
- the equivalent ExtendedWord
 
- 
encode62Encode 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
 
- 
randomWordCreate 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
 
- 
mainMain program for testing- Parameters:
- arg-
 
 
-