Git Product home page Git Product logo

xxh3's Introduction

dart-xxh3

Pub Publisher Pub Version GitHub Workflow Status Codecov MIT License

Port of the XXH3 hashing algorithm in Dart.

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

import 'package:xxh3/xxh3.dart';

void main() {

  // Get the string as UTF-8 bytes.
  final bytes = 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 an unsigned 64-bit integer.
  final int digest = xxh3(Uint8List.fromList(bytes));
  print(digest);
  
  // 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.

As it stands, this is a port written entirely in Dart. It should perform fairly well, but I have not benchmarked it as the main goal for this package is to have a compatible hash implementation in Dart. If better performance is needed, this could probably serve as a fallback and dart:ffi could be used to call native code for better performance.

This uses native integers for performance reasons, so this will not provide correct results for Dart web. If there is demand for this, that could probably be rectified.

xxh3's People

Contributors

samjakob avatar

Stargazers

 avatar  avatar

Watchers

 avatar

xxh3's Issues

xxh3 hash generates different result from c xxh3 lib

thank you for porting this lib!!

found this package generates different result from c lib.

dart, this package

xxh3(Uint8List.fromList(utf8.encode('test')), secret:null, seed: 0)

get result: -7004795540881933248

c lib get result: 5754696928334414137

is there anything I missed here?

Produce signed int

I'm surprised that in my case it produces a negative int, where the docs says unsigned int. Is that normal ?

// Get the string as UTF-8 bytes.
final bytes = utf8.encode('https://tile.openstreetmap.org/16/32768/32768.png');

// 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 an unsigned 64-bit integer.
digest = xxh3(Uint8List.fromList(bytes));
value = digest.toString();
debugPrint(value);
value = digest.toRadixString(16);
debugPrint(value);

Output :

-7244486220034343490
-648995d58d5c0242

Allow hashing a stream

The current implementation requires the whole data to be in memory. Allowing a Stream<List<int>> as an input would make it possible to hash big files.

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.