Sha256: 8b669dc3f10b6a8a0c256b5155e8fa1985bfea5e321f59a910702a54251708d2

Contents?: true

Size: 2 KB

Versions: 6

Compression:

Stored size: 2 KB

Contents

//-----------------------------------------------------------------------------
// MurmurHash2 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
//-----------------------------------------------------------------------------
// LibSass only needs MurmurHash2, so we made this header only
//-----------------------------------------------------------------------------

#ifndef _MURMURHASH2_H_
#define _MURMURHASH2_H_

//-----------------------------------------------------------------------------
// Platform-specific functions and macros

// Microsoft Visual Studio

#if defined(_MSC_VER) && (_MSC_VER < 1600)

typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;

// Other compilers

#else	// defined(_MSC_VER)

#include <stdint.h>

#endif // !defined(_MSC_VER)

//-----------------------------------------------------------------------------

inline uint32_t MurmurHash2 ( const void * key, int len, uint32_t seed )
{
  // 'm' and 'r' are mixing constants generated offline.
  // They're not really 'magic', they just happen to work well.

  const uint32_t m = 0x5bd1e995;
  const int r = 24;

  // Initialize the hash to a 'random' value

  uint32_t h = seed ^ len;

  // Mix 4 bytes at a time into the hash

  const unsigned char * data = (const unsigned char *)key;

  while(len >= 4)
  {
    uint32_t k = *(uint32_t*)data;

    k *= m;
    k ^= k >> r;
    k *= m;

    h *= m;
    h ^= k;

    data += 4;
    len -= 4;
  }

  // Handle the last few bytes of the input array

  switch(len)
  {
  case 3:
    h ^= data[2] << 16;
    /* fall through */
  case 2:
    h ^= data[1] << 8;
    /* fall through */
  case 1:
    h ^= data[0];
    h *= m;
  };

  // Do a few final mixes of the hash to ensure the last few
  // bytes are well-incorporated.

  h ^= h >> 13;
  h *= m;
  h ^= h >> 15;

  return h;
} 

//-----------------------------------------------------------------------------

#endif // _MURMURHASH2_H_

Version data entries

6 entries across 5 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/sassc-2.4.0/ext/libsass/src/MurmurHash2.hpp
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0/ext/libsass/src/MurmurHash2.hpp
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sassc-2.4.0/ext/libsass/src/MurmurHash2.hpp
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/ext/libsass/src/MurmurHash2.hpp
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/sassc-2.4.0/ext/libsass/src/MurmurHash2.hpp
sassc-2.4.0 ext/libsass/src/MurmurHash2.hpp