Skip to content

Commit

Permalink
Add docstrings in py_module
Browse files Browse the repository at this point in the history
  • Loading branch information
europeanplaice committed Feb 21, 2022
1 parent aac1b36 commit 2ce7e36
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/env
build.bat
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subset_sum"
version = "0.10.1"
version = "0.10.2"
edition = "2018"
authors = ["Tomohiro Endo <europeanplaice@gmail.com>"]
description = "Solves subset sum problem and returns a set of decomposed integers. It also can match corresponding numbers from two vectors and be used for Account reconciliation."
Expand Down
13 changes: 13 additions & 0 deletions src/py_module.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
use pyo3::prelude::*;

/// Finds subsets sum of a target value. It can accept negative values.
#[pyfunction]
#[pyo3(text_signature = "(a, n, /)")]
fn find_subset(a: Vec<i32>, n: i32) -> PyResult<Vec<Vec<i32>>> {
use crate::dp_module::*;
Ok(dp::find_subset(&a, n))
}

/// Finds subsets sum of a target value. It can't accept negative values but relatively faster.
#[pyfunction]
#[pyo3(text_signature = "(a, n, /)")]
fn find_subset_fast_only_positive(a: Vec<u32>, n: usize) -> PyResult<Vec<Vec<u32>>> {
use crate::dp_module::*;
Ok(dp::find_subset_fast_only_positive(&a, n))
}

/// Finds the integers from two vectors that sum to the same value.
/// This method assumes that the two vectors have One-to-Many relationships.
/// Each integer of the `key` vector corresponds to the multiple integers of the `value` vector.
#[pyfunction]
#[pyo3(text_signature = "(key, targets, /)")]
fn sequence_matcher(mut key: Vec<i32>, mut targets: Vec<i32>) -> PyResult<Vec<Vec<(Vec<i32>, i32)>>> {
use crate::dp_module::*;
Ok(dp::sequence_matcher(&mut key, &mut targets))
}

/// Finds the integers from two vectors that sum to the same value.
/// This method assumes that the two vectors have Many-to-Many relationships.
/// Each integer of the `key` vector corresponds to the multiple integers of the `value` vector.
/// With this method, we can find multiple combinations of the integers.
#[pyfunction]
#[pyo3(text_signature = "(key, targets, /)")]
fn sequence_matcher_m2m(mut key: Vec<i32>, mut targets: Vec<i32>) -> PyResult<Vec<Vec<(Vec<i32>, i32)>>> {
use crate::dp_module::*;
Ok(dp::sequence_matcher(&mut key, &mut targets))
Expand Down

0 comments on commit 2ce7e36

Please sign in to comment.