패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.2.0

xxh3

xxHash에서 온 XXH3 해시 알고리즘의 Dart 구현(포트).

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
78.4만
좋아요
15
Pub 점수
160

패키지 설치

flutter pub add xxh3

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Yann Collet에 의해 처음 개발된 XXH3 해시 알고리즘의 Dart 구현입니다. 이 패키지는 빠르고 신뢰할 수 있는 데이터 무결성 검사를 필요로 하는 애플리케이션에 적합한 고속 및 안전한 해싱을 제공합니다. 원본 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.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.