Merge pull request #127 from d0c-s4vage/hotfix-fix_word_count_cls_example-126

Synchronizes word-count-cls example README and code
This commit is contained in:
Nikolay Kim 2018-02-26 13:18:38 -08:00 committed by GitHub
commit d3a762ea9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View file

@ -11,5 +11,5 @@ python setup.py install
```python ```python
from word_count_cls import WordCounter from word_count_cls import WordCounter
WordCounter().search('path/to/file', 'word') WordCounter('path/to/file').search('word')
``` ```

View file

@ -13,17 +13,17 @@ use rayon::prelude::*;
use pyo3::prelude::*; use pyo3::prelude::*;
#[py::class] #[py::class]
struct Words { struct WordCounter {
path: String, path: String,
token: PyToken, token: PyToken,
} }
#[py::methods] #[py::methods]
impl Words { impl WordCounter {
#[new] #[new]
fn __new__(obj: &PyRawObject, path: String) -> PyResult<()> { fn __new__(obj: &PyRawObject, path: String) -> PyResult<()> {
obj.init(|t| Words {path: path, token: t}) obj.init(|t| WordCounter {path: path, token: t})
} }
fn search(&self, py: Python, search: String) -> PyResult<i32> { fn search(&self, py: Python, search: String) -> PyResult<i32> {
@ -85,7 +85,7 @@ fn wc_parallel(lines: &str, search: &str) -> i32 {
#[py::modinit(_word_count)] #[py::modinit(_word_count)]
fn init_mod(_py: Python, m: &PyModule) -> PyResult<()> { fn init_mod(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<Words>()?; m.add_class::<WordCounter>()?;
Ok(()) Ok(())
} }

View file

@ -41,12 +41,12 @@ Namespaces are one honking great idea -- let's do more of those!\n''' * 1000
def test_word_count_rust_parallel(benchmark): def test_word_count_rust_parallel(benchmark):
count = benchmark(word_count_cls.Words(path).search, 'is') count = benchmark(word_count_cls.WordCounter(path).search, 'is')
assert count == 10000 assert count == 10000
def test_word_count_rust_sequential(benchmark): def test_word_count_rust_sequential(benchmark):
count = benchmark(word_count_cls.Words(path).search_sequential, 'is') count = benchmark(word_count_cls.WordCounter(path).search_sequential, 'is')
assert count == 10000 assert count == 10000

View file

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import from __future__ import absolute_import
from ._word_count import Words from ._word_count import WordCounter
__all__ = ['Words', 'search_py'] __all__ = ['WordCounter', 'search_py']
def search_py(path, needle): def search_py(path, needle):