Skip to main content

Count-Min Sketch based memory-efficient key-value structure (using Madoka C++ library)

Project description

Madoka

Madoka is an implementation of a Count-Min sketch, a data structure for summarizing data streams.

String-int pairs in a Madoka-Sketch may take less memory than in a standard Python dict.

Based on madoka C++ library.

Installation

$ pip install madoka

Usage

Create a new sketch

>>> import madoka
>>> sketch = madoka.Sketch()
>>> sketch.create()
  • create(width = 0, max_value = 0, path = NULL, flags = 0, seed = 0)

Increment a key value

>>> sketch.inc('mami', 6)
  • inc(key, byte_size)

Add a value to current key value

>>> sketch.add('mami', 6, 3)
  • add(key, byte_size, value)

    • The byte_size argument is a range of a value.

Update a key value

>>> sketch.set('mami', 6, 2)
  • set(key, byte_size, value)

    • Note that set() does nothing when the given value is not greater than the current key value.

    • Also note that the new value is saturated when the given value is greater than the upper limit.

Get a key value

>>> sketch.get('mami', 6)
  • get(key, byte_size)

Save a sketch to a file

>>> sketch.save('example.madoka')
  • save(filename)

Load a sketch from a file

>>> sketch.save('example.madoka')
  • save(filename)

Clear a sketch

>>> sketch.clear()

Copy a sketch

>>> sketch.copy(othersketch)
  • copy(Sketch)

Merge two sketches

>>> sketch.merge(othersketch)
  • merge(Sketch)

Get inner product of two sketches

>>> sketch.inner_product(othersketch)
  • inner_product(Sketch)

Current limitations

  • Sketch.filter() doesn’t work;

Contributions are welcome!

License

  • Wrapper code is licensed under New BSD License.

  • Bundled madoka C++ library is licensed under the Simplified BSD License.

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

madoka-0.1.tar.gz (59.7 kB view details)

Uploaded Source

File details

Details for the file madoka-0.1.tar.gz.

File metadata

  • Download URL: madoka-0.1.tar.gz
  • Upload date:
  • Size: 59.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for madoka-0.1.tar.gz
Algorithm Hash digest
SHA256 83c7e29a05895102164f243164381c2b1a3a21cfcba6addbfeab6d7462b9e466
MD5 7c31a516146c0f4286e2595598c15975
BLAKE2b-256 e69eb514d7024cbc118d7ca8e8d0d50af14fb2af500405a99cfbe25ac589c89e

See more details on using hashes here.

Provenance

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