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 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>
KeyError: '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
>>> list(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 are growable; 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!
automap.AutoMap(['A', 'B', 'C', 'D', 'E', 'F'])

Performance

Preliminary tests show random string-keyed AutoMap objects being created 60-80% faster and accessed 10-30% faster than the equivalent dict construction. They tend to take up ~50% more RAM on average. You can run python performance.py from this repo 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.

Source Distribution

automap-0.0.0.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file automap-0.0.0.tar.gz.

File metadata

  • Download URL: automap-0.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.7.4

File hashes

Hashes for automap-0.0.0.tar.gz
Algorithm Hash digest
SHA256 a59dedcd4ab7093947fb1ce94c7f9c5da6bfcf41d7e3ea614a1e2074f14817b7
MD5 974e0c0eb66ec15bd8e205686d211d4c
BLAKE2b-256 aa2fc54ee1c43729753f74d657bcbc22cc277f948dc7ea9a5494556a30e08491

See more details on using hashes here.

Supported by

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