Code Monkey home page Code Monkey logo

ctspookyhash's Introduction

Compile-Time SpookyHash

This is a version of Bob Jenkins' SpookyHash hashing algorithm that can be evaluated at compile time. The Hash128, Hash64, and Hash32 functions are now all constexpr and can be used for things like switch case statements. This is still a C++ implementation.

CTSpookyHash's output is identical to the original SpookyHash's, and performance is comparable when used in run-time situations. Just like the original SpookyHash, this code is in the public domain and can be used unconditionally.

How to Use

  1. Download CTSpookyHash.h and CTSpookyHash.cpp.
  2. Add them to your project.
  3. Use CTSpookyHash::Hash128, CTSpookyHash::Hash64 or CTSpookyHash::Hash32 in your code.
  4. Profit.

Notes

  • This is an implementation of SpookyHash V2.
  • C++11 is needed for constexpr.
  • Just like the original SpookyHash, this code is not portable to big-endian processors.
  • SpookyHash is not cryptographic: do not use it in security scenarios.
  • Turning off ALLOW_UNALIGNED_READS will make all functions run-time only.
  • Only messages that are smaller than 192 bytes (sc_bufSize) can be evaluated at compile time. Larger messages must be hashed at run-time.
  • The functions CTSpookyHash::Init, CTSpookyHash::Update and CTSpookyHash::Final are still run-time only.

Bob Jenkins' original version of SpookyHash is available at http://burtleburtle.net/bob/hash/spooky.html.

ctspookyhash's People

Contributors

theothermichael avatar

Stargazers

yanwei avatar

Watchers

 avatar

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.