Skip to main content

### Circular Array

Project description

Python Circular Array Implementation

Python module implementing an indexable, double sided, auto-resizing queue data structure.

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
  • does not support slicing

Usage

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grscheller_circular_array-3.7.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

grscheller_circular_array-3.7.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file grscheller_circular_array-3.7.0.tar.gz.

File metadata

File hashes

Hashes for grscheller_circular_array-3.7.0.tar.gz
Algorithm Hash digest
SHA256 aaab44bf8526db2d345a65bc564e35cbb12e4ac6b94feb939ce30a7fe222e8af
MD5 c94b804c16bc3357d59ded39f40bf9f2
BLAKE2b-256 5bf2832157243bf5f01f736a895b38293ded27ea835e0c7ae99a9f5f59828021

See more details on using hashes here.

File details

Details for the file grscheller_circular_array-3.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for grscheller_circular_array-3.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ab7e08c7a264fce54d4eea608bc6088bc3c6a9ef2700ad382d8d2e9d12e5e6f
MD5 992d252bd79b1ffe2349c8400a9abb58
BLAKE2b-256 ceb185c6738669c1d9f26b34e3c2f0f13393d9f76f40739d0a7ae2853c8dcca9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page