File tree Expand file tree Collapse file tree 6 files changed +63
-16
lines changed Expand file tree Collapse file tree 6 files changed +63
-16
lines changed Original file line number Diff line number Diff line change @@ -158,3 +158,4 @@ cython_debug/
158158# and can be added to the global gitignore or merged into this file. For a more nuclear
159159# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160.idea /
161+ .vscode /
Original file line number Diff line number Diff line change 11[package ]
22name = " iotext"
3+ authors = [" Marcin Bielak <marcin.bieli@gmail.com>" ]
34version = " 0.1.0"
45rust-version = " 1.57.0"
56edition = " 2021"
67
78[lib ]
8- name = " _iotext "
9+ name = " iotext "
910crate-type = [" cdylib" ]
1011
1112[dependencies ]
12- pyo3 = { version = " 0.19.2" , features = [" auto-initialize " , " extension-module" ] }
13+ pyo3 = { version = " 0.19.2" , features = [" extension-module" ] }
1314iotext_rs = { git = " https://github.com/bieli/IoText-rs.git" }
15+ rayon = " 1.0.2"
16+
17+ # [lib]
18+ # name = "_iotext"
19+ # crate-type = ["cdylib"]
20+
21+ # pyo3 = { version = "0.19.2", features = ["auto-initialize", "extension-module"] }
22+ # iotext_rs = { git = "https://github.com/bieli/IoText-rs.git" }
1423# dependencies
15- fancy-regex = " 0.11.0"
16- regex = " 1.9.4"
17- rustc-hash = " 1.1.0"
18- bstr = " 1.6.1"
24+ # fancy-regex = "0.11.0"
25+ # regex = "1.9.4"
26+ # rustc-hash = "1.1.0"
27+ # bstr = "1.6.1"
1928
20- [profile .release ]
21- incremental = true
29+ # [profile.release]
30+ # incremental = true
Original file line number Diff line number Diff line change 1+ from .iotext import search
2+
3+ __all__ = [
4+ "search"
5+ ]
Original file line number Diff line number Diff line change 1+ import nox
2+
3+ nox .options .sessions = ["test" ]
4+
5+
6+ @nox .session
7+ def test (session ):
8+ session .install ("-rrequirements-dev.txt" )
9+ session .install ("maturin" )
10+ session .run_always ("maturin" , "develop" )
11+ session .run ("pytest" )
12+
13+
14+ @nox .session
15+ def bench (session ):
16+ session .install ("-rrequirements-dev.txt" )
17+ session .install ("." )
18+ session .run ("pytest" , "--benchmark-enable" )
Original file line number Diff line number Diff line change 1+ nox
12mypy
23black == 22.3.0
34parameterized == 0.9.0
Original file line number Diff line number Diff line change 22#![ allow( clippy:: borrow_deref_ref) ]
33
44use pyo3:: prelude:: * ;
5+ use rayon:: prelude:: * ;
56
6- /// Formats the sum of two numbers as string.
7+ /// Searches for the word, parallelized by rayon
78#[ pyfunction]
8- fn sum_as_string ( a : usize , b : usize ) -> PyResult < String > {
9- Ok ( ( a + b) . to_string ( ) )
9+ fn search ( contents : & str , needle : & str ) -> usize {
10+ contents
11+ . par_lines ( )
12+ . map ( |line| count_line ( line, needle) )
13+ . sum ( )
14+ }
15+
16+ /// Count the occurrences of needle in line, case insensitive
17+ fn count_line ( line : & str , needle : & str ) -> usize {
18+ let mut total = 0 ;
19+ for word in line. split ( ' ' ) {
20+ if word == needle {
21+ total += 1 ;
22+ }
23+ }
24+ total
1025}
1126
12- /// A Python module implemented in Rust. The name of this function must match
13- /// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
14- /// import the module.
1527#[ pymodule]
16- fn string_sum ( _py : Python < ' _ > , m : & PyModule ) -> PyResult < ( ) > {
17- m. add_function ( wrap_pyfunction ! ( sum_as_string, m) ?) ?;
28+ fn iotext ( _py : Python < ' _ > , m : & PyModule ) -> PyResult < ( ) > {
29+ m. add_function ( wrap_pyfunction ! ( search, m) ?) ?;
30+
1831 Ok ( ( ) )
1932}
You can’t perform that action at this time.
0 commit comments