Utils API
Preview notice
The MatrixOS Python API is in preview and is subject to change; it may contain errors.
Overview
The Utils API in MatrixOS provides utility functions for common operations like string hashing and other helper functions. The Utils API is available as MatrixOS.Utils and is imported by default.
The Python Utils API is implemented in Applications/Python/PikaPython/MatrixOS_Utils.py with type hints in Applications/Python/PikaPython/_MatrixOS_Utils.pyi.
StringHash
def StringHash(text: str) -> int
Generates a hash value from a text string. This is useful for creating consistent numeric identifiers from string data, particularly for NVS storage keys or other identification purposes.
Parameters:
text(str): The input string to hash
Returns:
int: Hash value of the input string
Hash Function Properties
The StringHash function provides:
- Consistency: Same input always produces same output
- Distribution: Different inputs typically produce different outputs
- Fixed Range: Returns integer values suitable for NVS keys
- Fast Computation: Optimized for real-time usage
Comments