farmhash

Node.js implementation of Google's FarmHash family of very fast hash functions.

FarmHash is the successor to CityHash. Functions in the FarmHash family are not suitable for cryptography. A fast, cryptographically-secure alternative is HighwayHash.

As the V8 JavaScript engine only natively supports 32-bit unsigned integers, the 64-bit methods return strings instead of Numbers and the 128-bit methods are not implemented.

This module uses FarmHash v1.1.0 (2015-03-01). It has been tested with Node.js v0.10, v0.12, v4, v6 on Linux, OS X and Windows.

Installation

npm install farmhash

Usage

var farmhash = require('farmhash');
var hash = farmhash.hash32('test');
console.log(typeof hash); // 'number'
var hash = farmhash.hash64(new Buffer('test'));
console.log(typeof hash); // 'string'
var hash = farmhash.hash64WithSeed('test', 123);
console.log(typeof hash); // 'string'
var hash = farmhash.fingerprint32(new Buffer('test'));
console.log(typeof hash); // 'number'
var hash = farmhash.fingerprint64('test');
console.log(typeof hash); // 'string'

API

Hash

The hash methods are platform dependent. Different CPU architectures, for example 32-bit vs 64-bit, Intel vs ARM, SSE4.2 vs AVX might produce different results for a given input.

hash32(input)

  • input is the Buffer or String to hash.

Returns a Number containing the 32-bit unsigned integer hash value of input.

hash32WithSeed(input, seed)

  • input is the Buffer or String to hash.
  • seed is an integer Number to use as a seed.

Returns a Number containing the 32-bit unsigned integer hash value of input.

hash64(input)

  • input is the Buffer or String to hash.

Returns a String representing the 64-bit unsigned integer hash value of input.

hash64WithSeed(input, seed)

  • input is the Buffer or String to hash.
  • seed is an integer Number to use as a seed.

Returns a String representing the 64-bit unsigned integer hash value of input.

hash64WithSeeds(input, seed1, seed2)

  • input is the Buffer or String to hash.
  • seed1 and seed2 are integer Numbers to use as seeds.

Returns a String representing the 64-bit unsigned integer hash value of input.

hash32v1(input)

Legacy function to access v1 of the FarmHash implementation.

  • input is the Buffer or String to hash.

Returns a Number containing the 32-bit unsigned integer v1 hash value of input.

Fingerprint

The fingerprint methods are platform independent, producing the same results for a given input on any machine.

fingerprint32(input)

  • input is the Buffer or String to fingerprint.

Returns a Number containing the 32-bit unsigned integer fingerprint value of input.

fingerprint64(input)

  • input is the Buffer or String to fingerprint.

Returns a String representing the 64-bit unsigned integer fingerprint value of input.

Testing

Build Status

Build status

npm test

Licence

Copyright 2014, 2015, 2016 Lovell Fuller and contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014, 2015 Google, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



farmhash

Node.js实现Google的 FarmHash 一系列非常快的散列函数。

FarmHash是CityHash的继承者。 FarmHash系列中的功能不适用于加密。 一个快速,密码安全的替代方案是 HighwayHash

由于V8 JavaScript引擎本身只支持32位无符号整数, 64位方法返回字符串而不是数字 而128位方法未实现。

此模块使用FarmHash v1.1.0(2015-03-01)。 已经使用Node.js v0.10,v0.12,v4,v6进行了测试 在Linux,OS X和Windows上。

安装

npm install farmhash

用法

var farmhash = require('farmhash');
var hash = farmhash.hash32('test');
console.log(typeof hash); // 'number'
var hash = farmhash.hash64(new Buffer('test'));
console.log(typeof hash); // 'string'
var hash = farmhash.hash64WithSeed('test', 123);
console.log(typeof hash); // 'string'
var hash = farmhash.fingerprint32(new Buffer('test'));
console.log(typeof hash); // 'number'
var hash = farmhash.fingerprint64('test');
console.log(typeof hash); // 'string'

API

哈希

散列方法与平台有关。 不同的CPU架构,例如32位vs 64位,Intel与ARM,SSE4.2和AVX 可能会为给定的输入产生不同的结果。

hash32(input)

  • input 是要排序的缓冲区或字符串。

返回一个包含输入的32位无符号整数哈希值的数字。

hash32WithSeed(input, seed)

  • input 是要排序的缓冲区或字符串。
  • seed 是一个用作种子的整数。

返回一个包含输入的32位无符号整数哈希值的数字。

hash64(input)

  • input 是要排序的缓冲区或字符串。

返回一个表示输入的64位无符号整数哈希值的字符串。

hash64WithSeed(input, seed)

  • input 是要排序的缓冲区或字符串。
  • seed 是一个用作种子的整数。

返回一个表示输入的64位无符号整数哈希值的字符串。

hash64WithSeeds(input, seed1, seed2)

  • input 是要排序的缓冲区或字符串。
  • seed1 和 seed2 是用作种子的整数。

返回一个表示输入的64位无符号整数哈希值的字符串。

hash32v1(input)

传入功能以访问FarmHash实现的v1。

  • input 是要排序的缓冲区或字符串。

返回一个包含输入的32位无符号整数v1哈希值的数字。

指纹

指纹方法与平台无关,对任何机器的给定输入产生相同的结果。

fingerprint32(input)

  • input 是指纹的缓冲区或字符串。

返回一个包含输入的32位无符号整数指纹值的数字。

fingerprint64(input)

  • input 是指纹的缓冲区或字符串。

返回一个表示输入的64位无符号整数指纹值的字符串。

测试

建立状态

建立状态

npm test

许可证

版权所有2014,2015,2016 Lovell Fuller和贡献者。

根据Apache许可证2.0版(许可证)许可; 您不得使用此文件,除非符合许可证。 您可以在

获取许可证的副本
 http://www.apache.org/licenses/LICENSE-2.0

除非适用法律要求或书面同意,软件 根据许可证分发的分发是按原样的基础, 无明示或暗示的任何形式的担保或条件。 请参阅有关权限的特定语言的许可证 许可证下的限制。

版权所有2014,2015 Google,Inc。

特此授予任何获得副本的人免费许可 的这个软件和相关的文档文件(软件)来处理 软件无限制,包括但不限于权限 使用,复制,修改,合并,发布,分发,再许可和/或销售 软件的副本,并允许本软件的人员 须遵守以下条件:

上述版权声明和本许可声明应包括在内 软件的所有副本或主要部分。

该软件按原样提供,不提供任何明示或暗示的保证 暗示,包括但不限于适销性的保证, 适用于特定用途和非侵权。在任何情况下 作者或版权所有人不得对任何索赔,损害或其他责任负责 责任,无论在合同,侵权行为或其他方面的行为, 与本软件或其使用或其他交易相关或不存在 该软件。




相关问题推荐