python_hll.util module

class python_hll.util.BitUtil[source]

Bases: object

A 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 long that is set to 1. 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 long whose least-significant bit is desired.
Returns:the least-significant bit of the specified long. -1 is 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

classmethod to_signed_byte(i)[source]

Converts a Python byte (unsigned integer from 0 to 255) to a Java byte (signed two’s complement integer from -128 to 127). :type i: byte :rtype: byte

classmethod unsigned_right_shift_byte(val, n)[source]

Equivalent to Java >>> on a byte value

classmethod unsigned_right_shift_int(val, n)[source]

Equivalent to Java >>> on an int value

classmethod unsigned_right_shift_long(val, n)[source]

Equivalent to Java >>> on a long value

class python_hll.util.BitVector(width, count)[source]

Bases: object

A vector (array) of bits that is accessed in units (“registers”) of width bits 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 LongIterator for iterating starting at the register with index zero. This will never be None.
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

set_register(register_index, value)[source]
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
Return type:

long

class python_hll.util.LongIterator(register_width, words, register_mask, count)[source]

Bases: object

A long-based iterator.

BITS_PER_WORD = 64
LOG2_BITS_PER_WORD = 6
next()[source]
class python_hll.util.NumberUtil[source]

Bases: object

A 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 (low byte first).

Parameters:
  • string (string) – the string of hex characters to be converted into byte’s. This cannot be None though 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 be None though it may be empty if string is empty or count is zero.

Return type:

list

classmethod log2(value)[source]

Computes the log2 (log-base-two) of the specified value.

Parameters:value (float) – the float for which the log2 is desired.
Returns:the log2 of the specified value
Return type:float
classmethod to_hex(bytes, offset, count)[source]

Converts the specified array of byte’s into a string of hex characters (low byte first).

Parameters:
  • bytes (list) – the array of byte’s that are to be converted. This cannot be None though it may be empty.
  • offset (int) – the offset in bytes at which the bytes will be taken. This cannot be negative and must be less than bytes.length - 1.
  • count (int) – the number of bytes to be retrieved from the specified array. This cannot be negative. If greater than bytes.length - offset then that value is used.
Returns:

a string of at most count characters that represents the specified byte array in hex. This will never be None though it may be empty if bytes is empty or count is zero.

Return type:

string