Utilities
This module pydsa.utils
contains utility functions that aid implementing
abstract data types and algorithms.
ElemTypeName = Literal['int', 'uint', 'float', 'double', 'object']
module-attribute
¶
All possible options for contiguous memory cell item type.
is_pos_power_of_two(num)
¶
Checks if num
is a positive power of 2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num |
int
|
The number to test. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
Source code in pydsa/utils.py
48 49 50 51 52 53 54 55 56 57 |
|
py_obj_array_type(size, item_type)
¶
Creates and returns a type that represents contiguous memory cells for
size
number of objects of item_type
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_type |
ElemTypeName
|
Cell item type -- 'int', 'uint', 'float', 'double', 'object'. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if |
Returns:
Name | Type | Description |
---|---|---|
Type |
Type
|
The contiguous memory cell type desired. |
See Also
pydsa.utils.ElemTypeName
Source code in pydsa/utils.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
validate_close_range(name, value, low, high, error=IndexError)
¶
Checks if the number value
falls within the close range [low,
high]
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the number to check. |
required |
value |
int
|
The number to check. |
required |
low |
int
|
Beginning of the close range. |
required |
high |
int
|
End of the close range. |
required |
error |
Type[Exception]
|
The exception type to raise when the test fails. |
IndexError
|
Raises:
Type | Description |
---|---|
error
|
if |
Source code in pydsa/utils.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|