Skip to content

Commit

Permalink
docs: bulk api docs (#5).
Browse files Browse the repository at this point in the history
  • Loading branch information
yankun1992 committed Feb 16, 2023
1 parent b22c25c commit 1b9162e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ assert bloom3.contains('hello')

```

there are some bulk api for python to reduce ffi cost between python and rust

```python
bloom = BloomFilter(100_000_000, 0.01)
inserts = [1, 2, 3, 4, 5, 6, 7, 9, 18, 68, 90, 100]
checks = [1, 2, 3, 4, 5, 6, 7, 9, 18, 68, 90, 100, 190, 290, 390]
results = [True, True, True, True, True, True, True, True, True, True, True, True, False, False, False]

bloom.add_int_batch(inserts)
contains = bloom.contains_int_batch(checks)
assert contains == results

bloom.add_str_batch(list(map(lambda x: str(x), inserts)))
assert bloom.contains_str_batch(list(map(lambda x: str(x), checks))) == results

bloom.add_bytes_batch(list(map(lambda x: bytes(x), inserts)))
assert bloom.contains_bytes_batch(list(map(lambda x: bytes(x), checks))) == results
```

more examples at [py_tests](py_tests/test_bloom.py).

### Rust
Expand Down
19 changes: 19 additions & 0 deletions docs/README.zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ assert bloom3.contains('hello')

```

由于python与rust之间的数据转换有一定的性能开销,所以`fastbloom`提供了一些批量操作api用于减少ffi开销

```python
bloom = BloomFilter(100_000_000, 0.01)
inserts = [1, 2, 3, 4, 5, 6, 7, 9, 18, 68, 90, 100]
checks = [1, 2, 3, 4, 5, 6, 7, 9, 18, 68, 90, 100, 190, 290, 390]
results = [True, True, True, True, True, True, True, True, True, True, True, True, False, False, False]

bloom.add_int_batch(inserts)
contains = bloom.contains_int_batch(checks)
assert contains == results

bloom.add_str_batch(list(map(lambda x: str(x), inserts)))
assert bloom.contains_str_batch(list(map(lambda x: str(x), checks))) == results

bloom.add_bytes_batch(list(map(lambda x: bytes(x), inserts)))
assert bloom.contains_bytes_batch(list(map(lambda x: bytes(x), checks))) == results
```

更多例子参考 [py_tests](py_tests/test_bloom.py).

### Rust
Expand Down

0 comments on commit 1b9162e

Please sign in to comment.