Convert Figma logo to code with AI

aappleby logosmhasher

Automatically exported from code.google.com/p/smhasher

2,629
469
2,629
70

Top Related Projects

8,937

Extremely fast non-cryptographic hash algorithm

Quick Overview

SMHasher is a test suite designed to test the quality of hash functions. It provides a comprehensive set of tests to evaluate various properties of hash functions, including distribution, avalanche, and collision resistance. The project aims to help developers choose appropriate hash functions for their specific use cases and to assist in the development of new hash functions.

Pros

  • Comprehensive test suite for evaluating hash functions
  • Supports a wide range of hash functions, including popular ones like MurmurHash and CityHash
  • Provides detailed statistical analysis and visualizations of test results
  • Open-source and actively maintained

Cons

  • Primarily focused on non-cryptographic hash functions
  • Can be complex to set up and use for beginners
  • Limited documentation for some advanced features
  • May require significant computational resources for thorough testing of complex hash functions

Code Examples

  1. Testing a custom hash function:
#include "SMHasher.h"

uint32_t MyCustomHash(const void* key, int len, uint32_t seed) {
    // Your hash function implementation here
}

int main(int argc, char** argv) {
    HashInfo hi;
    hi.hash = MyCustomHash;
    hi.name = "MyCustomHash";
    
    TestHashFunction(hi);
    return 0;
}
  1. Running specific tests on a hash function:
#include "SMHasher.h"

int main(int argc, char** argv) {
    HashInfo hi;
    hi.hash = MurmurHash3_x86_32;
    hi.name = "MurmurHash3_x86_32";
    
    Test<Blob>("Bit Independence Criteria", 100000, 300, hi.hash, true);
    TestDistribution(hi.hash, 0, 10000000);
    
    return 0;
}
  1. Comparing multiple hash functions:
#include "SMHasher.h"

int main(int argc, char** argv) {
    std::vector<HashInfo> hashFunctions = {
        { MurmurHash3_x86_32, "MurmurHash3_x86_32" },
        { CityHash32, "CityHash32" },
        { FNV1a, "FNV1a" }
    };
    
    for (const auto& hi : hashFunctions) {
        TestHashFunction(hi);
    }
    
    return 0;
}

Getting Started

To use SMHasher:

  1. Clone the repository:

    git clone https://github.com/aappleby/smhasher.git
    
  2. Build the project:

    cd smhasher
    mkdir build && cd build
    cmake ..
    make
    
  3. Run the test suite:

    ./SMHasher
    

To test your own hash function, create a new C++ file with your implementation, include it in the project, and modify the main.cpp file to include your hash function in the test suite.

Competitor Comparisons

8,937

Extremely fast non-cryptographic hash algorithm

Pros of xxHash

  • Faster performance, especially for large data sets
  • Provides both 32-bit and 64-bit hash functions
  • Offers a streaming API for processing data in chunks

Cons of xxHash

  • Limited to non-cryptographic hash functions
  • Fewer hash algorithm implementations compared to SMHasher
  • Less comprehensive testing suite for hash quality

Code Comparison

SMHasher (MurmurHash3):

uint32_t MurmurHash3_x86_32(const void* key, int len, uint32_t seed) {
  const uint8_t* data = (const uint8_t*)key;
  const int nblocks = len / 4;
  uint32_t h1 = seed;
  // ... (additional implementation)
}

xxHash:

XXH32_hash_t XXH32(const void* input, size_t length, XXH32_hash_t seed) {
    const xxh_u8* p = (const xxh_u8*)input;
    const xxh_u8* const bEnd = p + length;
    // ... (additional implementation)
}

Both repositories focus on non-cryptographic hash functions, but xxHash prioritizes speed and simplicity, while SMHasher offers a broader range of hash algorithms and extensive testing. xxHash is more suitable for performance-critical applications, whereas SMHasher is better for evaluating and comparing different hash functions.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SMHasher is a test suite designed to test the distribution, collision, and performance properties of non-cryptographic hash functions.

This is the home for the MurmurHash family of hash functions along with the SMHasher test suite used to verify them. SMHasher is released under the MIT license. All MurmurHash versions are public domain software, and the author disclaims all copyright to their code.

SMHasher is a test suite designed to test the distribution, collision, and performance properties of non-cryptographic hash functions - it aims to be the DieHarder of hash testing, and does a pretty good job of finding flaws with a number of popular hashes.

The SMHasher suite also includes MurmurHash3, which is the latest version in the series of MurmurHash functions - the new version is faster, more robust, and its variants can produce 32- and 128-bit hash values efficiently on both x86 and x64 platforms.

Updates

1/8/2016

Woo, we're on Github! I've been putting off the migration for a few, uh, years or so, but hopefully Github won't be shutting down any time soon so I don't have to move things again. MurmurHash is still used all over the place, SMHasher is still the defacto hash function test suite, and there are all sorts of interesting new hash functions out there that improve bulk hashing speed and use new shiny hardware instructions for AES and whatnot. Interesting times. :)

I've copied the few wiki pages from code.google.com/p/smhasher to this wiki, though I haven't reformatted them to Markdown yet. The MurmurHash page on Wikipedia should also be linking here now as well. Feel free to send me pull requests.