.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/04_tables.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_04_tables.py: Tables and updates ====================== A permission table records which combinations of read, write, and share are allowed. Construct a circuit directly from Boolean rows, update the allowed set, and query it with another Boolean condition. .. GENERATED FROM PYTHON SOURCE LINES 10-23 .. code-block:: Python from tididi import Vtree, from_models, literal vtree = Vtree.balanced(3) read, write, share = 1, 2, 3 rows = [ (True, False, False), (True, True, False), (True, False, True), (True, True, False), ] permissions = from_models(vtree, [read, write, share], rows) print("Distinct permission sets:", permissions.model_count()) .. rst-class:: sphx-glr-script-out .. code-block:: none Distinct permission sets: 3 .. GENERATED FROM PYTHON SOURCE LINES 24-31 Rows describe a set: the repeated row contributes only once. The positions in each row correspond to the supplied variable list. Other vtree variables, if any, would be free. Insert the combination with all three permissions and remove read/write without sharing. Updates use signed literals; ``-share`` means sharing is false. The operation consumes the old circuit and returns its replacement. .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: Python permissions = permissions.update(insert=[[read, write, share]], remove=[[read, write, -share]]) print("After updates:", permissions.model_count()) .. rst-class:: sphx-glr-script-out .. code-block:: none After updates: 3 .. GENERATED FROM PYTHON SOURCE LINES 35-37 The updated table contains read-only, read-and-share, and all three permissions. Filter a copy so the full table stays available for the next update. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python sharing = permissions.copy() & literal(vtree, share) print("Permission sets allowing sharing:", sharing.model_count()) .. rst-class:: sphx-glr-script-out .. code-block:: none Permission sets allowing sharing: 2 .. GENERATED FROM PYTHON SOURCE LINES 41-46 Remove a group of rows ---------------------- Suppose sharing is withdrawn entirely. A partial assignment names just the permissions to match: ``[share]`` selects every row where sharing is true, whatever its read and write values. .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python permissions = permissions.update(remove=[[share]]) print("After withdrawing sharing:", permissions.model_count()) .. rst-class:: sphx-glr-script-out .. code-block:: none After withdrawing sharing: 1 .. GENERATED FROM PYTHON SOURCE LINES 50-52 Only read access without write or share remains. Removing matching rows does not change their share column to false. An empty cube matches all assignments. .. _sphx_glr_download_tutorials_04_tables.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04_tables.ipynb <04_tables.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04_tables.py <04_tables.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 04_tables.zip <04_tables.zip>`