feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support: - Splash screen on boot (1.5s) with project name, version, board - Dashboard showing radio state, config, counters, RSSI/SNR - RSSI history sparkline (64-sample ring buffer, 2px-wide bars) - DisplayOn/DisplayOff host commands routed via dedicated channel - Pure render functions against generic DrawTarget (no hardware coupling) - Display on/off control bypasses radio task entirely Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
17624 files changed
+4564928
-38
No files matched your search
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"files":{".cargo_vcs_info.json":"f886cb4552ea1974de3bb178c61a0a9ba3f4af9f7826182fd96574aa5893709d",".github/bors.toml":"1eefee7786efb5237fab3e74eb8704a917e8c1f235b967919cea14d4693a2b17",".github/workflows/ci.yml":"7acd475af1ccb8c462d9a8d99ceef08c93d2b87d63aa325eb78496bddc01e0b9",".travis.yml":"c31401333c62eaffbffb813638e5dc57164f8ba5cff3e8fae2ef45d1b5e76df4","CHANGELOG.md":"9d1499ff3a31f6677fe7d1b85c475a143fbe84b6702f6dc7f57c78bdf34dc89a","Cargo.lock":"a794e199c1cdf5d2b335200cd937c02e3209cfedab1207798e733b7928c49777","Cargo.toml":"167a05eea579dd60a0489ef2ecfe5dcc1353eca2189d7c10fb010fa28a5f7974","Cargo.toml.orig":"d31cd36d73f02708a83742aeb7012631c3878fa35eae831a9ea47b6190427914","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"c986bcdb83103d4ddf58aeb7b5302359782e54dc4eea14a0cc27c62dcbd50729","README.md":"4af21f69cb38d4651ca73b4c5d2191362d90f9804424ec79106f415c0928ae31","examples/derive.rs":"e64bcc2de0a285da4519f18928ba741987374ea9f0bb78848287ee8c754ef44c","src/fnv.rs":"db654d88ad27c6acd361a65a96140bbf0ad67505fd45692a3f36af284d7cd81b","src/lib.rs":"1619dfa22a88463e9ff4d65abdd6668f04655d7a1dc5caf121e4869af0871415","src/murmur3.rs":"49bd9828c48607a060cb4f4263de6d3954a2a2b41a054cb083560da4fac632eb"},"package":"47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "d44eb33a01be4582669d9a1fa3f7c58455a21de9"
|
||||
},
|
||||
"path_in_vcs": ""
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
delete_merged_branches = true
|
||||
status = ["ci"]
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
on:
|
||||
push:
|
||||
branches: [main, staging, trying]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
name: Continuous integration
|
||||
|
||||
jobs:
|
||||
test :
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
target:
|
||||
- x86_64-unknown-linux-gnu
|
||||
- i686-unknown-linux-musl
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
target: ${{ matrix.target }}
|
||||
override: true
|
||||
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --target ${{ matrix.target }}
|
||||
|
||||
ci-success:
|
||||
name: ci
|
||||
if: github.event_name == 'push' && success()
|
||||
needs:
|
||||
- test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Mark the job as a success
|
||||
run: exit 0
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
language: rust
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- env: TARGET=x86_64-unknown-linux-gnu
|
||||
- env: TARGET=x86_64-unknown-linux-gnu
|
||||
rust: nightly
|
||||
- env: TARGET=thumbv7m-none-eabi
|
||||
rust: nightly
|
||||
|
||||
before_install: set -e
|
||||
|
||||
install:
|
||||
- bash ci/install.sh
|
||||
|
||||
script:
|
||||
- bash ci/script.sh
|
||||
|
||||
after_script: set +e
|
||||
|
||||
cache: cargo
|
||||
|
||||
before_cache:
|
||||
- chmod -R a+r $HOME/.cargo;
|
||||
|
||||
branches:
|
||||
only:
|
||||
- staging
|
||||
- trying
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
||||
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [v0.3.1] - 2022-08-09
|
||||
|
||||
### Fixed
|
||||
|
||||
- fixed downstream clippy warnings around `murmur3::Hasher`
|
||||
|
||||
## [v0.3.0] - 2022-04-29
|
||||
|
||||
### Changed
|
||||
|
||||
- [breaking-change] Made `Hasher` a subtrait of `core::hash::Hasher`, and
|
||||
renamed `finish` to `finish32` to avoid conflicting
|
||||
- Relaxed some restrictions on `BuildHasherDefault`
|
||||
|
||||
### Removed
|
||||
|
||||
- [breaking-change] Removed `Hash` in favour of `core::hash::Hash`
|
||||
- [breaking-change] Removed `BuildHasher` in favour of `core::hash::BuildHasher`
|
||||
|
||||
## [v0.2.1] - 2021-04-19
|
||||
|
||||
### Added
|
||||
|
||||
- implement `Clone`, `PartialEq`, `Eq` for `BuildDefaultHasher`
|
||||
|
||||
## [v0.2.0] - 2021-04-19
|
||||
|
||||
### Changed
|
||||
|
||||
- [breaking-change] `const-fn` feature has been removed
|
||||
- [breaking-change] MSRV policy has been changed to "only latest stable is guaranteed to be supported"
|
||||
|
||||
## [v0.1.2] - 2019-11-14
|
||||
|
||||
### Updated
|
||||
|
||||
- Included MSRV in the documentation; also added examples for 2015 and 2018
|
||||
editions.
|
||||
|
||||
## [v0.1.1] - 2019-11-14
|
||||
|
||||
### Added
|
||||
|
||||
- Implementations for tuples
|
||||
|
||||
## v0.1.0 - 2018-04-23
|
||||
|
||||
Initial release
|
||||
|
||||
[Unreleased]: https://github.com/japaric/hash32/compare/v0.3.1...HEAD
|
||||
[v0.3.1]: https://github.com/japaric/hash32/compare/v0.3.0...v0.3.1
|
||||
[v0.3.0]: https://github.com/japaric/hash32/compare/v0.2.1...v0.3.0
|
||||
[v0.2.1]: https://github.com/japaric/hash32/compare/v0.2.0...v0.2.1
|
||||
[v0.2.0]: https://github.com/japaric/hash32/compare/v0.1.2...v0.2.0
|
||||
[v0.1.2]: https://github.com/japaric/hash32/compare/v0.1.1...v0.1.2
|
||||
[v0.1.1]: https://github.com/japaric/hash32/compare/v0.1.0...v0.1.1
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
authors = ["Jorge Aparicio <jorge@japaric.io>"]
|
||||
description = "32-bit hashing algorithms"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"32-bit",
|
||||
"hash",
|
||||
"fnv",
|
||||
"murmur3",
|
||||
]
|
||||
categories = ["no-std"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/japaric/hash32"
|
||||
|
||||
[dependencies.byteorder]
|
||||
version = "1.2.2"
|
||||
default-features = false
|
||||
Vendored
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2018 Jorge Aparicio
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
# `hash32`
|
||||
|
||||
> 32-bit hashing machinery
|
||||
|
||||
## [Documentation](https://docs.rs/hash32)
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||
http://www.apache.org/licenses/LICENSE-2.0)
|
||||
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the
|
||||
work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
|
||||
additional terms or conditions.
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
extern crate hash32;
|
||||
|
||||
use std::hash::Hash;
|
||||
|
||||
use hash32::{FnvHasher, Hasher};
|
||||
|
||||
#[derive(Hash)]
|
||||
struct Led {
|
||||
state: bool,
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
struct Ipv4Addr([u8; 4]);
|
||||
|
||||
#[derive(Hash)]
|
||||
struct Generic<T> {
|
||||
inner: T,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fnv = FnvHasher::default();
|
||||
Led { state: true }.hash(&mut fnv);
|
||||
Generic { inner: 0 }.hash(&mut fnv);
|
||||
Ipv4Addr([127, 0, 0, 1]).hash(&mut fnv);
|
||||
println!("{}", fnv.finish32())
|
||||
}
|
||||
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
use crate::Hasher as _;
|
||||
|
||||
const BASIS: u32 = 0x811c9dc5;
|
||||
const PRIME: u32 = 0x1000193;
|
||||
|
||||
/// 32-bit Fowler-Noll-Vo hasher
|
||||
pub struct Hasher {
|
||||
state: u32,
|
||||
}
|
||||
|
||||
impl Default for Hasher {
|
||||
fn default() -> Self {
|
||||
Hasher { state: BASIS }
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Hasher for Hasher {
|
||||
#[inline]
|
||||
fn finish32(&self) -> u32 {
|
||||
self.state
|
||||
}
|
||||
}
|
||||
|
||||
impl core::hash::Hasher for Hasher {
|
||||
#[inline]
|
||||
fn write(&mut self, bytes: &[u8]) {
|
||||
for byte in bytes {
|
||||
self.state ^= u32::from(*byte);
|
||||
self.state = self.state.wrapping_mul(PRIME);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn finish(&self) -> u64 {
|
||||
self.finish32().into()
|
||||
}
|
||||
}
|
||||
Vendored
+141
@@ -0,0 +1,141 @@
|
||||
//! 32-bit hashing algorithms
|
||||
//!
|
||||
//! # Why?
|
||||
//!
|
||||
//! Because 32-bit architectures are a thing (e.g. ARM Cortex-M) and you don't want your hashing
|
||||
//! function to pull in a bunch of slow 64-bit compiler intrinsics (software implementations of
|
||||
//! 64-bit operations).
|
||||
//!
|
||||
//! # Relationship to `core::hash`
|
||||
//!
|
||||
//! This crate extends [`core::hash`] with a 32-bit version of `Hasher`, which extends
|
||||
//! `core::hash::Hasher`. It requires that the hasher only performs 32-bit operations when computing
|
||||
//! the hash, and adds [`finish32`] to get the hasher's result as a `u32`. The standard `finish`
|
||||
//! method should just zero-extend this result.
|
||||
//!
|
||||
//! Since it extends `core::hash::Hasher`, `Hasher` can be used with any type which implements the
|
||||
//! standard `Hash` trait.
|
||||
//!
|
||||
//! This crate also adds a version of `BuildHasherDefault` with a const constructor, to work around
|
||||
//! the `core` version's lack of one.
|
||||
//!
|
||||
//! [`core::hash`]: https://doc.rust-lang.org/std/hash/index.html
|
||||
//! [`finish32`]: crate::Hasher::finish32
|
||||
//!
|
||||
//! # Hashers
|
||||
//!
|
||||
//! This crate provides implementations of the following 32-bit hashing algorithms:
|
||||
//!
|
||||
//! - [Fowler-Noll-Vo](struct.FnvHasher.html)
|
||||
//! - [MurmurHash3](struct.Murmur3Hasher.html)
|
||||
//!
|
||||
//! # Generic code
|
||||
//!
|
||||
//! In generic code, the trait bound `H: core::hash::Hasher` accepts *both* 64-bit hashers like
|
||||
//! `std::collections::hash_map::DefaultHasher`; and 32-bit hashers like the ones defined in this
|
||||
//! crate (`hash32::FnvHasher` and `hash32::Murmur3Hasher`)
|
||||
//!
|
||||
//! The trait bound `H: hash32::Hasher` is *more* restrictive as it only accepts 32-bit hashers.
|
||||
//!
|
||||
//! The `BuildHasherDefault<H>` type implements the `core::hash::BuildHasher` trait so it can
|
||||
//! construct both 32-bit and 64-bit hashers. To constrain the type to only produce 32-bit hasher
|
||||
//! you can add the trait bound `H::Hasher: hash32::Hasher`
|
||||
//!
|
||||
//! # MSRV
|
||||
//!
|
||||
//! This crate is guaranteed to compile on latest stable Rust. It *might* compile on older
|
||||
//! versions but that may change in any new patch release.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
#![deny(warnings)]
|
||||
#![no_std]
|
||||
|
||||
extern crate byteorder;
|
||||
|
||||
use core::fmt;
|
||||
use core::hash::BuildHasher;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
pub use fnv::Hasher as FnvHasher;
|
||||
pub use murmur3::Hasher as Murmur3Hasher;
|
||||
|
||||
mod fnv;
|
||||
mod murmur3;
|
||||
|
||||
/// A copy of [`core::hash::BuildHasherDefault`][0], but with a const constructor.
|
||||
///
|
||||
/// This will eventually be deprecated once the version in `core` becomes const-constructible
|
||||
/// (presumably using `const Default`).
|
||||
///
|
||||
/// [0]: https://doc.rust-lang.org/core/hash/struct.BuildHasherDefault.html
|
||||
pub struct BuildHasherDefault<H> {
|
||||
_marker: PhantomData<H>,
|
||||
}
|
||||
|
||||
impl<H> Default for BuildHasherDefault<H> {
|
||||
fn default() -> Self {
|
||||
BuildHasherDefault {
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<H> Clone for BuildHasherDefault<H> {
|
||||
fn clone(&self) -> Self {
|
||||
BuildHasherDefault::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<H> PartialEq for BuildHasherDefault<H> {
|
||||
fn eq(&self, _other: &BuildHasherDefault<H>) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<H> Eq for BuildHasherDefault<H> {}
|
||||
|
||||
impl<H> fmt::Debug for BuildHasherDefault<H> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.pad("BuildHasherDefault")
|
||||
}
|
||||
}
|
||||
|
||||
impl<H> BuildHasherDefault<H> {
|
||||
/// `const` constructor
|
||||
pub const fn new() -> Self {
|
||||
BuildHasherDefault {
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<H> BuildHasher for BuildHasherDefault<H>
|
||||
where
|
||||
H: Default + core::hash::Hasher,
|
||||
{
|
||||
type Hasher = H;
|
||||
|
||||
fn build_hasher(&self) -> Self::Hasher {
|
||||
H::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// An extension of [core::hash::Hasher][0] for hashers which use 32 bits.
|
||||
///
|
||||
/// For hashers which implement this trait, the standard `finish` method should just return a
|
||||
/// zero-extended version of the result of `finish32`.
|
||||
///
|
||||
/// [0]: https://doc.rust-lang.org/core/hash/trait.Hasher.html
|
||||
///
|
||||
/// # Contract
|
||||
///
|
||||
/// Implementers of this trait must *not* perform any 64-bit (or 128-bit) operation while computing
|
||||
/// the hash.
|
||||
pub trait Hasher: core::hash::Hasher {
|
||||
/// The equivalent of [`core::hash::Hasher.finish`][0] for 32-bit hashers.
|
||||
///
|
||||
/// This returns the hash directly; `finish` zero-extends it to 64 bits for compatibility.
|
||||
///
|
||||
/// [0]: https://doc.rust-lang.org/std/hash/trait.Hasher.html#tymethod.finish
|
||||
fn finish32(&self) -> u32;
|
||||
}
|
||||
Vendored
+206
@@ -0,0 +1,206 @@
|
||||
use core::slice;
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
use byteorder::{ByteOrder, LE};
|
||||
|
||||
use crate::Hasher as _;
|
||||
|
||||
/// 32-bit MurmurHash3 hasher
|
||||
pub struct Hasher {
|
||||
buf: Buffer,
|
||||
index: Index,
|
||||
processed: u32,
|
||||
state: State,
|
||||
}
|
||||
|
||||
struct State(u32);
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(align(4))]
|
||||
struct Buffer {
|
||||
bytes: MaybeUninit<[u8; 4]>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum Index {
|
||||
_0,
|
||||
_1,
|
||||
_2,
|
||||
_3,
|
||||
}
|
||||
|
||||
impl Index {
|
||||
fn usize(&self) -> usize {
|
||||
match *self {
|
||||
Index::_0 => 0,
|
||||
Index::_1 => 1,
|
||||
Index::_2 => 2,
|
||||
Index::_3 => 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for Index {
|
||||
fn from(x: usize) -> Self {
|
||||
match x % 4 {
|
||||
0 => Index::_0,
|
||||
1 => Index::_1,
|
||||
2 => Index::_2,
|
||||
3 => Index::_3,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Hasher {
|
||||
fn push(&mut self, buf: &[u8]) {
|
||||
let start = self.index.usize();
|
||||
let len = buf.len();
|
||||
// NOTE(unsafe) avoid calling `memcpy` on a 0-3 byte copy
|
||||
// self.buf.bytes[start..start+len].copy_from(buf);
|
||||
for i in 0..len {
|
||||
unsafe {
|
||||
*self.buf.bytes.assume_init_mut().get_unchecked_mut(start + i) = *buf.get_unchecked(i);
|
||||
}
|
||||
}
|
||||
self.index = Index::from(start + len);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Hasher {
|
||||
#[allow(deprecated)]
|
||||
fn default() -> Self {
|
||||
Hasher {
|
||||
buf: Buffer { bytes: MaybeUninit::uninit() },
|
||||
index: Index::_0,
|
||||
processed: 0,
|
||||
state: State(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Hasher for Hasher {
|
||||
fn finish32(&self) -> u32 {
|
||||
// tail
|
||||
let mut state = match self.index {
|
||||
Index::_3 => {
|
||||
let mut block = 0;
|
||||
unsafe {
|
||||
block ^= u32::from(self.buf.bytes.assume_init_ref()[2]) << 16;
|
||||
block ^= u32::from(self.buf.bytes.assume_init_ref()[1]) << 8;
|
||||
block ^= u32::from(self.buf.bytes.assume_init_ref()[0]);
|
||||
}
|
||||
self.state.0 ^ pre_mix(block)
|
||||
}
|
||||
Index::_2 => {
|
||||
let mut block = 0;
|
||||
unsafe {
|
||||
block ^= u32::from(self.buf.bytes.assume_init_ref()[1]) << 8;
|
||||
block ^= u32::from(self.buf.bytes.assume_init_ref()[0]);
|
||||
}
|
||||
self.state.0 ^ pre_mix(block)
|
||||
}
|
||||
Index::_1 => {
|
||||
let mut block = 0;
|
||||
unsafe {
|
||||
block ^= u32::from(self.buf.bytes.assume_init_ref()[0]);
|
||||
}
|
||||
self.state.0 ^ pre_mix(block)
|
||||
}
|
||||
Index::_0 => self.state.0,
|
||||
};
|
||||
|
||||
// finalization mix
|
||||
state ^= self.processed;
|
||||
state ^= state >> 16;
|
||||
state = state.wrapping_mul(0x85ebca6b);
|
||||
state ^= state >> 13;
|
||||
state = state.wrapping_mul(0xc2b2ae35);
|
||||
state ^= state >> 16;
|
||||
|
||||
state
|
||||
}
|
||||
}
|
||||
|
||||
impl core::hash::Hasher for Hasher {
|
||||
#[inline]
|
||||
fn write(&mut self, bytes: &[u8]) {
|
||||
let len = bytes.len();
|
||||
self.processed += len as u32;
|
||||
|
||||
let body = if self.index == Index::_0 {
|
||||
bytes
|
||||
} else {
|
||||
let index = self.index.usize();
|
||||
if len + index >= 4 {
|
||||
// we can complete a block using the data left in the buffer
|
||||
// NOTE(unsafe) avoid panicking branch (`slice_index_len_fail`)
|
||||
// let (head, body) = bytes.split_at(4 - index);
|
||||
let mid = 4 - index;
|
||||
let head = unsafe { slice::from_raw_parts(bytes.as_ptr(), mid) };
|
||||
let body = unsafe {
|
||||
slice::from_raw_parts(bytes.as_ptr().offset(mid as isize), len - mid)
|
||||
};
|
||||
|
||||
// NOTE(unsafe) avoid calling `memcpy` on a 0-3 byte copy
|
||||
// self.buf.bytes[index..].copy_from_slice(head);
|
||||
for i in 0..4 - index {
|
||||
unsafe {
|
||||
*self.buf.bytes.assume_init_mut().get_unchecked_mut(index + i) = *head.get_unchecked(i);
|
||||
}
|
||||
}
|
||||
|
||||
self.index = Index::_0;
|
||||
|
||||
self.state.process_block(&self.buf.bytes);
|
||||
|
||||
body
|
||||
} else {
|
||||
bytes
|
||||
}
|
||||
};
|
||||
|
||||
for block in body.chunks(4) {
|
||||
if block.len() == 4 {
|
||||
self.state
|
||||
.process_block(unsafe { &*(block.as_ptr() as *const _) });
|
||||
} else {
|
||||
self.push(block);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX is this faster?
|
||||
// for block in body.exact_chunks(4) {
|
||||
// self.state
|
||||
// .process_block(unsafe { &*(block.as_ptr() as *const _) });
|
||||
// }
|
||||
|
||||
// let tail = body.split_at(body.len() / 4 * 4).1;
|
||||
|
||||
// self.push(tail);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn finish(&self) -> u64 {
|
||||
self.finish32().into()
|
||||
}
|
||||
}
|
||||
|
||||
const C1: u32 = 0xcc9e2d51;
|
||||
const C2: u32 = 0x1b873593;
|
||||
const R1: u32 = 15;
|
||||
|
||||
impl State {
|
||||
fn process_block(&mut self, block: &MaybeUninit<[u8; 4]>) {
|
||||
self.0 ^= pre_mix(LE::read_u32(unsafe { block.assume_init_ref() }));
|
||||
self.0 = self.0.rotate_left(13);
|
||||
self.0 = 5u32.wrapping_mul(self.0).wrapping_add(0xe6546b64);
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_mix(mut block: u32) -> u32 {
|
||||
block = block.wrapping_mul(C1);
|
||||
block = block.rotate_left(R1);
|
||||
block = block.wrapping_mul(C2);
|
||||
block
|
||||
}
|
||||
Reference in new issue
Block a user