Skip to main content

High-performance autoincremented integer-valued mappings.

Project description

automap

latest versionlatest release datebuild statusissues


automap is a Python package containing high-performance autoincremented integer-valued mappings.

To install, just run pip install automap.

Examples

automap objects are sort of like "inverse sequences". They come in two variants:

FrozenAutoMap

>>> from automap import FrozenAutoMap

FrozenAutoMap objects are immutable. They can be constructed from any iterable of hashable, unique keys.

>>> a = FrozenAutoMap("AAA")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 'A'
>>> a = FrozenAutoMap("ABC")
>>> a
automap.FrozenAutoMap(['A', 'B', 'C'])

The values are integers, incrementing according to the order of the original keys:

>>> a["A"]
0
>>> a["C"]
2
>>> a["X"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'X'

The full Mapping interface is provided:

>>> [*a.keys()]
['A', 'B', 'C']
>>> [*a.values()]
[0, 1, 2]
>>> [*a.items()]
[('A', 0), ('B', 1), ('C', 2)]
>>> a.get("X", 42)
42
>>> "B" in a
True
>>> [*a]
['A', 'B', 'C']

They may also be combined with each other using the | operator:

>>> b = FrozenAutoMap(range(5))
>>> c = FrozenAutoMap(range(5, 10))
>>> b | c
automap.FrozenAutoMap([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> b |= c  # Note that b is reassigned, not mutated!
>>> b
automap.FrozenAutoMap([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

AutoMap

>>> from automap import AutoMap

Unlike FrozenAutoMap objects, AutoMap objects can grow; new keys may be added, but existing ones may not be deleted or changed.

>>> d = AutoMap("ABC")
>>> d
automap.AutoMap(['A', 'B', 'C'])
>>> d |= "DEF"  # Here, d *is* mutated!
>>> d
automap.AutoMap(['A', 'B', 'C', 'D', 'E', 'F'])

They also have add and update methods for adding new keys:

>>> e = AutoMap(["I", "II", "III"])
>>> e.add("IV")
>>> e
automap.AutoMap(['I', 'II', 'III', 'IV'])
>>> e.update(["V", "VI", "VII"])
>>> e
automap.AutoMap(['I', 'II', 'III', 'IV', 'V', 'VI', 'VII'])

Performance

Tests show string-keyed AutoMap objects being created 75% faster and accessed 10% faster than the equivalent dict construction. They tend to take up the same amount of memory, on average. You can run invoke performance from this repository to see the comparison on your machine.

More details on the design can be found in automap.c.

Project details


Download files

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

Files for automap, version 0.4.6
Filename, size File type Python version Upload date Hashes
Filename, size automap-0.4.6-cp36-cp36m-macosx_10_6_intel.whl (10.3 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp36-cp36m-manylinux1_x86_64.whl (30.5 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp36-cp36m-win32.whl (10.9 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp36-cp36m-win_amd64.whl (12.3 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp37-cp37m-macosx_10_6_intel.whl (10.3 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp37-cp37m-manylinux1_x86_64.whl (30.5 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp37-cp37m-win32.whl (10.9 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp37-cp37m-win_amd64.whl (12.3 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp38-cp38-macosx_10_6_intel.whl (10.5 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp38-cp38-manylinux1_x86_64.whl (32.2 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp38-cp38-win32.whl (11.0 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size automap-0.4.6-cp38-cp38-win_amd64.whl (12.4 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size automap-0.4.6.tar.gz (10.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page