Skip to main content

Python Soft Heap Implementation

Project description

Soft Heap in Python

This library is a full python implementation of Bernard Chazelle's soft heap [1].

The soft heap is a heap-like data structure which gives all heap operations a constant runtime, with the exception of insert. However, in order to maintain this seemingly impossible runtime, some of the data is "corrupted". The result of this is that insert takes O(log 1/e) where e is the rate of corruption.

[1] http://www.cs.cmu.edu/afs/cs/academic/class/15859-f05/www/documents/p1012-chazelle.pdf

Usage

To get started, import the module. We'll also import random for this example.

from softheap import *
import random

The soft heap requires one input, the error rate r. The number of corrupted nodes in the heap is inversely proportional to r.

s = SoftHeap(2)

We can test the heap by randomly inserting 100 elements into the heap.

arr = list(range(100))
random.shuffle(arr)

for a in arr:
  s.insert(a)

Now when we deletemin repeatedly, the output will be approximately sorted.

output = []

for b in range(len(arr))
  output.append(s.deletemin())

print(output)

This takes O(n log 1/e) time.

Installation

Use pip to install softheap. Via the command line:

pip install softheap

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

softheap-0.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

softheap-0.2-py2-none-any.whl (3.8 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: softheap-0.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for softheap-0.2.tar.gz
Algorithm Hash digest
SHA256 442d5c0a86cf445a05cdd86510972e67e022eabdec0db11375270db60882ea89
MD5 052650c2f83a5eef4a43ce6ba81c816a
BLAKE2b-256 9d066bc74e02d2b5129ec0caec7ab2650264df0b0ca1543fa5e2048ad2be13ad

See more details on using hashes here.

File details

Details for the file softheap-0.2-py2-none-any.whl.

File metadata

  • Download URL: softheap-0.2-py2-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for softheap-0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 306e86a9dcf6271977e31332361350a49c7485138eefb94a210510a0ca7bd446
MD5 c934629b86cba4a71e0ef0254576e6af
BLAKE2b-256 e8d4cdab50442713d46f0044ddbd3c8d5eb9334682370a2ee8dcd1efa45324bc

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