Skip to main content

Copy-on-write dictionary

Project description

cowdict is a python module implementing copy-on-write pattern on dictionaries.

This means that if someone change the dict-like object, the original object won’t be changed but the differences will be tracked instead.

Nutshell

Here’s a small example:

base_dict = {"foo": "bar"}
cd = CowDict(base_dict)
cd["foo"] = "baz"

print(base_dict["foo"]) # will still print 'bar'
print(cd["foo"]) # will print 'baz'

CowDict object (cd in the code above) implements the MutableMapping interface, simply speaking it has the same interface as the dict object.

This means that it is guaranteed that changing keys/values on this object will never cause the change of the underlying dictionary (base_dict in the example).

Philosophy

The idea behind this module is to avoid copying dictionary where it is possible and use this wrapper class instead. While it has some penalties on the performance on key lookup and length calculation, the memory footprint can be kept at minimum (compared to a full copy of the dictionary).

Behind the scenes

Behind the scenes, new items are added to a separate directory. Keys which exist on the base dictionary are ‘deleted’ by keeping a separate set object about the the keys deleted. Every time when a key is accessed either by getitem or items or other methods, these additional structures are involved to produce the correct result.

While having an assumption of having the base dictionary read-only would make the world easier, especially when calculating the length of the object, the library handles the situation when the base dictionary changes.

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

cowdict-0.2.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

cowdict-0.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file cowdict-0.2.tar.gz.

File metadata

  • Download URL: cowdict-0.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cowdict-0.2.tar.gz
Algorithm Hash digest
SHA256 ee21a35f43ab9f8ad205121220b020aba1342e5285f230bb7110953809d38703
MD5 d838fad2571474dbe0f2be3188a563b7
BLAKE2b-256 ee0ceff9b399cb8311235fceb85a194b7ff973a7833efee5db2f47459403d979

See more details on using hashes here.

File details

Details for the file cowdict-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cowdict-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 46d9d19b52451e55857f0bc02403d912aa731da288938dea374558469f955195
MD5 83cf9d1f3d8475abb7ca7238ae65ca80
BLAKE2b-256 cd9a3220db473587729fcd02175f368cba92ec9d4e9130034a6ae798b3fa8d4b

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