Skip to main content

A collection of optimized N-dimensional data structures in Python

Project description

N-Dimensional Data Structures

A library providing generalized N-dimensional data structures for C++ and Python.

Data Structures Included

  1. Static N-Dim Prefix Sum (static_n_dim_prefix_sum)
  2. Static N-Dim Difference Array (static_n_dim_difference_array)
  3. Dynamic N-Dim Fenwick Tree (dynamic_n_dim_fenwick_tree)
  4. Dynamic N-Dim Difference Fenwick Tree (dynamic_n_dim_diff_fenwick_tree)
  5. Dynamic N-Dim Range Fenwick Tree (dynamic_n_dim_range_fenwick_tree)
  6. Dynamic N-Dim Segment Tree (dynamic_n_dim_seg_tree)

C++ Usage

The cpp/include/ndim/ directory contains header-only C++23 templates formatted for competitive programming. They use #include <bits/stdc++.h> and using namespace std;.

Example

#include "dynamic_n_dim_seg_tree.hpp"

// Example: 3D Segment Tree using std::min
auto min_func = [](int64_t a, int64_t b) { return min(a, b); };
int64_t def = 1e18;

// 4x4x4 grid
DynamicNDimSegTree<int64_t, decltype(min_func)> tree({4, 4, 4}, min_func, def);

tree.update({1, 1, 1}, 5);
tree.update({2, 2, 2}, 10);

int64_t val = tree.query_range({0, 0, 0}, {3, 3, 3});

Python Usage

The python/src/ directory contains the Python implementations. The package is available on PyPI.

Installation

pip install ndim_ds

Example

from static_n_dim_prefix_sum import StaticNDimPrefixSum

# 10x10x10 grid
grid = StaticNDimPrefixSum([10, 10, 10])

grid.add([1, 1, 1], 50)
grid.add([5, 5, 5], 25)
grid.sweep()

total = grid.query_range([0, 0, 0], [3, 3, 3])

Testing

  • Python: Run uv run pytest test/
  • C++: Compile the files in cpp/test/ using g++ -std=c++23 and run the resulting executables.

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

ndim_ds-0.1.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

ndim_ds-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file ndim_ds-0.1.2.tar.gz.

File metadata

  • Download URL: ndim_ds-0.1.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.13

File hashes

Hashes for ndim_ds-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d03d51d3a89be0472bfaa6df229dd7ba47e26b80c75d32d255f57bc72bc3efbf
MD5 ccb6a4fb02fe4d2a5286a662a0cf77bb
BLAKE2b-256 7c7ae63780a4fe7eb8a0895ade29eaabbf83b6d32f906afc9c08784a460c4b1c

See more details on using hashes here.

File details

Details for the file ndim_ds-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ndim_ds-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.13

File hashes

Hashes for ndim_ds-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b056ea053d53fc9f5c0435421ac96d07fc63a0fe4ef6a02bc2b10b8e761ae9dd
MD5 0a2af859c37bf82738e0c65023f22be4
BLAKE2b-256 f5a5141be21110e0e9e57aaf7aef5cfe1546f158a8c79031ba47ade163a1d340

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