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

cityhash

v0.0.5

Published

NodeJS binding for Google CityHash.

Downloads

20

Readme

node-cityhash

A NodeJS binding for Google CityHash.

Install

npm install cityhash

Functions

64-bit hash object:
{
    low:    {unsigned long}, eg 1727229466.
    high:   {unsigned long}, eg 1535838579.
    uint64: {boolean} true if hash object is uint64. Otherwise undefined.
    value:  {string}, eg "6596376470467341850".
}

128-bit hash object:
{
    low:     {64-bit hash object}.
    high:    {64-bit hash object}.
    uint128: {boolean} true if hash object is uint128. Otherwise undefined.
    value:   {string}, "low64,high64", eg "9138004313465017137,12242971252332641544".
}

/**
 * convert string or number to hash object.
 * @param {unsigned long long | string} the string or number to be convered to hash object.
 * @return {hash} 64-bit hash object or 128-bit hash object.
**/
function objectify(obj);

/**
 * stringify the hash object.
 * @param {hash} 64-bit hash object or 128-bit hash object.
 * @return {string} the hash string value, eg "6596376470467341850" or "9138004313465017137,12242971252332641544".
**/
function stringify(obj);

/**
 * Compute hash for str by CityHash64().
 * @param {string} str The string to compute hash.
 * @param {unsigned long long | string | 64-bit hash object} [seed0] The hash seed.
 * @param {unsigned long long | string | 64-bit hash object} [seed1] The hash seed.
 * @return {hash} 64-bit hash value.
**/
function hash64(str, [seed0], [seed1]);

/**
 * Compute hash for str by CityHash128().
 * @param {string} str The string to compute hash.
 * @param {string | 128-bit hash object} [seed0] The hash seed.
 * @return {hash} 128-bit hash value.
**/
function hash128(str, [seed0]);

/**
 * Compute hash crc for str by CityHashCrc128().
 * @param {string} str The string to compute hash.
 * @param {string | 128-bit hash object} [seed0] The hash seed.
 * @return {hash} 128-bit hash value.
**/
function crc128(str, [seed0]);

/**
 * Compute hash crc for str by CityHashCrc256().
 * @param {string} str The string to compute hash.
 * @return {array} 4 64-bit hash object in an array, eg [hash1, hash2, hash3, hash4].
**/
function crc256(str);

Usage

var cityhash = require('node-cityhash');
var hash;

hash = cityhash.stringify({low:1727229466, high:1535838579});
// hash = '6596376470467341850'

hash = cityhash.objectify('6596376470467341850');
// hash = {low: 1727229466, high: 1535838579, uint64: true}

hash = cityhash.hash64('Hello');
// hash = {
//    low: 1727229466,
//    high: 1535838579,
//    uint64: true,
//    value:'6596376470467341850'
//    }

hash = cityhash.hash64('Hello', 87392039);
// hash = {
//        low: 2569634289,
//        high: 3664379964,
//        uint64: true,
//        value: '15738392108067291633'
//    }

hash = cityhash.hash64('Hello', cityhash.objectify(87392039));
// hash = {
//        low: 2569634289,
//        high: 3664379964,
//        uint64: true,
//        value: '15738392108067291633'
//    }

hash = cityhash.hash64('Hello', 87392039, 1230234);
// hash = {
//        low: 2389520903,
//        high: 3787608545,
//        value: '16267654833214665223',
//        uint64: true,
//    }

hash = cityhash.hash128('Hello');
// hash = {
//        "low": {
//            "low": 68277041,
//            "high": 2127607426,
//            "value": "9138004313465017137",
//            "uint64": true
//        },
//        "high": {
//            "low": 3936042248,
//            "high": 2850538876,
//            "value": "12242971252332641544",
//            "uint64": true
//        },
//        "value": "9138004313465017137,12242971252332641544",
//        "uint128": true
//    }

hash = cityhash.hash128('Hello', '12343,30293');
// hash = {
//        "low": {
//            "low": 3184066266,
//            "high": 3674042232,
//            "value": "15779891233746910938",
//            "uint64": true
//        },
//        "high": {
//            "low": 4196783977,
//            "high": 3519958761,
//            "value": "15118107765960464233",
//            "uint64": true
//        },
//        "value": "15779891233746910938,15118107765960464233",
//        "uint128": true
//    }

hash = cityhash.hash128('Hello', cityhash.objectify('12343,30293'));
// hash = {
//        "low": {
//            "low": 3184066266,
//            "high": 3674042232,
//            "value": "15779891233746910938",
//            "uint64": true
//        },
//        "high": {
//            "low": 4196783977,
//            "high": 3519958761,
//            "value": "15118107765960464233",
//            "uint64": true
//        },
//        "value": "15779891233746910938,15118107765960464233",
//        "uint128": true
//    }

hash = cityhash.crc128('Hello');
// hash = {
//        "low": {
//            "low": 68277041,
//            "high": 2127607426,
//            "value": "9138004313465017137",
//            "uint64": true
//        },
//        "high": {
//            "low": 3936042248,
//            "high": 2850538876,
//            "value": "12242971252332641544",
//            "uint64": true
//        },
//        "value": "9138004313465017137,12242971252332641544",
//        "uint128": true
//    }

hash = cityhash.crc128('Hello', '12343,30293');
// hash = {
//        "low": {
//            "low": 3184066266,
//            "high": 3674042232,
//            "value": "15779891233746910938",
//            "uint64": true
//        },
//        "high": {
//            "low": 4196783977,
//            "high": 3519958761,
//            "value": "15118107765960464233",
//            "uint64": true
//        },
//        "value": "15779891233746910938,15118107765960464233",
//        "uint128": true
//    }

Benchmark

todo