{"id":19241857,"url":"https://github.com/quantum-0/custom-python-structures","last_synced_at":"2026-04-20T13:36:40.565Z","repository":{"id":38378132,"uuid":"495856317","full_name":"Quantum-0/custom-python-structures","owner":"Quantum-0","description":"Practice custom data structures","archived":false,"fork":false,"pushed_at":"2022-07-09T20:10:09.000Z","size":133,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-05T03:12:11.674Z","etag":null,"topics":["list","matrix","python","python3","structures"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Quantum-0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-24T14:20:47.000Z","updated_at":"2022-05-29T18:23:51.000Z","dependencies_parsed_at":"2022-07-12T02:17:08.848Z","dependency_job_id":null,"html_url":"https://github.com/Quantum-0/custom-python-structures","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantum-0%2Fcustom-python-structures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantum-0%2Fcustom-python-structures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantum-0%2Fcustom-python-structures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantum-0%2Fcustom-python-structures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quantum-0","download_url":"https://codeload.github.com/Quantum-0/custom-python-structures/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240331314,"owners_count":19784643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["list","matrix","python","python3","structures"],"created_at":"2024-11-09T17:12:45.151Z","updated_at":"2025-10-06T16:09:09.321Z","avatar_url":"https://github.com/Quantum-0.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom-Python-Structures\n\nPractice custom data structures.\n\n*Also testing Github Actions on that repo.*\n\n# Badges\n\n[![Tests](https://github.com/Quantum-0/custom-python-structures/actions/workflows/tests.yml/badge.svg)](https://github.com/Quantum-0/custom-python-structures/actions/workflows/tests.yml)\n[![Black](https://github.com/Quantum-0/custom-python-structures/actions/workflows/black.yml/badge.svg)](https://github.com/Quantum-0/custom-python-structures/actions/workflows/black.yml)\n[![MyPy](https://github.com/Quantum-0/custom-python-structures/actions/workflows/mypy.yml/badge.svg)](https://github.com/Quantum-0/custom-python-structures/actions/workflows/mypy.yml)\n[![PyLint](https://github.com/Quantum-0/custom-python-structures/actions/workflows/lint.yml/badge.svg)](https://github.com/Quantum-0/custom-python-structures/actions/workflows/lint.yml)\n[![Coverage](https://github.com/Quantum-0/custom-python-structures/actions/workflows/coverage.yml/badge.svg)](https://github.com/Quantum-0/custom-python-structures/actions/workflows/coverage.yml)\n\n# Structures\n\n## LoopList\n\nSequence structure, implements list with feature, where indexes go by cycle.\n\n### Default `List` sequence:\n```mermaid\ngraph LR\n    A --\u003e B --\u003e C --\u003e D --\u003e E\n```\n\n### Loop List\n```mermaid\ngraph LR\n    A --\u003e B --\u003e C --\u003e D --\u003e E --\u003e A\n```\n\nSo, if in default `List` you try to get 5th element from that sequence, you'll get `IndexError: list index out of range`.\n\nBut with LoopList 5th element will be **A** again, 6th = **B**, 9th = **E**, 10th = **A** again and etc.\n\nSame with negative indexes: -1th element == **E**, -2th = **D**, -5th == **A**, -6th == **E** again and etc.\n\nThat structure also supports slices, but currently without step, so you can try get slise `[-2:7]` and that will return list `[D,E,A,B,C,D,E,A,B]`.\n\nIdea was inspired by [**Josephus Problem**](https://en.wikipedia.org/wiki/Josephus_problem) and with that structure solution will look like that:\n```python\nring = LoopList(range(1, n + 1))\nwhile len(ring) \u003e 1:\n    ring.rotate(k - 1)\n    del ring[0]\nreturn ring[0]\n```\n\n## Matrix\n\nThat structure implements matrix interface on nested list.\n\n### UML\n```mermaid\nclassDiagram\n        Matrix \u003c|-- NumericMatrix\n        Matrix \u003c|-- BitMatrix\n        class Matrix{\n            -_values : [[T]]\n            -_width : int\n            -_height : int\n            +width int\n            +height int\n            +size tuple\n            +is_square bool\n            +rotated_... Matrix\n            +mirrored_... Matrix\n            +main_diagonal [T]\n            +__getitem__(key)\n            +__setitem__(key, value)\n            +generate(...)\n            +from_nested_list(list of lists)\n            +from_joined_lists(w, h, list)\n            +from_lists(*lists)\n            +input_matrix(...)\n            +transpose()\n            +get_minor(i, j)\n        }\n        class NumericMatrix{\n            +zero_matrix(n, [m]) NumericMatrix\n            +identity(n) NumericMatrix\n            +trace : int or float\n            +determinant : int or float\n            +__add__(other)\n            +__sub__(other)\n            +__mul__(other)\n            +__div__(other)\n            +__invert__()\n            +__neg__()\n        }\n        class BitMatrix{\n            +zero_matrix(n, [m]) BitMatrix\n            +identity(n) BitMatrix\n            +__and__(other)\n            +__or__(other)\n            +__xor__(other)\n            +__sub__(other)\n            +__neg__()\n        }\n        MatrixIterator --o Matrix\n        MatrixIterator: matrix\n        MatrixIterator: WALKTHROW_TYPE\n        MatrixIterator: +__init__(Matrix)\n        MatrixIterator: +__iter__()\n        MatrixIterator: +__next__()\n```\n\n### Usage\n\n```python\n# Creating examples\nm1 = NumericMatrix.from_joined_lists(3, values=range(9))\nm2 = Matrix(2, 2, [['A', 'B'], ['C', 'D']])\nm3 = NumericMatrix.zero_matrix(size=4)\nm4 = BitMatrix.from_lists([True, False], [False, True])\n\n# Comparing\nassert m1 != m2 # Supports compating between matrix\nassert m2 == [['A', 'B'], ['C', 'D']] # And directly with nested list\n\n# Math\n# A, B : NumericMatrix\nassert A + B == B + A == C\nassert A += B\nassert A == C\n# Same with subtraction\n# Multiplication implements matrix multiplication, so:\nassert A * B != B * A\n# Trace and Determinant:\nA.trace\nA.determinant\n\n# Transformations\nA.transponate()\nassert A.rotated_clockwise.rotated_counterclockwise == A\nassert A.mirrored_horizontaly.mirrored_horizontaly == A\n\n# Bit operations - implements bit logic between elements\n# A, B : BitMatrix\nassert A \u0026 B == B \u0026 A\nassert A | B == B | A\nassert A ^ B == B ^ A\nassert -(-A) == A\n\n# Indexing and slicing\nA[0,0]\nA[1,:]\nA[:,2]\nA[4:7,2:4]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantum-0%2Fcustom-python-structures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquantum-0%2Fcustom-python-structures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantum-0%2Fcustom-python-structures/lists"}