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:
commit
d3a762ea9f
|
@ -11,5 +11,5 @@ python setup.py install
|
|||
```python
|
||||
from word_count_cls import WordCounter
|
||||
|
||||
WordCounter().search('path/to/file', 'word')
|
||||
```
|
||||
WordCounter('path/to/file').search('word')
|
||||
```
|
|
@ -13,17 +13,17 @@ use rayon::prelude::*;
|
|||
use pyo3::prelude::*;
|
||||
|
||||
#[py::class]
|
||||
struct Words {
|
||||
struct WordCounter {
|
||||
path: String,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::methods]
|
||||
impl Words {
|
||||
impl WordCounter {
|
||||
|
||||
#[new]
|
||||
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> {
|
||||
|
@ -85,7 +85,7 @@ fn wc_parallel(lines: &str, search: &str) -> i32 {
|
|||
|
||||
#[py::modinit(_word_count)]
|
||||
fn init_mod(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_class::<Words>()?;
|
||||
m.add_class::<WordCounter>()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -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):
|
||||
count = benchmark(word_count_cls.Words(path).search, 'is')
|
||||
count = benchmark(word_count_cls.WordCounter(path).search, 'is')
|
||||
assert count == 10000
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue