Exemplo n.º 1
0
hash_u getHash(const char * seq, int length)
{
    //for ( int i = 0; i < length; i++ ) { cout << *(seq + i); } cout << endl;
    
    bool use64 = length > 16;
    char data[use64 ? 8 : 4];
    
#ifdef ARCH_32
    MurmurHash3_x86_32(seq, length > 16 ? 16 : length, seed, data);
    if ( use64 )
    {
        MurmurHash3_x86_32(seq + 16, length - 16, seed, data + 4);
    }
#else
    MurmurHash3_x64_128(seq, length, seed, data);
#endif    
    
    hash_u hash;
    
    if ( use64 )
    {
        hash.hash64 = *((hash64_t *)data);
    }
    else
    {
        hash.hash32 = *((hash32_t *)data);
    }
    
    return hash;
}
Exemplo n.º 2
0
void fillWriterVectors(const std::deque<BSONObj>& ops,
                       std::vector<std::vector<BSONObj>>* writerVectors) {
    for (std::deque<BSONObj>::const_iterator it = ops.begin(); it != ops.end(); ++it) {
        const BSONElement e = it->getField("ns");
        verify(e.type() == String);
        const char* ns = e.valuestr();
        int len = e.valuestrsize();
        uint32_t hash = 0;
        MurmurHash3_x86_32(ns, len, 0, &hash);

        const char* opType = it->getField("op").valuestrsafe();

        if (getGlobalServiceContext()->getGlobalStorageEngine()->supportsDocLocking() &&
            isCrudOpType(opType)) {
            BSONElement id;
            switch (opType[0]) {
                case 'u':
                    id = it->getField("o2").Obj()["_id"];
                    break;
                case 'd':
                case 'i':
                    id = it->getField("o").Obj()["_id"];
                    break;
            }

            const size_t idHash = BSONElement::Hasher()(id);
            MurmurHash3_x86_32(&idHash, sizeof(idHash), hash, &hash);
        }

        (*writerVectors)[hash % writerVectors->size()].push_back(*it);
    }
}
Exemplo n.º 3
0
Arquivo: set.c Projeto: lmb/Spielbub
static uint32_t add_to_filter(uint32_t filter, uint16_t value)
{
    uint32_t hash1, hash2;
    
    MurmurHash3_x86_32((const void*)&value, 2, SEED1, (void*)&hash1);
    MurmurHash3_x86_32((const void*)&value, 2, SEED2, (void*)&hash2);

    return filter | hash1 | hash2;
}
Exemplo n.º 4
0
void checkInterface(struct MergedBloomFilter *mbf, unsigned char *key, int *MatchVector, int *default_router, uint32_t *interface_num)
{
  char tmp[NAME_PREF_BUF]="";
  int key_len, slash_count = 0;
  uint32_t hash1, hash2, hash3;//, Flug = 0, num = 0;
  int Flug = 0, num = 0;
  
  memset(tmp,0,NAME_PREF_BUF);

  /*
  printf("MatchVector : ");
  for(int i=NAME_PREF_LEN-1; i>=0; i--){
	printf("%d",MatchVector[i]);
	if((i==24)||(i==16)||(i==8)) printf(" ");
  }
  printf("\n");
  */
  
  printf("---%s---\n",key);
  for(int i=NAME_PREF_LEN; i>=1; i--){
	if(MatchVector[i-1]){
	  for(int j = 1; j <= strlen(key); j++) {
		//printf("%c\n",*(key+j));
		if((*(key+j)=='/')||(*(key+j)=='\0')){
		  slash_count++;
		  if(slash_count == i){
			strncpy(tmp,key,j);
			tmp[j] = '\0';
			printf("%s : ",tmp);
			key_len = strlen(tmp);
			hash1 = MurmurHash3_x86_32 (tmp, key_len, 1);
			hash2 = MurmurHash3_x86_32 (tmp, key_len, 2);
			hash3 = MurmurHash3_x86_32 (tmp, key_len, 3);
			//Flug = 0;
			checkMergedBloomFilter(mbf, hash1, hash2, hash3, &Flug, &num);
			//printf("tmp = %s\n",tmp);
			//printf("num = %u\n",num);
			//printf("Flug = %u\n",Flug);
			*interface_num = num;
			//if(Flug==1) break;
			//if((Flug==1)||(Flug==2)) break;
			if(Flug!=0) break;
		  }
		}
	  }
	  //slash_count=0;
	  if(Flug==1){
		*default_router = 1;
		break;
	  }
	}
  }
  if(Flug==2) *default_router = 2;
  
  printf("\n");
}
Exemplo n.º 5
0
void makeHash(struct Name *list){
  uint32_t len;
  char *tmp;
  for(int i=0; i<=NAME_PREF_LEN; i++){
    struct List *node = list[i].next;
    for(; node != NULL; node = node->next){
      len = strlen(node->NamePrefix);
      tmp = node->NamePrefix;
      node->hash1 = MurmurHash3_x86_32 (tmp, len, 1);
      node->hash2 = MurmurHash3_x86_32 (tmp, len, 2);
      node->hash3 = MurmurHash3_x86_32 (tmp, len, 3);
    }
  }
}
Exemplo n.º 6
0
 //32bits
 template<> MurmurHash<32>::result_type MurmurHash<32>::salt(bool fixed)
 {
     if (fixed) {
         return result_type(0x58132134);
     }
     result_type h = 0;
     std::vector<zks::u8string> mac_addrs = get_mac_address();
     for (size_t i = 0; i < mac_addrs.size(); ++i) {
         MurmurHash3_x86_32((void*) mac_addrs[i].data(), (int)mac_addrs[i].size(), h, (void*) &h);
     }
     std::time_t now = std::time(nullptr);
     char* nowstr = std::ctime(&now);
     MurmurHash3_x86_32((void*) nowstr, (int)std::strlen(nowstr), h, (void*) &h);
     return h;
 }
Exemplo n.º 7
0
uint32_t flow_src_hash_bin(flow_src_t* p_flow_src, uint32_t map_size) {
#ifdef FLOW_SRC
    uint32_t hash;
    MurmurHash3_x86_32((void*)(&(p_flow_src->srcip)), sizeof(p_flow_src->srcip), 42, &hash);
    hash = hash - map_size * (hash / map_size); // A % B <=> A – B * (A / B)
    //printf("srcip:%u, hash_bin:%u, map_size:%u\n", p_flow_src->srcip, hash, map_size);
    return hash;
#endif

#ifdef FLOW_SRC_DST
    uint32_t hash = 0;
    MurmurHash3_x86_32((void*)p_flow_src, sizeof(flow_src_t), 42, &hash);
    hash = hash - map_size * (hash / map_size);
#endif
}
Exemplo n.º 8
0
ol_bucket *ol_get_bucket(const ol_database *db, const char *key, const size_t klen, char (*_key)[KEY_SIZE], size_t *_klen) {
    if (db == NULL)
        return NULL;

    uint32_t hash;
    _ol_trunc(key, klen, *_key);
    *_klen = strnlen(*_key, KEY_SIZE);

    if (*_klen == 0)
        return NULL;

    MurmurHash3_x86_32(*_key, *_klen, DEVILS_SEED, &hash);

    unsigned int index = _ol_calc_idx(db->cur_ht_size, hash);
    if (db->hashes[index] != NULL) {
        size_t larger_key = 0;
        ol_bucket *tmp_bucket;
        tmp_bucket = db->hashes[index];
        larger_key = tmp_bucket->klen > klen ? tmp_bucket->klen : klen;
        if (strncmp(tmp_bucket->key, key, larger_key) == 0) {
            return tmp_bucket;
        } else if (tmp_bucket->next != NULL) {
            /* Keys were not the same, traverse the linked list to see if it's
             * farther down. */
            do {
                tmp_bucket = tmp_bucket->next;
                larger_key = tmp_bucket->klen > klen ? tmp_bucket->klen : klen;
                if (strncmp(tmp_bucket->key, key, larger_key) == 0)
                    return tmp_bucket;
            } while (tmp_bucket->next != NULL);
        }
    }
    return NULL;
}
Exemplo n.º 9
0
size_t BlockHashIndex::GetFprint(const char* key) const
{
  size_t hash;
  MurmurHash3_x86_32(key, std::strlen(key), 100000, &hash);
  hash &= (1ul << m_fingerPrintBits) - 1;
  return hash;
}
Exemplo n.º 10
0
uint64_t Database::next_type_id()
{
	Engine& engine = Engine::get_instance();
	uint32_t shard;
	string id = SEQ_DATATYPE;
	MurmurHash3_x86_32(id.c_str(), id.size(), DataType::SEQUENCE, &shard);

	int size = id.size() + 32;
	uint64_t msg_id = engine.next_message_id();
	_enc_declare_(req, size);
	_enc_put_msg_header_(req, MessageType::SEQ_TYPE, msg_id, shard);
	_enc_put_string_(req, id);
	_enc_update_msg_size_(req);

	servernode_ptr node = ring->get_node(shard);
	boost::scoped_ptr<ReplyContext> context(new ReplyContext(msg_id));
	engine.save_context(context.get());
	node->connection->send(_enc_data_(req), _enc_size_(req));
	context->wait();
	engine.release_context(context.get());
	if (!context->done) return 0;

	int code;
	_dec_declare2_(rep, context->get_reply()->get_content_data(), context->get_reply()->get_content_size());
	_dec_get_var32_(rep, code);
	uint64_t val;
	if (code == ErrorCode::OK)
	{
		_dec_get_var64_(rep, val);
	}
	if (!_dec_valid_(rep)) return 0;
	if (code != ErrorCode::OK) return 0;
	return val;
}
Exemplo n.º 11
0
/*U32 SGL_DataSaveShader(const char * filePath, const char* name)
{
	U32 loc;
	U32 hash;
	SDL_RWops* rw;
	U32 size;
	U8* shaderData;
	{
		rw = SDL_RWFromFile(filePath, "rb");
		if (rw == NULL)
		{
			SDL_Log("SGL_DataSaveShader couldn't open file in path: %s, SDL_Error:%s", filePath, SDL_GetError());
			return SGL_FALSE;
		}
		size = SDL_RWseek(rw, 0, RW_SEEK_END);
		shaderData = SDL_malloc(size);
		SDL_RWseek(rw, 0, RW_SEEK_SET);
		if (SDL_RWread(rw, shaderData, size, 1) != 1)
		{
			SDL_RWclose(rw);
			SDL_Log("SGL_DataSaveShader couldn't read data from file in path: %s", filePath);
			return SGL_FALSE;
		}
		SDL_RWclose(rw);
	}
	targetData.block.shaderCount++;
	{
		rw = SDL_RWFromFile(targetData.path, "rb+");
		if (rw == NULL)
		{
			SDL_Log("SGL_DataSaveShader couldn't open file in path: %s, SDL_Error:%s", targetData.path, SDL_GetError());
			return SGL_FALSE;
		}
		loc = (U32)SDL_RWseek(rw, 0, RW_SEEK_END);
		if (SDL_RWwrite(rw, &size, sizeof(U32), 1) != 1)
		{
			SDL_RWclose(rw);
			SDL_Log("SGL_DataSaveShader couldn't write to data file in path: %s", targetData.path);
			return SGL_FALSE;
		}
		if (SDL_RWwrite(rw, shaderData, size, 1) != 1)
		{
			SDL_RWclose(rw);
			SDL_Log("SGL_DataSaveShader couldn't write to data file in path: %s", targetData.path);
			return SGL_FALSE;
		}
		SDL_RWseek(rw, 0, RW_SEEK_SET);
		if (SDL_RWwrite(rw, &targetData.block, sizeof(SGL_DataBlock), 1) != 1)
		{
			SDL_RWclose(rw);
			SDL_Log("SGL_DataSaveShader couldn't write to data file in path: %s, SDL_Error: %s", targetData.path, SDL_GetError());
			return SGL_FALSE;
		}
		SDL_RWclose(rw);
	}
	MurmurHash3_x86_32(name, (I32)SDL_strlen(name), targetData.block.seed, &hash);
	return AddNode(hash, loc);
	return SGL_TRUE;
}*/
SDL_Surface * SGL_DataLoadImage(const char * imageName)
{
	U32 hash;
	MurmurHash3_x86_32(imageName, (I32)SDL_strlen(imageName), targetData.block.seed, &hash);
	U32 loc = FindNodeLoc(hash);
	if (loc == SGL_FALSE)
	{
		return NULL;
	}
	SDL_RWops* rw = SDL_RWFromFile(targetData.path, "rb");
	if (rw == NULL)
	{
		SDL_Log("SGL_DataLoadImage couldn't open file in path: %s, SDL_Error:%s", targetData.path, SDL_GetError());
		return NULL;
	}
	SDL_RWseek(rw, loc, RW_SEEK_SET);
	SGL_FileSurface surfData;
	if (SDL_RWread(rw, &surfData, sizeof(SGL_FileSurface), 1) != 1)
	{
		SDL_RWclose(rw);
		SDL_Log("SGL_DataSaveImage couldn't read data from file in path: %s", targetData.path);
		return NULL;
	}
	const size_t size = surfData.h * surfData.w * (surfData.depth/8);
	void* pixels = SDL_malloc(size);
	if (SDL_RWread(rw, pixels, size, 1) != 1)
	{
		SDL_RWclose(rw);
		SDL_Log("SGL_DataSaveImage couldn't read data from file in path: %s", targetData.path);
		return NULL;
	}
	return SDL_CreateRGBSurfaceFrom(pixels, surfData.w, surfData.h, surfData.depth, surfData.w*(surfData.depth / 8), surfData.Rmask, surfData.Gmask, surfData.Bmask, surfData.Amask);
}
Exemplo n.º 12
0
Arquivo: muk.c Projeto: bd/urbit
/* functions
*/
  u3_noun
  u3qc_muk(u3_atom seed,
           u3_atom len,
           u3_atom key)
  {
    c3_w seed_w;
    c3_w len_w;
    c3_y *key_y;
    c3_w out_w;

    c3_assert(u3r_met(5, seed) <= 1);
    c3_assert(u3r_met(0, len)  <= 31);
    c3_assert(u3r_met(3, key)  <= len);

    seed_w = u3r_word(0, seed);
    len_w  = u3r_word(0, len);
    if (len_w > 0) { /* can't u3a_calloc 0 bytes */
      key_y  = u3a_calloc(sizeof(c3_y), len);
    } else {
      key_y = 0;
    }
    u3r_bytes(0, len, key_y, key);

    MurmurHash3_x86_32(key_y, len, seed_w, &out_w);

    u3a_free(key_y);
    return u3i_words(1, &out_w);
  }
/**
* Returns true if viewport should be squished for this shader.
***/
bool ShaderModificationRepository::SquishViewportForShader(IDirect3DVertexShader9* pActualVertexShader)
{
	// Hash the shader
	BYTE *pData = NULL;
	UINT pSizeOfData;

	pActualVertexShader->GetFunction(NULL, &pSizeOfData);
	pData = new BYTE[pSizeOfData];
	pActualVertexShader->GetFunction(pData,&pSizeOfData);

	uint32_t hash;
	MurmurHash3_x86_32(pData, pSizeOfData, VIREIO_SEED, &hash);

	delete[] pData;

	// find hash
	auto i = std::find(m_shaderViewportSquashIDs.begin(), m_shaderViewportSquashIDs.end(), hash);

	// found
	if (i != m_shaderViewportSquashIDs.end()) {
		return true;
	} 

	return false;
}
Exemplo n.º 14
0
int HashMap::_GetHash(std::string read_id)
{
    uint32_t hash_value = 0;
    MurmurHash3_x86_32(read_id.c_str(), strlen(read_id.c_str()), 0, &hash_value);

    return hash_value;
}
Exemplo n.º 15
0
uint32_t
MurmurHash3_x86_32_i(const void * key, int len, uint32_t seed)
{
    uint32_t out = 0;
    MurmurHash3_x86_32(key, len, seed, &out);
    return out;
}
Exemplo n.º 16
0
    //128bit;
    template<> MurmurHash<128>::result_type MurmurHash<128>::salt(bool fixed)
    {
        if (fixed) {
            result_type ret;
            uint32_t* p = (uint32_t*)&ret;
            (*p++) = 0x58132134;
            (*p++) = 0x94827513;
            (*p++) = 0x16574893;
            (*p)   = 0x17932864;
            return ret;
        }

        result_type h;
        uint32_t* p0 = (uint32_t*)&h;
        std::time_t now = std::time(nullptr);
        char* nowstr = std::ctime(&now);
        MurmurHash3_x86_32((void*)nowstr, (int)std::strlen(nowstr), 0, (void*)p0);

        std::vector<zks::u8string> mac_addrs = get_mac_address();
        for (size_t i = 0; i < mac_addrs.size(); ++i) {
#ifdef _ZKS64
            MurmurHash3_x64_128((void*)mac_addrs[i].data(), (int)mac_addrs[i].size(), *p0, (void*)&h);
#else
            MurmurHash3_x86_128((void*)mac_addrs[i].data(), (int)mac_addrs[i].size(), *p0, (void*)&h);
#endif
        }
        return h;
    }
Exemplo n.º 17
0
Cursor::Cursor(const CaptureConfig &config)
{
    id cursor = cursor_currentSystemCursor();
    BridgePoint hotSpot = cursor_hotSpot(cursor);
    BridgePoint mouseLocation = event_mouseLocation();
    id cursorImage = cursor_image(cursor);
    id tiffData = cursorImage != nil ?
        image_TIFFRepresentation(cursorImage) : nil;

    if (tiffData == nil) {
        m_imageID = Cursor::blankCursor();
        m_position.rx() = 0;
        m_position.ry() = 0;
        return;
    }

    MurmurHash3_x86_32(
                data_bytes(tiffData),
                data_length(tiffData),
                0,
                &m_imageID);

    if (m_cachedImages.find(m_imageID) == m_cachedImages.end()) {
        m_cachedImages.insert(m_imageID);
        bridgeWriteCursorFile(tiffData, m_imageID);
    }

    // The NSCursor Y coordinate's origin is at the bottom of the screen.
    // Invert it.
    mouseLocation.y =
        QApplication::desktop()->screenGeometry().height() - mouseLocation.y;

    m_position.rx() = mouseLocation.x - hotSpot.x - config.captureX;
    m_position.ry() = mouseLocation.y - hotSpot.y - config.captureY;
}
Exemplo n.º 18
0
std::size_t InputLayoutCache::hashInputLayout(const InputLayoutKey &inputLayout)
{
    static const unsigned int seed = 0xDEADBEEF;

    std::size_t hash = 0;
    MurmurHash3_x86_32(inputLayout.begin(), inputLayout.end() - inputLayout.begin(), seed, &hash);
    return hash;
}
Exemplo n.º 19
0
std::size_t RenderStateCache::hashBlendState(const BlendStateKey &blendState)
{
    static const unsigned int seed = 0xABCDEF98;

    std::size_t hash = 0;
    MurmurHash3_x86_32(&blendState, sizeof(gl::BlendState), seed, &hash);
    return hash;
}
Exemplo n.º 20
0
std::size_t RenderStateCache::hashSamplerState(const gl::SamplerState &samplerState)
{
    static const unsigned int seed = 0xABCDEF98;

    std::size_t hash = 0;
    MurmurHash3_x86_32(&samplerState, sizeof(gl::SamplerState), seed, &hash);
    return hash;
}
Exemplo n.º 21
0
std::size_t RenderStateCache::hashRasterizerState(const RasterizerStateKey &rasterState)
{
    static const unsigned int seed = 0xABCDEF98;

    std::size_t hash = 0;
    MurmurHash3_x86_32(&rasterState, sizeof(RasterizerStateKey), seed, &hash);
    return hash;
}
Exemplo n.º 22
0
std::size_t RenderStateCache::hashDepthStencilState(const gl::DepthStencilState &dsState)
{
    static const unsigned int seed = 0xABCDEF98;

    std::size_t hash = 0;
    MurmurHash3_x86_32(&dsState, sizeof(gl::DepthStencilState), seed, &hash);
    return hash;
}
Exemplo n.º 23
0
Arquivo: json.c Projeto: sahib/rmlint
static guint32 rm_fmt_json_generate_id(RmFmtHandlerJSON *self, RmFile *file,
                                       const char *file_path, char *cksum) {
    guint32 hash = 0;
    hash = file->inode ^ file->dev;
    hash ^= file->actual_file_size;

    for(int i = 0; i < 8192; ++i) {
        hash ^= MurmurHash3_x86_32(file_path, strlen(file_path), i);
        hash ^= MurmurHash3_x86_32(cksum, strlen(cksum), i);

        if(!g_hash_table_contains(self->id_set, GUINT_TO_POINTER(hash))) {
            break;
        }
    }

    g_hash_table_add(self->id_set, GUINT_TO_POINTER(hash));
    return hash;
}
Exemplo n.º 24
0
/**
 * Hash a paxos_connect identity descriptor, i.e., a string.
 */
unsigned
connect_key_hash(const void *data)
{
  uint32_t r;
  pax_str_t *str = (pax_str_t *)data;

  MurmurHash3_x86_32(str->data, str->size, murmurseed, &r);
  return r;
}
Exemplo n.º 25
0
uint32_t do_hash(char* key, size_t len)
{
        uint32_t out;

        MurmurHash3_x86_32(key, len, 0, &out);

        return out;

}
Exemplo n.º 26
0
/** Calculate the hash value for a function memoization signature
	@param[in] functPointer: Pointer to a function
	@param[in] numArgs: Number of arguments for the function
	@param[in] sizeOfArgs: A sum of sizeOf for the type of all given arguments
	@param[in] argumentData: A pointer to a memory block that stores a copy of all argument values passed to the function during this call
	@return: A 32 bit hash value calculated from the input params
*/
inline uint32_t calc_hash_memoization_signature(memoization_function_pointer functPointer, unsigned int numArgs, unsigned int sizeOfArgs, void* argumentData){
	uint32_t hashInputLen = SIZE_OF_ARGS(functPointer, numArgs, sizeOfArgs) + sizeOfArgs;
	void* hashInput = malloc(hashInputLen);
	uint32_t key = 0;
	uint32_t offset = 0;
	hashInput = STORE_ARGUMENTS(hashInput, offset, functPointer, sizeOfArgs);
	memcpy(hashInput+offset, argumentData, sizeOfArgs);
	MurmurHash3_x86_32(hashInput, hashInputLen, HASH_ALGORITHM_SEED, &key);
	free(hashInput);
	return key;
}
Exemplo n.º 27
0
void makeInterface(struct MergedBloomFilter *mbf, unsigned char *key, unsigned char *interface, uint32_t *port)
{
  uint32_t len, interface_num = 0, hash1, hash2, hash3;
  
  len = strlen(key);
  for(int i = 0; i < strlen(interface); i++)
	interface_num = interface_num * 10 + *(interface + i) - '0';
 
  if((0 <= interface_num) && (interface_num < FORWARDING_PORT_NUM)){
	hash1 = MurmurHash3_x86_32 (key, len, 1);
	hash2 = MurmurHash3_x86_32 (key, len, 2);
	hash3 = MurmurHash3_x86_32 (key, len, 3);
  
	makeMergedBloomFilter(mbf, key, hash1, hash2, hash3, interface_num);
  }
  else{
	//printf("Name[%s]'s Interface %d is Out of range.\n",key,interface_num);
	*port = 1;
  }
}
Exemplo n.º 28
0
void LongestPrefixMatching(struct Name *list, struct BloomFilter (*bf)[TEN_BIT], unsigned char *key, int *MatchVector)
{
  int prefix_len = 0, key_len = 0;
  char tmp[NAME_PREF_LEN]="";
  uint32_t hash1, hash2, hash3;

  memset(MatchVector,0,NAME_PREF_LEN);

  for(int i = 0; i < strlen(key); i++)
    if(*(key+i)=='/') prefix_len++;

  //NamePrefix最大長時の処理
  key_len = strlen(key);
  hash1 = MurmurHash3_x86_32 (key, key_len, 1);
  hash2 = MurmurHash3_x86_32 (key, key_len, 2);
  hash3 = MurmurHash3_x86_32 (key, key_len, 3);
  checkStage1BloomFilter(bf, prefix_len, hash1, hash2, hash3, MatchVector);
  
  //Longest Prefix Matching
  for(int j = strlen(key)-1; j > 0; j--) {
	if(*(key+j)=='/'){
      strncpy(tmp,key,j);
      tmp[j] = '\0';
	  key_len = strlen(tmp);
	  hash1 = MurmurHash3_x86_32 (tmp, key_len, 1);
	  hash2 = MurmurHash3_x86_32 (tmp, key_len, 2);
	  hash3 = MurmurHash3_x86_32 (tmp, key_len, 3);
	  prefix_len--;
	  checkStage1BloomFilter(bf, prefix_len, hash1, hash2, hash3, MatchVector);
	}
  }  
}
Exemplo n.º 29
0
/* Hash a buffer of length `len` to a 32-bit integer.
 * MurmurHash3 is used because it's fast, simple, public domain, and provides a 32-bit variant.
 */
uint32_t hash(const void * buf, size_t len)
{
    uint32_t hashcode;

    if (len > (size_t) INT_MAX)
    {
        fprintf(stderr, "Maximum line length (%d) exceeded: %zu.\n", INT_MAX, len);
        exit(1);
    }
    MurmurHash3_x86_32(buf, (int) len, HASH_SEED, &hashcode);

    return hashcode;
}
ERL_NIF_TERM
erlang_murmurhash3_x86_32_1_impl(ErlNifEnv* env, int, const ERL_NIF_TERM argv[])
{
    ErlNifBinary bin;
    uint32_t     h;

    if (!check_and_unpack_data(env, argv[0], &bin)) {
        return enif_make_badarg(env);
    }

    MurmurHash3_x86_32(bin.data, bin.size, 0, &h);

    return enif_make_uint(env, h);
}