Giter Site home page Giter Site logo

tushushu / murmurust Goto Github PK

View Code? Open in Web Editor NEW
8.0 0.0 1.0 59 KB

Python binding of MurmurHash3 Rust implementation.

License: BSD 3-Clause "New" or "Revised" License

Python 70.31% Rust 26.24% Shell 3.45%
murmurhash3 pyo3 python rust hash mmh3 murmurhash

murmurust's Introduction

murmurust

pypi license unittest publish codestyle downloads downloads/month

What

Python binding of MurmurHash3 Rust implementation.

Requirements

  • Python: 3.8+
  • OS: Linux, MacOS and Windows

Installation

Run pip install mmr3

Benchmark

mmr3 is faster than mmh3 on average, which is a popular murmurhash3 library written in C/C++ and Python. For the details, please refer to benchmark.md.

Item XS S M L XL Average Faster
Hash32 1.9x 1.8x 1.8x 1.3x 1.0x 1.6x Y
Hash128 1.9x 1.9x 1.8x 1.5x 1.0x 1.6x Y

Examples

>>> import mmr3
# By default, seed=0, return unsigned int.
>>> mmr3.hash32('foo')
4138058784

# When seed = 100.
>>> mmr3.hash32('foo', seed=100)
3757588558

# Return signed int.
>>> mmr3.hash32('foo', signed=True)
-156908512

# hash128 for x64 architecture
>>> mmr3.hash128_x64('foo', seed=20, signed=True)
-114440907836743398687870327469607863688

murmurust's People

Contributors

tushushu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

yutiansut

murmurust's Issues

Support Numpy array.

By calling Numpy C-API, implement hash functions for Numpy array. For example:

import numpy as np
import mmr3

arr = np.array(['foo', 'bar', 'baz'], dtype=object)
mmr3.hash32(arr)

Here is the Rust bindings for Numpy C-API: https://github.com/PyO3/rust-numpy

Support signed int as return value.

User can decide whether use signed int(i32) or unsigned int (u32) as hash32 function return type. For example:

>>> import mmh3
>>> mmh3.hash('foo', signed=False)
4138058784
>>> mmh3.hash('foo', signed=True)
-156908512
>>> mmh3.hash('foo')
-156908512

Recover clippy test.

The clippy test shows the errors below, which is not expected:

error: deref on an immutable reference
  --> src/lib.rs:80:34
   |
80 | fn hash128_x[64](https://github.com/tushushu/murmurust/runs/7928640580?check_suite_focus=true#step:6:65)(_py: Python, key: &str, seed: u32, signed: bool) -> Py<PyAny> {
   |                                  ^ help: if you would like to reborrow, try removing `&*`: `&`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref

This is going to be fixed by PyO3/pyo3#2555. Currently, I have to disable the clippy errors, and when PYO3 0.17.0 released, we need change it back.

Make parameter `seed` optional.

The default seed of hash32 function is zero, for example:

>>> import mmr3
>>> mmr3.hash32('foo')
4138058784
>>> mmr3.hash32('foo', 0)
4138058784

Implement hash128 function.

Need to implement hash128 function by Rust, and provide a Python wrapper. For the details, please refer to how we implement hash32 in this repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.