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
- Static N-Dim Prefix Sum (
static_n_dim_prefix_sum) - Static N-Dim Difference Array (
static_n_dim_difference_array) - Dynamic N-Dim Fenwick Tree (
dynamic_n_dim_fenwick_tree) - Dynamic N-Dim Difference Fenwick Tree (
dynamic_n_dim_diff_fenwick_tree) - Dynamic N-Dim Range Fenwick Tree (
dynamic_n_dim_range_fenwick_tree) - 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/usingg++ -std=c++23and 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ndim_ds-0.1.1.tar.gz.
File metadata
- Download URL: ndim_ds-0.1.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
060fbd091469a432812e15b8ce1dc723144a9697fb68b7a9ac0e8482c5c02a23
|
|
| MD5 |
74af52d8ecad2e5389faf54463f5c391
|
|
| BLAKE2b-256 |
97f65fe1fa345b5f4d274263b8083637bce5f2b223d0debd4a7c52e95ba0c633
|
File details
Details for the file ndim_ds-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ndim_ds-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afdeedc3cccf105bf104208d91adafc02d91f2f29b753c40d3275c8f2f626bca
|
|
| MD5 |
a8e6f05f8112652e93e939fc0e9eb3d5
|
|
| BLAKE2b-256 |
949195d32ec6c3ca8b84900ebda9eded1f2026045d10f312629de74b9aa22486
|