Skip to content

Commit 618a094

Browse files
committed
feat: add gxhash Python bindings
1 parent eab2961 commit 618a094

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

py-gxhash/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "py-gxhash"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
name = "gxhash"
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
pyo3 = "0.22.0"
12+
gxhash = { path = "..", features = ["hybrid"] }

py-gxhash/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# py-gxhash
2+
3+
```bash
4+
uv venv --seed
5+
uv run maturin develop
6+
```

py-gxhash/gxhash.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def gxhash32(input: bytes, seed: int) -> int: ...
2+
def gxhash64(input: bytes, seed: int) -> int: ...
3+
def gxhash128(input: bytes, seed: int) -> int: ...

py-gxhash/pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[build-system]
2+
requires = ["maturin>=1.7,<2.0"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "gxhash"
7+
requires-python = ">=3.7"
8+
dynamic = ["version"]
9+
classifiers = [
10+
"Programming Language :: Rust",
11+
"Programming Language :: Python :: Implementation :: CPython",
12+
"Programming Language :: Python :: Implementation :: PyPy",
13+
]
14+
15+
[tool.maturin]
16+
features = ["pyo3/extension-module"]
17+
18+
[dependency-groups]
19+
dev = ["maturin>=1.7.4"]

py-gxhash/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use pyo3::prelude::*;
2+
3+
#[pyfunction]
4+
fn gxhash32(input: &[u8], seed: i64) -> PyResult<u32> {
5+
Ok(gxhash::gxhash32(input, seed))
6+
}
7+
8+
#[pyfunction]
9+
fn gxhash64(input: &[u8], seed: i64) -> PyResult<u64> {
10+
Ok(gxhash::gxhash64(input, seed))
11+
}
12+
13+
#[pyfunction]
14+
fn gxhash128(input: &[u8], seed: i64) -> PyResult<u128> {
15+
Ok(gxhash::gxhash128(input, seed))
16+
}
17+
18+
#[pymodule(name = "gxhash")]
19+
fn pygxhash(m: &Bound<'_, PyModule>) -> PyResult<()> {
20+
m.add_function(wrap_pyfunction!(gxhash32, m)?)?;
21+
m.add_function(wrap_pyfunction!(gxhash64, m)?)?;
22+
m.add_function(wrap_pyfunction!(gxhash128, m)?)?;
23+
Ok(())
24+
}

0 commit comments

Comments
 (0)