src.pydasa.structs.tools.memory#

Module with utility functions for handling memory allocation in the Data Structures of PyDASA.

IMPORTANT: based on the implementations proposed by the following authors/books:

  1. Algorithms, 4th Edition, Robert Sedgewick and Kevin Wayne.

  2. Data Structure and Algorithms in Python, M.T. Goodrich, R. Tamassia, M.H. Goldwasser.

Functions#

alloc_slots()

Decorator that converts a class into a dataclass with slots for memory optimization.

Module Contents#

src.pydasa.structs.tools.memory.alloc_slots()#

Decorator that converts a class into a dataclass with slots for memory optimization.

This decorator uses Python 3.10+ native slots support in dataclasses to reduce memory usage by preventing the creation of __dict__ for each instance.

Raises:
  • TypeError – If the decorated object is not a class type.

  • RuntimeError – If the Python version is less than 3.10.

Returns:

Decorated class as a dataclass with slots.

Return type:

Callable

Example:

# Simple usage - all fields slotted, no dynamic attributes
@alloc_slots()
class Point:
    x: int
    y: int

# Works with existing dataclasses
@alloc_slots()
@dataclass
class Vector:
    x: float
    y: float
    z: float