Skip to main content

Segment Tree written in C as a Python Module

This is a Segment Tree written in C, made available as a Python package.

It supports basic min/max/sum queries which all happen in log(n) time. It also supports update queries in log(n) time.

Usage Examples

> from segtree import Segtree
> obj = Segtree([1, 2, 3, 4, 5], 'sum') # Accepted types: 'sum', 'min', 'max
> obj.sum(0, 3)                         # Gets range sum in log(n) time
> obj.update(0, 50)                     # Updates index 0 to value 50 in log(n) time
> from segtree import Segtree
> obj = Segtree([1, 2, 3, 4, 5], 'min')
> obj.min(0, 3)
> obj.update(0, 50)
> from segtree import Segtree
> obj = Segtree([1, 2, 3, 4, 5], 'max')
> obj.max(0, 3)
> obj.update(0, 50)

Download files

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

Source Distribution

c-segment-tree-1.0.tar.gz (18.4 kB view details)

Uploaded Source

File details

Details for the file c-segment-tree-1.0.tar.gz.

File metadata

  • Download URL: c-segment-tree-1.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for c-segment-tree-1.0.tar.gz
Algorithm Hash digest
SHA256 95c66ddade697885fbb4f9e5b0d8cdc1ea08749a8eba9573eb51c2a0253903f5
MD5 6c0694d8368a71b1ec0e9033a9c3df5c
BLAKE2b-256 a0a9b13fcd3f2b2a6a465c9fe4381d5ef453147a9e03960bcebebf4f91949c38

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0

Supported by

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