搜索插件、代码仓与 APP 分类

插件详情v1.2.0

xxh3

xxHash 的 XXH3 哈希算法的 Dart 实现(移植)。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
78.4万
喜欢数
15
Pub 分数
160

安装插件

flutter pub add xxh3

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

XXH3 哈希算法的 Dart 实现,最初由 Yann Collet 开发。此包提供高速、安全的哈希功能,适用于需要快速可靠数据完整性检查的应用程序。它是对原始 xxHash 库的直接移植,针对多种平台进行了性能优化。非常适合用于缓存、校验和以及数据去重场景,其中速度和低冲突率至关重要。

适合场景

  • 数据完整性验证
  • 缓存系统
  • 文件和流哈希
  • 加密校验和
  • 快速数据去重

主要特点

  • 高性能哈希
  • 跨平台兼容性
  • 低碰撞率
  • 简单 API
  • 针对速度进行了优化

适合对象

  • 性能关键的应用程序
  • 大规模数据处理
  • 实时系统
  • 安全敏感环境
  • 需要快速哈希生成的应用程序

使用建议

  • 不适合用于密码哈希等加密安全场景
  • 不提供加密
  • 最适合用于完整性,而非保密性
  • 在敏感情境中需要谨慎处理
  • 不建议用于加密密钥派生

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

xxh3 (for Dart)

Pub Publisher Pub Version GitHub Workflow Status Codecov MIT License

Port of the XXH3 hashing algorithm in Dart.

Presently, only the 64-bit version of XXH3 (XXH3-64) is supported. Please feel free to open a GitHub issue if you need support for XXH3-128.

import 'dart:convert' show utf8;
import 'dart:typed_data';

import 'package:xxh3/xxh3.dart';

void main() {
  // Get the string as UTF-8 bytes.
  final helloWorldBytes = utf8.encode("Hello, world!");
  
  // Use XXH3 to hash the byte array (returns an int).
  // XXH3 is a 64-bit hash, so the value is returned in the
  // form of a 64-bit integer.
  final int digest = xxh3(helloWorldBytes);
  print(digest); // -881777603154417559
  
  // Alternatively, in version 1.1.0+, you can use the
  // xxh3String convenience method to get a hexadecimal
  // string representation of the hash.
  final String hexDigest = xxh3String(helloWorldBytes);
  print(hexDigest); // f3c34bf11915e869

  // Similarly, in version 1.2.0+, you can use the
  // stream API to process your data in blocks.
  final hashStream = xxh3Stream();
  hashStream.update(helloWorldBytes);
  print(hashStream.digest()); // -881777603154417559
  print(hashStream.digestString()); // f3c34bf11915e869
  
  // See the examples and documentation for more...
}

Refer to the Example tab for a 'quick start guide', or for more details refer to the API Documentation.

Performance

As it stands, this is a port written entirely in Dart. At the time of writing it has a throughput of ~0.29 ns/byte (3.16 GB/s) on an Apple M-series processor in JIT mode or ~0.28 ns/byte (3.23 GB/s) in AOT mode.

The streaming APIs currently have no further optimization and are therefore about 0.4-0.6ns/byte slower than the buffered APIs.

You can run the benchmarks yourself on your machine with the following commands:

# For JIT mode
dart run tool/benchmark.dart
# For AOT mode
dart compile exe tool/benchmark.dart -o benchmark
./benchmark

If better performance is needed, dart:ffi can be used to call the original C implementation. This is not currently implemented in this package, but feel free to open a ticket on GitHub if you would like this.

This assumes that the int type is a 64-bit integer, so this will likely not provide correct results for Dart web (JavaScript), where after 2^53, integers become floating point numbers. If there is demand for this, that could probably be addressed by using a custom integer type or a JavaScript Uint8Array.

WebAssembly could also be a potential workaround, but I have not investigated this yet.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。