https://github.com/brianpugh/micropython-fnv1a32

Micropython native module for the FNV1a hashing algorithm.

https://github.com/brianpugh/micropython-fnv1a32

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.9%) to scientific vocabulary

Keywords

fnv hash hashing micropython native native-module python
Last synced: 5 months ago · JSON representation

Repository

Micropython native module for the FNV1a hashing algorithm.

Basic Info
  • Host: GitHub
  • Owner: BrianPugh
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 40 KB
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 4
Topics
fnv hash hashing micropython native native-module python
Created over 1 year ago · Last pushed 6 months ago
Metadata Files
Readme License

README.md

micropython-fnv1a32

FNV1a32 is a simple 32-bit hash function that is optimized for speed while maintaining a low collision rate.

This repo implements a micropython native module of the fnv1a32 hash function. To use a precompiled micropython native module, download the appropriate architecture/micropython-version from the release page. Requires MicroPython >1.22.0.

Usage

This library supplies a single function, fnv1a32, that can handle a variety of datatypes. The resulting hash is an integer object (not bytes!).

Hashing Data In-Memory

To hash bytes/bytearray/str in-memory:

```python from fnv1a32 import fnv1a32

fnv1a32_hash = fnv1a32(b"this is the data to be hashed") ```

To continue hashing, supply the previous hash into the next fnv1a32 invocation:

```python from fnv1a32 import fnv1a32

fnv1a32hash = fnv1a32(b"this is the data to be hashed") fnv1a32hash = fnv1a32(b"more data", fnv1a32_hash) ```

Hashing File

To hash a file:

```python from fnv1a32 import fnv1a32

with open("foo.bin") as f: # Defaults to using 4096-byte chunks fnv1a32_hash = fnv1a32(f) ```

To read and hash bigger chunks at a time (uses more memory, may improve speed):

```python from fnv1a32 import fnv1a32

with open("foo.bin") as f: fnv1a32_hash = fnv1a32(f, buffer=16384) ```

A pre-allocated buffer may also be used:

```python from fnv1a32 import fnv1a32

buffer = bytearray(16384) with open("foo.bin") as f: fnv1a32_hash = fnv1a32(f, buffer=buffer) ```

Unit Testing

To run the unittests, install Belay and run the following commands:

```bash make clean make

belay run micropython -m unittest tests/test_fnv1a32.py ```

Benchmark

The following were benchmarked on an rp2040 hashing 50KB of data in-memory.

| Implementation | Bytes/s | Relative Speed | |----------------------------|------------|----------------| | vanilla micropython | 24,912 | 1.00x | | @micropython.native | 26,619 | 1.07x | | @micropython.viper | 2,438,786 | 97.90x | | micropython native module | 25,906,736 | 1040x |

To run the benchmark, install Belay and run the following commands:

```bash export MPY_DIR=../micropython # Replace with your micropython directory. make clean ARCH=armv6m make # Change the arch if running on different hardware.

belay install /dev/ttyUSB0 --with=dev belay sync /dev/ttyUSB0 fnv1a32.mpy belay run /dev/ttyUSB0 benchmark/fnv1a32_benchmark.py ```

Owner

  • Name: Brian Pugh
  • Login: BrianPugh
  • Kind: user
  • Location: Washington D.C.

Deep Learning Scientist and blockchain enthusiast

GitHub Events

Total
  • Release event: 2
  • Push event: 5
  • Pull request event: 7
  • Create event: 6
Last Year
  • Release event: 2
  • Push event: 5
  • Pull request event: 7
  • Create event: 6

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 16
  • Total Committers: 1
  • Avg Commits per committer: 16.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 9
  • Committers: 1
  • Avg Commits per committer: 9.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Brian Pugh b****7@g****m 16

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: about 1 hour
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: about 1 hour
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • BrianPugh (4)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/mpy_native_module.yaml actions
  • BrianPugh/install-micropython v2 composite
  • actions/cache v4 composite
  • actions/checkout v4 composite
  • actions/download-artifact v4 composite
  • actions/setup-python v5 composite
  • actions/upload-artifact v4 composite
  • carlosperate/arm-none-eabi-gcc-action v1.8.1 composite
  • softprops/action-gh-release v2 composite
pyproject.toml pypi