# Python Circular Array Implementation
Python module implementing an indexable, double sided,
auto-resizing queue data structure.
* **Repositories**
* [grscheller.circular-array][1] project on *PyPI*
* [Source code][2] on *GitHub*
* **Detailed documentation**
* [Detailed API documentation][3] on *GH-Pages*
### Overview
Useful if used directly as an improved version of a Python List or in
a "has-a" relationship when implementing other data structures.
* O(1) pushes and pops either end.
* O(1) indexing
* now fully supports slicing!
### Usage
```python
from grscheller.circular_array.ca import CA
ca = CA(1, 2, 3)
assert ca.popL() == 1
assert ca.popR() == 3
ca.pushR(42, 0)
ca.pushL(0, 1)
assert repr(ca) == 'CA(1, 0, 2, 42, 0)'
assert str(ca) == '(|1, 0, 2, 42, 0|)'
ca = CA(*range(1,11))
assert repr(ca) == 'CA(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)'
assert str(ca) == '(|1, 2, 3, 4, 5, 6, 7, 8, 9, 10|)'
assert len(ca) == 10
tup3 = ca.popLT(3)
tup4 = ca.popRT(4)
assert tup3 == (1, 2, 3)
assert tup4 == (10, 9, 8, 7)
assert ca == CA(4, 5, 6)
four, *rest = ca.popFT(1000)
assert four == 4
assert rest == [5, 6]
assert len(ca) == 0
ca = CA(1, 2, 3)
assert ca.popLD(42) == 1
assert ca.popRD(42) == 3
assert ca.popLD(42) == 2
assert ca.popRD(42) == 42
assert ca.popLD(42) == 42
assert len(ca) == 0
```
---
[1]: https://pypi.org/project/grscheller.circular-array
[2]: https://github.com/grscheller/circular-array
[3]: https://grscheller.github.io/grscheller-pypi-namespace-docs/circular-array/
Raw data
{
"_id": null,
"home_page": null,
"name": "grscheller.circular-array",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "circular array, circle array, CA, double ended queue, dequeue, dqueue, pop, push, popL, popR, pushL, pushR, indexable, auto-resizing, auto resizing, resizing",
"author": null,
"author_email": "\"Geoffrey R. Scheller\" <geoffrey@scheller.com>",
"download_url": "https://files.pythonhosted.org/packages/aa/42/a23ae811320f4f7f07445d77b1730936318b0bd443f33a84626b3d32cd54/grscheller_circular_array-3.8.1.tar.gz",
"platform": null,
"description": "# Python Circular Array Implementation\n\nPython module implementing an indexable, double sided,\nauto-resizing queue data structure.\n\n* **Repositories**\n * [grscheller.circular-array][1] project on *PyPI*\n * [Source code][2] on *GitHub*\n* **Detailed documentation**\n * [Detailed API documentation][3] on *GH-Pages*\n\n### Overview\n\nUseful if used directly as an improved version of a Python List or in\na \"has-a\" relationship when implementing other data structures.\n\n* O(1) pushes and pops either end.\n* O(1) indexing\n* now fully supports slicing!\n\n### Usage\n\n```python\nfrom grscheller.circular_array.ca import CA\n\nca = CA(1, 2, 3)\nassert ca.popL() == 1\nassert ca.popR() == 3\nca.pushR(42, 0)\nca.pushL(0, 1)\nassert repr(ca) == 'CA(1, 0, 2, 42, 0)'\nassert str(ca) == '(|1, 0, 2, 42, 0|)'\n\nca = CA(*range(1,11))\nassert repr(ca) == 'CA(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)'\nassert str(ca) == '(|1, 2, 3, 4, 5, 6, 7, 8, 9, 10|)'\nassert len(ca) == 10\ntup3 = ca.popLT(3)\ntup4 = ca.popRT(4)\nassert tup3 == (1, 2, 3)\nassert tup4 == (10, 9, 8, 7)\n\nassert ca == CA(4, 5, 6)\nfour, *rest = ca.popFT(1000)\nassert four == 4\nassert rest == [5, 6]\nassert len(ca) == 0\n\nca = CA(1, 2, 3)\nassert ca.popLD(42) == 1\nassert ca.popRD(42) == 3\nassert ca.popLD(42) == 2\nassert ca.popRD(42) == 42\nassert ca.popLD(42) == 42\nassert len(ca) == 0\n```\n\n---\n\n[1]: https://pypi.org/project/grscheller.circular-array\n[2]: https://github.com/grscheller/circular-array\n[3]: https://grscheller.github.io/grscheller-pypi-namespace-docs/circular-array/\n",
"bugtrack_url": null,
"license": null,
"summary": "### Circular Array",
"version": "3.8.1",
"project_urls": {
"Changelog": "https://github.com/grscheller/circular-array/blob/main/CHANGELOG.md",
"Documentation": "https://grscheller.github.io/grscheller-pypi-namespace-docs/circular-array",
"Source": "https://github.com/grscheller/circular-array"
},
"split_keywords": [
"circular array",
" circle array",
" ca",
" double ended queue",
" dequeue",
" dqueue",
" pop",
" push",
" popl",
" popr",
" pushl",
" pushr",
" indexable",
" auto-resizing",
" auto resizing",
" resizing"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4f621bda3ada964a5457f8cb2546126d30ff31a842ef9e494d49f7197307ec28",
"md5": "ebc2132988082cf86c4a96b39f82d595",
"sha256": "d3d6a5bf548914b489802399f7889430ab72033ceca7f590231c5f2ad8ef5746"
},
"downloads": -1,
"filename": "grscheller_circular_array-3.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebc2132988082cf86c4a96b39f82d595",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 10542,
"upload_time": "2025-01-03T20:38:13",
"upload_time_iso_8601": "2025-01-03T20:38:13.061883Z",
"url": "https://files.pythonhosted.org/packages/4f/62/1bda3ada964a5457f8cb2546126d30ff31a842ef9e494d49f7197307ec28/grscheller_circular_array-3.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "aa42a23ae811320f4f7f07445d77b1730936318b0bd443f33a84626b3d32cd54",
"md5": "b7e3b2db6a7ab101686f9f731c05b18d",
"sha256": "1fafb08121252b46a7e87028f7796dff7292527a1de7aeb36af797aca7e09b23"
},
"downloads": -1,
"filename": "grscheller_circular_array-3.8.1.tar.gz",
"has_sig": false,
"md5_digest": "b7e3b2db6a7ab101686f9f731c05b18d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 15510,
"upload_time": "2025-01-03T20:38:16",
"upload_time_iso_8601": "2025-01-03T20:38:16.397348Z",
"url": "https://files.pythonhosted.org/packages/aa/42/a23ae811320f4f7f07445d77b1730936318b0bd443f33a84626b3d32cd54/grscheller_circular_array-3.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-03 20:38:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "grscheller",
"github_project": "circular-array",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "grscheller.circular-array"
}