python_hll.util module¶
-
class
python_hll.util.BitUtil[source]¶ Bases:
objectA collection of bit utilities.
-
LEAST_SIGNIFICANT_BIT= [-1, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0]¶
-
classmethod
least_significant_bit(value)[source]¶ Computes the least-significant bit of the specified
longthat is set to1. Zero-indexed.See <http://stackoverflow.com/questions/757059/position-of-least-significant-bit-that-is-set> and <http://www-graphics.stanford.edu/~seander/bithacks.html>.
Parameters: value (long) – the longwhose least-significant bit is desired.Returns: the least-significant bit of the specified long.-1is returned if there are no bits set.Return type: int
-
classmethod
left_shift_byte(byte_x, int_y)[source]¶ Simulates a Java << for a byte.
Parameters: - byte_x – expected byte value in python code
- int_y – expected int value in python
Returns: left shift result for, x << y
Return type: int
-
classmethod
left_shift_int(int_x, int_y)[source]¶ Simulates a Java << for an integer.
Parameters: - int_x – expected int value in python code
- int_y – expected int value in python
Returns: left shift result for, x << y
Return type: int
-
classmethod
left_shift_long(long_x, int_y)[source]¶ Simulates a Java << for a long.
Parameters: - long_x – expected long value in python code
- int_y – expected int value in python
Returns: left shift result for, x << y
Return type: long
-
-
class
python_hll.util.BitVector(width, count)[source]¶ Bases:
objectA vector (array) of bits that is accessed in units (“registers”) of
widthbits which are stored as 64bit “words” (long’s). In this context a register is at most 64bits.-
BITS_PER_BYTE= 8¶
-
BITS_PER_WORD= 64¶
-
BITS_PER_WORD_MASK= 63¶
-
BYTES_PER_WORD= 8¶
-
LOG2_BITS_PER_BYTE= 3¶
-
LOG2_BITS_PER_WORD= 6¶
-
fill(value)[source]¶ Fills this bit vector with the specified bit value. This can be used to clear the vector by specifying
0.Parameters: value (long) – the value to set all bits to (only the lowest bit is used) Return type: void
-
get_register(register_index)[source]¶ Parameters: register_index (long) – the index of the register whose value is to be retrieved. This cannot be negative. Returns: the value at the specified register index Return type: long
-
get_register_contents(serializer)[source]¶ Serializes the registers of the vector using the specified serializer.
Parameters: serializer (BigEndianAscendingWordSerializer) – the serializer to use. This cannot be None.Return type: void
-
register_iterator()[source]¶ Returns: a LongIteratorfor iterating starting at the register with index zero. This will never beNone.Return type: LongIterator
-
set_max_register(register_index, value)[source]¶ Sets the value of the specified index register if and only if the specified value is greater than the current value in the register. This is equivalent to but much more performant than
vector.setRegister(index, Math.max(vector.getRegister(index), value));Parameters: - register_index (long) – the index of the register whose value is to be set. This cannot be negative
- value (long) – the value to set in the register if and only if this value is greater than the current value in the register
Returns: True if and only if the specified value is greater than or equal to the current register value. False otherwise.
Return type: boolean
-
-
class
python_hll.util.LongIterator(register_width, words, register_mask, count)[source]¶ Bases:
objectA
long-based iterator.-
BITS_PER_WORD= 64¶
-
LOG2_BITS_PER_WORD= 6¶
-
-
class
python_hll.util.NumberUtil[source]¶ Bases:
objectA collection of utilities to work with numbers.
-
HEX= ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']¶
-
LOGE_2= 0.6931471805599453¶
-
classmethod
from_hex(string, offset, count)[source]¶ Converts the specified array of hex characters into an array of
byte’s (lowbytefirst).Parameters: - string (string) – the string of hex characters to be converted into
byte’s. This cannot beNonethough it may be blank. - offset (int) – the offset in the string at which the characters will be
taken. This cannot be negative and must be less than
string.length() - 1. - count (int) – the number of characters to be retrieved from the specified
string. This cannot be negative and must be divisible by two
(since there are two characters per
byte).
Returns: the array of
byte’s that were converted from the specified string (in the specified range). This will never beNonethough it may be empty ifstringis empty orcountis zero.Return type: list
- string (string) – the string of hex characters to be converted into
-
classmethod
log2(value)[source]¶ Computes the
log2(log-base-two) of the specified value.Parameters: value (float) – the floatfor which thelog2is desired.Returns: the log2of the specified valueReturn type: float
-
classmethod
to_hex(bytes, offset, count)[source]¶ Converts the specified array of
byte’s into a string of hex characters (lowbytefirst).Parameters: - bytes (list) – the array of
byte’s that are to be converted. This cannot beNonethough it may be empty. - offset (int) – the offset in
bytesat which the bytes will be taken. This cannot be negative and must be less thanbytes.length - 1. - count (int) – the number of bytes to be retrieved from the specified array.
This cannot be negative. If greater than
bytes.length - offsetthen that value is used.
Returns: a string of at most
countcharacters that represents the specified byte array in hex. This will never beNonethough it may be empty ifbytesis empty orcountis zero.Return type: string
- bytes (list) – the array of
-