void updateSketch(const DataTypeT& data)
 {
     uint64_t v = MurmurHash64A(&data,
         sizeof(DataTypeT), seed_);
     uint32_t bit = (v & 0xFFFFFFFF) % BITSIZE;
     sketch_.set(bit);
 }
Esempio n. 2
0
 void updateSketch(const DataTypeT& data)
 {
     uint64_t v = MurmurHash64A(&data,
         sizeof(DataTypeT), seed_);
     uint8_t lsb = LSB(v/fm_k_);
     sketch_[v % fm_k_].set(lsb);
     level2sketches_[v % fm_k_].updateBucket(lsb, data);
 }
Esempio n. 3
0
static unsigned long
hs_hash(const void *object, unsigned long seed)
{
	const char *c = object;
	unsigned long h;

	h = (unsigned long)MurmurHash64A(c, strlen(c), seed);
	return h;
}
ERL_NIF_TERM
erlang_murmurhash64a_1_impl(ErlNifEnv* env, int, const ERL_NIF_TERM argv[])
{
    ErlNifBinary bin;
    uint64_t     h;

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

    h = MurmurHash64A(bin.data, bin.size, 0);

    return enif_make_uint64(env, h);
}
Esempio n. 5
0
void test_updateM() {
    byte results[] = {3, 4, 3, 3};
    uint b = 2;
    Hyperloglog *hll = create_hll(b, 0);
    uint64_t digest;

    for (uint32_t i = 0; i < 10; i++) {
        digest = MurmurHash64A(&i, 4, 42);
        updateM(hll, digest);
    }

    assert_array_eq(results, hll->M, hll->m, byte);

    free(hll);
}
Esempio n. 6
0
const font_setting_cache *gdimm_setting_cache::lookup(const gdimm_setting_trait *setting_trait)
{
#ifdef _M_X64
	uint64_t cache_trait = MurmurHash64A(setting_trait, sizeof(gdimm_setting_trait), 0);
#else
	uint64_t cache_trait = MurmurHash64B(setting_trait, sizeof(gdimm_setting_trait), 0);
#endif // _M_X64

	// if the setting for the specified font is not found
	// construct setting cache for the font and return
	map<uint64_t, font_setting_cache>::const_iterator iter = _cache.find(cache_trait);
	if (iter == _cache.end())
	{
		// double-check lock
		gdimm_lock lock(LOCK_SETTING_CACHE);
		iter = _cache.find(cache_trait);
		if (iter == _cache.end())
		{
			font_setting_cache new_cache;

			wcs_convert(gdipp_get_gdimm_setting(L"auto_hinting", setting_trait), reinterpret_cast<WORD *>(&new_cache.auto_hinting));
			wcs_convert(gdipp_get_gdimm_setting(L"embedded_bitmap", setting_trait), &new_cache.embedded_bitmap);
			wcs_convert(gdipp_get_gdimm_setting(L"embolden", setting_trait), &new_cache.embolden);

			wcs_convert(gdipp_get_gdimm_setting(L"gamma/red", setting_trait), &new_cache.gamma.red);
			wcs_convert(gdipp_get_gdimm_setting(L"gamma/green", setting_trait), &new_cache.gamma.green);
			wcs_convert(gdipp_get_gdimm_setting(L"gamma/blue", setting_trait), &new_cache.gamma.blue);

			wcs_convert(gdipp_get_gdimm_setting(L"hinting", setting_trait), reinterpret_cast<WORD *>(&new_cache.hinting));
			wcs_convert(gdipp_get_gdimm_setting(L"kerning", setting_trait), &new_cache.kerning);

			wcs_convert(gdipp_get_gdimm_setting(L"renderer", setting_trait), reinterpret_cast<WORD *>(&new_cache.renderer));
			wcs_convert(gdipp_get_gdimm_setting(L"render_mode/mono", setting_trait), reinterpret_cast<WORD *>(&new_cache.render_mode.mono));
			wcs_convert(gdipp_get_gdimm_setting(L"render_mode/gray", setting_trait), reinterpret_cast<WORD *>(&new_cache.render_mode.gray));
			wcs_convert(gdipp_get_gdimm_setting(L"render_mode/subpixel", setting_trait), reinterpret_cast<WORD *>(&new_cache.render_mode.subpixel));
			wcs_convert(gdipp_get_gdimm_setting(L"render_mode/pixel_geometry", setting_trait), reinterpret_cast<WORD *>(&new_cache.render_mode.pixel_geometry));
			wcs_convert(gdipp_get_gdimm_setting(L"render_mode/aliased_text", setting_trait), reinterpret_cast<WORD *>(&new_cache.render_mode.aliased_text));

			wcs_convert(gdipp_get_gdimm_setting(L"shadow/offset_x", setting_trait), &new_cache.shadow.offset_x);
			wcs_convert(gdipp_get_gdimm_setting(L"shadow/offset_x", setting_trait), &new_cache.shadow.offset_y);
			wcs_convert(gdipp_get_gdimm_setting(L"shadow/alpha", setting_trait), reinterpret_cast<WORD *>(&new_cache.shadow.alpha));

			_cache[cache_trait] = new_cache;
		}
	}

	return &_cache[cache_trait];
}
Esempio n. 7
0
static bucket2 * search_kmer ( hashtable2 * ht, kmer_t2 * t_kmer )
{
	uint64_t hv = MurmurHash64A ( t_kmer, sizeof ( kmer_t2 ), 0 );
	size_t hash_idx = ( size_t ) ( hv % ht->ht_sz );
	bucket2 * starter = ht->store_pos[hash_idx];

	while ( starter )
	{
		if ( kmerCompare ( & ( starter->kmer_t2 ), t_kmer ) == 0 )
		{
			return starter;
		}

		starter = starter->nxt_bucket;
	}

	return NULL;
}
static vertex2 * search_vertex ( vertex_hash2 * v_ht, kmer_t2 * vertex_kmer ) //fixed ...
{
	uint64_t hv = MurmurHash64A ( vertex_kmer->kmer, sizeof ( kmer_t2 ), 0 ); //hash value
	uint64_t idx = ( size_t ) ( hv % v_ht->ht_sz );
	vertex2 * ver = ( v_ht->store_pos ) [idx];

	while ( ver )
	{
		if ( kmerCompare ( & ( ver->kmer_t2 ), vertex_kmer ) == 0 )
		{
			return ver;
		}

		ver = ver->next;
	}

	return NULL;
}
Esempio n. 9
0
void ring_murmurhash64a(void *pPointer)
{
    char *key = NULL;
    int keylen;
    int seed = 0;
    uint64_t out;
    int ret_type = 0;

    if (RING_API_PARACOUNT < 2 || RING_API_PARACOUNT > 3) {
		RING_API_ERROR(RING_API_MISS2PARA);
		return ;
	}

    if (!RING_API_ISSTRING(1)) {
        RING_API_ERROR("murmurhash64a expects the first parameter to be a string");
        return;
    }

    if (!RING_API_ISNUMBER(2)) {
        RING_API_ERROR("murmurhash64a expects the first parameter to be an integer");
        return;
    }

    key = RING_API_GETSTRING(1);
    keylen = strlen(key);
    seed = RING_API_GETNUMBER(2);

    if (RING_API_PARACOUNT == 3) {
        if (RING_API_ISNUMBER(3)) {
            ret_type = RING_API_GETNUMBER(3);
            if (!is_bool(ret_type)) {
                RING_API_ERROR("Third parameter should be boolean value\n");
            }
        } else {
            RING_API_ERROR("murmurhash64a expects the third parameter to be an integer\n");
        }
    }

    out = MurmurHash64A(key, keylen, seed);

    MH_RETURN_LONG(out, ret_type);
}
Esempio n. 10
0
static ssize_t murmur2_64_handler(machine_t *machine, request_t *request){ // {{{
	uint64_t               hash              = 0;
	data_t                *key               = NULL;
	murmur_userdata       *userdata          = (murmur_userdata *)machine->userdata;
	
	key = hash_data_find(request, userdata->input);
	if(key == NULL){
		if(userdata->fatal == 0)
			return machine_pass(machine, request);
		return error("input key not supplied");
	}
	
	hash = MurmurHash64A(key, 0);
	
	request_t r_next[] = {
		{ userdata->output, DATA_UINT64T(hash) },
		hash_next(request)
	};
	return machine_pass(machine, r_next);
} // }}}
Esempio n. 11
0
sqlite3_stmt *YesqlClient::construct_sql_insert(const TableId& table, const Key& key, const ValueMap& values){
  sqlite3_stmt* ret = nullptr;
  bool prepared = false;
  std::string sql;
  sql.append("INSERT OR REPLACE INTO ");
  sql.append(table);
  sql.append(" (");
  sql.append(KEYNAME);
  sql.append(",");
  for (auto& it: values){
    sql.append(it.first);
    sql.append(",");
  }
  sql.back() = ')';
  sql.append(" VALUES (");
  sql.append("?,");
  for (auto& it : values){
    sql.append("?,");
  }
  sql.back() = ')';

  int rc = stmt_cache(STMT_INDEX_INSERT, sql.c_str(), &ret);
  
  if (rc == SQLITE_OK){
    int count = 1;
    rc = sqlite3_bind_int64(ret, count++, MurmurHash64A(key.c_str(), (int) key.length()));
    //rc = sqlite3_bind_text(ret, count++, key.c_str(), (int) key.length(), SQLITE_STATIC);
    
    for (auto& it : values){
      if (rc != SQLITE_OK) break;
      rc = sqlite3_bind_text(ret, count++, it.second.c_str(), (int) it.second.length(), SQLITE_STATIC);
    }
  }
  if (rc != SQLITE_OK){
    LOG("Error %s insert: %s\n\tSQL was: %s\n", (prepared) ? "binding" : "preparing",
	            sqlite3_errmsg(_dbhandle), sql.c_str());
    //sqlite3_finalize(ret);
    ret = nullptr;
  }
  return ret;
}
static vertex2 * put_vertex ( vertex_hash2 * v_ht, kmer_t2 vertex_kmer, int & is_found ) //63 127 differ fixed
{
	uint64_t hv = MurmurHash64A ( vertex_kmer.kmer, sizeof ( kmer_t2 ), 0 ); //hash value
	uint64_t idx = ( size_t ) ( hv % v_ht->ht_sz );
	vertex2 * ver = ( v_ht->store_pos ) [idx];

	if ( !ver )
	{
		( v_ht->store_pos ) [idx] = ( vertex2 * ) malloc ( sizeof ( vertex2 ) );
		ver = ( v_ht->store_pos ) [idx];
		ver->kmer_t2 = vertex_kmer;
		ver->left = NULL;
		ver->right = NULL;
		ver->next = NULL;
		is_found = 0;
		return ver;
	}

	while ( ver )
	{
		if ( kmerCompare ( & ( ver->kmer_t2 ), &vertex_kmer ) == 0 )
		{
			is_found = 1;
			return ver;
		}

		if ( ver->next == NULL ) { break; }

		ver = ver->next;
	}

	is_found = 0;
	ver->next = ( vertex2 * ) malloc ( sizeof ( vertex2 ) );
	ver->next->kmer_t2 = vertex_kmer;
	ver->next->left = NULL;
	ver->next->right = NULL;
	ver->next->next = NULL;
	return ver->next;
}
Esempio n. 13
0
sqlite3_stmt *YesqlClient::construct_sql_update(const TableId& table, const Key& key, const ValueMap& values){
  sqlite3_stmt* ret = nullptr;
  bool prepared = false;
  std::string sql;
  sql.append("UPDATE OR FAIL ");
  sql.append(table);
  sql.append(" SET ");
  for (auto& it : values){
    sql.append(it.first);
    sql.append("=upper(");
    sql.append(it.first);
    sql.append("),");
  }
  sql.back() = ' ';
  sql.append("WHERE ");
  sql.append(KEYNAME);
  sql.append("=?");
  
  int rc = stmt_cache(STMT_INDEX_UPDATE, sql.c_str(), &ret);
  
  if (rc == SQLITE_OK){
    int count = 1;
    prepared = true;
    //for (auto& it : values){
    //  rc = sqlite3_bind_text(ret, count++, it.second.c_str(), (int) it.second.length(), SQLITE_STATIC);
    //  if (rc != SQLITE_OK) break;
    //}
    rc = sqlite3_bind_int64(ret, count, MurmurHash64A(key.c_str(), (int) key.length()));
    //rc = sqlite3_bind_text(ret, count, key.c_str(), (int) key.length(), SQLITE_STATIC);
  }
  if (rc != SQLITE_OK){
    LOG("Error %s update: %s\n\tSQL was: %s\n", (prepared) ? "binding" : "preparing",
	            sqlite3_errmsg(_dbhandle), sql.c_str());
    //sqlite3_finalize(ret);
    ret = nullptr;
  }
  return ret;
}
uint64_t hash(void *key) {
	return MurmurHash64A(key, 8, 0x9747b28c);
}
 inline uint64_t get_hash() {
   return MurmurHash64A(&key, sizeof(key), 0x818c4070) & ary->size_mask;
 }
Esempio n. 16
0
/**
 * eblob_l2hash_key() - second hash for eblob key
 */
static inline __attribute_pure__
eblob_l2hash_t eblob_l2hash_key(const struct eblob_key *key)
{
	assert(key != NULL);
	return MurmurHash64A(key, EBLOB_ID_SIZE, 0);
}
Esempio n. 17
0
inline int bind_key(sqlite3_stmt* stmt, const Key& key){
  return sqlite3_bind_int64(stmt, 1, MurmurHash64A(key.c_str(), (int) key.length()));
  //return sqlite3_bind_text(stmt, 1, key.c_str(), (int) key.length(), SQLITE_STATIC);
}
Esempio n. 18
0
size_t session_hash::operator()(const session_key& sk) const {
	return MurmurHash64A(&sk, sizeof(sk), 0xee6b27eb);
}