freezing#
Functions
|
Freeze a planar diagram so it cannot be modified. |
|
Dummy method used on frozen diagrams to block mutation. |
|
Lock a planar diagram so it cannot be modified. |
|
Unfreeze a planar diagram so it can be modified again. |
- freeze(k, inplace=True)#
Freeze a planar diagram so it cannot be modified.
Freezing monkey-patches mutating methods on the instance to a dummy method that raises
RuntimeError
. The diagram’s data stays intact.- Parameters:
k (PlanarDiagram | OrientedPlanarDiagram) – Diagram to freeze.
inplace (bool) – If
True
, freezek
in place; otherwise work on a shallow copy.
- Returns:
PlanarDiagram – The frozen diagram (
k
or its copy).- Return type:
Examples
>>> from knotpy.classes.planardiagram import PlanarDiagram >>> d = PlanarDiagram() >>> d.add_vertices_from(["a", "b"]) >>> freeze(d) PlanarDiagram(...) >>> d.is_frozen() True >>> d.add_vertex("c") Traceback (most recent call last): ... RuntimeError: Frozen diagrams cannot be modified
- unfreeze(k, inplace=True)#
Unfreeze a planar diagram so it can be modified again.
Restores original bound methods from the diagram’s class. Useful when a frozen diagram was used as a dict/set key and you want to mutate it again.
- Parameters:
k (PlanarDiagram | OrientedPlanarDiagram) – Diagram to unfreeze.
inplace (bool) – If
True
, unfreezek
in place; otherwise operate on a shallow copy.
- Returns:
PlanarDiagram – The unfrozen diagram (
k
or its copy).- Return type:
Examples
>>> from knotpy.classes.planardiagram import PlanarDiagram >>> d = PlanarDiagram() >>> freeze(d) PlanarDiagram(...) >>> unfreeze(d) PlanarDiagram(...) >>> d.is_frozen() False >>> d.add_vertex("x") # works again
- lock(k, inplace=True)#
Lock a planar diagram so it cannot be modified. Unlike freezing, a diagram cannot be unlocked. Used for knot tables, so the user cannot modify a knot in a precomputed knot table.
- Parameters:
inplace (bool)
- Return type: