npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dding-fnv

v1.0.1

Published

Hash Fnv-1/Fnv-1a Algorithm in 32/64

Downloads

68

Readme

DDing-Fnv

Fowler–Noll–Vo Hash Function ,Versions contains FNV-1 hash and FNV-1a hash.

Concept

Fowler–Noll–Vo is a non-cryptographic hash function.

The basis of the FNV hash algorithm was taken from an idea sent as reviewer comments to the IEEE POSIX P1003.2 committee by Glenn Fowler and Phong Vo in 1991. In a subsequent ballot round, Landon Curt Noll improved on their algorithm. In an email message to Landon, they named it the Fowler/Noll/Vo or FNV hash.

FNV-1 hash

The FNV-1 hash algorithm is as follows:

  hash = FNV_offset_basis
  for each byte_of_data to be hashed
       hash = hash × FNV_prime
       hash = hash XOR byte_of_data
  return hash

In the above pseudocode, all variables are unsigned integers. All variables, except for byte_of_data, have the same number of bits as the FNV hash. The variable, byte_of_data, is an 8 bit unsigned integer.

FNV-1a hash

The FNV-1a hash differs from the FNV-1 hash by only the order in which the multiply and XOR is performed:

  hash = FNV_offset_basis
  for each byte_of_data to be hashed
       hash = hash XOR byte_of_data
       hash = hash × FNV_prime
  return hash

The above pseudocode has the same assumptions that were noted for the FNV-1 pseudocode. The small change in order leads to slightly better avalanche characteristics.

As an example, consider the 64-bit FNV hash:

  • All variables, except for byte_of_data, are 64-bit unsigned integers.
  • The variable, byte_of_data, is an 8-bit unsigned integer.
  • The FNV_offset_basis is the 64-bit FNV offset basis value: 14695981039346656037 (in hex, 0xcbf29ce484222325).
  • The FNV_prime is the 64-bit FNV prime value: 1099511628211 (in hex, 0x100000001b3).
  • The multiply returns the lower 64-bits of the product.
  • The XOR is an 8-bit operation that modifies only the lower 8-bits of the hash value.
  • The hash value returned is a 64-bit unsigned integer.

Installation

Install from NPM.

  $ npm install dding-fnv --save

Usage

Hash32

version: fnv-1, Examples:
var Fnv = require('dding-fnv');
var hashValue = Fnv.hash32('testString', '1');
console.log('String:', hashValue.toStr());
console.log('Decimal: ', hashValue.toDec());
console.log('Hexadecimal: ', hashValue.toHex());
version: fnv-1a, Examples:
var Fnv = require('dding-fnv');
var hashValue = Fnv.hash32('testString', '1a');
console.log('String:', hashValue.toStr());
console.log('Decimal: ', hashValue.toDec());
console.log('Hexadecimal: ', hashValue.toHex());

Hash64

version: fnv-1, Examples:
var Fnv = require('dding-fnv');
var hashValue = Fnv.hash64('testString', '1');
console.log('String:', hashValue.toStr());
console.log('Decimal: ', hashValue.toDec());
console.log('Hexadecimal: ', hashValue.toHex());
version: fnv-1a, Examples:
var Fnv = require('dding-fnv');
var hashValue = Fnv.hash64('testString', '1a');
console.log('String:', hashValue.toStr());
console.log('Decimal: ', hashValue.toDec());
console.log('Hexadecimal: ', hashValue.toHex());

License

MIT. Copyright © 2012-2017 Linan Design & The Yunding-network Company