All Projects → desmondyeung → Scala Hashing

desmondyeung / Scala Hashing

Licence: apache-2.0
Fast non-cryptographic hash functions for Scala

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Scala Hashing

Upash
🔒Unified API for password hashing algorithms
Stars: ✭ 484 (+633.33%)
Mutual labels:  hashing, hash-functions
prvhash
PRVHASH - Pseudo-Random-Value Hash. Hash functions, PRNG with unlimited period, randomness extractor. (Codename Gradilac/Градилак)
Stars: ✭ 194 (+193.94%)
Mutual labels:  hashing, hash-functions
Crypto Hash
Tiny hashing module that uses the native crypto API in Node.js and the browser
Stars: ✭ 501 (+659.09%)
Mutual labels:  hashing, hash-functions
T1ha
One of the fastest hash functions
Stars: ✭ 302 (+357.58%)
Mutual labels:  hashing, hash-functions
Zero Allocation Hashing
Zero-allocation hashing for Java
Stars: ✭ 561 (+750%)
Mutual labels:  hashing, hash-functions
Java Competitive Programming
I have written some important Algorithms and Data Structures in an efficient way in Java with proper references to time and space complexity. These Pre-cooked and well-tested codes help to implement larger hackathon problems in lesser time. DFS, BFS, LCA, All Pair Shortest Path, Longest Common Subsequence, Binary Search, Lower Bound Search, Maximal Matching, Matrix Exponentiation, Segment Tree, Sparse Table, Merge Sort, Miller Prime Test, Prims - Minimum Spanning Tree, BIT - Binary Index Tree, Two Pointers, BST - Binary Search Tree, Maximum Subarray Sum, Immutable Data Structures, Persistent Data Structurs - Persistent Trie, Dijkstra, Z - Function, Minimum Cost Maximal Matching, Heavy Light Decomposition, Knapsack, Suffix Array and LCP - Longest Common Prefix, Squre Root Decomposition, Kth Order Statics, Trie / Prefix Tree, LIS - Longest Increasing Subsequence, Hashing
Stars: ✭ 24 (-63.64%)
Mutual labels:  hashing
Wyhash Rs
wyhash fast portable non-cryptographic hashing algorithm and random number generator in Rust
Stars: ✭ 44 (-33.33%)
Mutual labels:  hashing
Highwayhash
Native Go version of HighwayHash with optimized assembly implementations on Intel and ARM. Able to process over 10 GB/sec on a single core on Intel CPUs - https://en.wikipedia.org/wiki/HighwayHash
Stars: ✭ 670 (+915.15%)
Mutual labels:  hash-functions
Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (+866.67%)
Mutual labels:  hashing
Blake2fast
Optimized BLAKE2 hashing implementations in C#
Stars: ✭ 63 (-4.55%)
Mutual labels:  hashing
Fast Near Duplicate Image Search
Fast Near-Duplicate Image Search and Delete using pHash, t-SNE and KDTree.
Stars: ✭ 54 (-18.18%)
Mutual labels:  hashing
Swift Crypto
Open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.
Stars: ✭ 1,005 (+1422.73%)
Mutual labels:  hash-functions
Streebog
GOST R 34.11-2012: RFC-6986 cryptographic hash function
Stars: ✭ 24 (-63.64%)
Mutual labels:  hash-functions
Esecurity
MSc Module
Stars: ✭ 49 (-25.76%)
Mutual labels:  hashing
Smhasher
Hash function quality and speed tests
Stars: ✭ 719 (+989.39%)
Mutual labels:  hash-functions
String Hash
Get the hash of a string
Stars: ✭ 56 (-15.15%)
Mutual labels:  hashing
Multihash
Self describing hashes - for future proofing
Stars: ✭ 656 (+893.94%)
Mutual labels:  hash-functions
Parallel Xxhash
Compute xxHash hash codes for 8 keys in parallel
Stars: ✭ 36 (-45.45%)
Mutual labels:  hashing
Farmhash.sharp
Port of Google's farmhash algorithm to .NET
Stars: ✭ 52 (-21.21%)
Mutual labels:  hashing
Rhashmap
Robin Hood hash map library
Stars: ✭ 33 (-50%)
Mutual labels:  hashing

Scala-Hashing

Build Status codecov.io Maven Central

Overview

Fast non-cryptographic hash functions for Scala. This library provides APIs for computing 32-bit and 64-bit hashes.

Currently implemented hash functions

Hash functions in this library can be accessed via either a standard API for hashing primitives, byte arrays, or Java ByteBuffers (direct and non-direct), or a streaming API for hashing stream-like objects such as InputStreams, Java NIO Channels, or Akka Streams. Hash functions should produce consistent output regardless of platform or endianness.

This library uses the sun.misc.Unsafe API internally. I might explore using the VarHandle API introduced in Java 9 in the future, but am currently still supporting Java 8.

Performance

Benchmarked against various other open-source implementations

  • Guava (MurmurHash3)
  • LZ4 Java (XxHash32 and XxHash64 - Includes JNI binding, pure Java, and Java+Unsafe implementations)
  • Scala (Scala's built-in scala.util.hashing.MurmurHash3)
  • Zero-Allocation-Hashing (XxHash64)

MurmurHash3_32

MurmurHash3_32

XxHash32

XxHash32

XxHash64

XxHash64

Running Locally

Benchmarks are located in the bench subproject and can be run using the sbt-jmh plugin.

To run all benchmarks with default settings

bench/jmh:run

To run a specific benchmark with custom settings

bench/jmh:run -f 2 -wi 5 -i 5 XxHash64Bench

Getting Started

libraryDependencies += "com.desmondyeung.hashing" %% "scala-hashing" % "0.1.0"

Examples

This library defines the interfaces Hash32 and StreamingHash32 for computing 32-bit hashes and Hash64 and StreamingHash64 for computing 64-bit hashes. Classes extending StreamingHash32 or StreamingHash64 are not thread-safe.

The public API for Hash64 and StreamingHash64 can be seen below

trait Hash64 {
  def hashByte(input: Byte, seed: Long): Long
  def hashInt(input: Int, seed: Long): Long
  def hashLong(input: Long, seed: Long): Long
  def hashByteArray(input: Array[Byte], seed: Long): Long
  def hashByteArray(input: Array[Byte], offset: Int, length: Int, seed: Long): Long
  def hashByteBuffer(input: ByteBuffer, seed: Long): Long
  def hashByteBuffer(input: ByteBuffer, offset: Int, length: Int, seed: Long): Long
}

trait StreamingHash64 {
  def reset(): Unit
  def value: Long
  def updateByteArray(input: Array[Byte], offset: Int, length: Int): Unit
  def updateByteBuffer(input: ByteBuffer, offset: Int, length: Int): Unit
}

Using the standard API

import com.desmondyeung.hashing.XxHash64
import java.nio.ByteBuffer

// hash a long
val hash = XxHash64.hashLong(123, seed = 0)

// hash a Array[Byte]
val hash = XxHash64.hashByteArray(Array[Byte](123), seed = 0)

// hash a ByteBuffer
val hash = XxHash64.hashByteBuffer(ByteBuffer.wrap(Array[Byte](123)), seed = 0)

Using the streaming API

import com.desmondyeung.hashing.StreamingXxHash64
import java.nio.ByteBuffer
import java.io.FileInputStream

val checksum = StreamingXxHash64(seed = 0)
val channel  = new FileInputStream("/path/to/file.txt").getChannel
val chunk    = ByteBuffer.allocate(1024)

var bytesRead = channel.read(chunk)
while (bytesRead > 0) {
  checksum.updateByteBuffer(chunk, 0, bytesRead)
  chunk.rewind
  bytesRead = channel.read(chunk)
}

val hash = checksum.value

License

Licensed under the Apache License, Version 2.0 (the "License").

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].