コード例 #1
0
ファイル: input_lines.c プロジェクト: MLDroid/harry
/** 
 * Converts the beginning of a text line to a label. The label is computed
 * by matching a regular expression, either directly if the match is a
 * number or indirectly by hashing.
 * @param line Text line
 * @return label value.
 */
static float get_label(char *line)
{
    char *endptr, *name = line, old;
    regmatch_t pmatch[1];

    /* No match found */
    if (regexec(&re, line, 1, pmatch, 0))
        return 1.0;

    name = line + pmatch[0].rm_so;
    old = line[pmatch[0].rm_eo];
    line[pmatch[0].rm_eo] = 0;

    /* Test direct conversion */
    float f = strtof(name, &endptr);

    /* Compute hash value */
    if (!endptr || strlen(endptr) > 0)
        f = MurmurHash64B(name, strlen(name), 0xc0d3bab3) % 0xffff;

    line[pmatch[0].rm_eo] = old;

    /* Shift string. This is very inefficient. I know */
    memmove(line, line + pmatch[0].rm_eo, strlen(line) - pmatch[0].rm_eo + 1);
    return f;
}
コード例 #2
0
ファイル: vec.c プロジェクト: NguyenNhatNam/salad
const dim_t hash(const char* const s, const size_t len)
{
	assert(s != NULL && len >= 0);

	// TODO: Make the the number of bits configurable
	const int numBits = 24;
	dim_t hashMask = ((long long unsigned) 2 << (numBits - 1)) - 1;

	// TODO: 0x123457678 is the magic number used in Sally
	return MurmurHash64B(s, len, 0x12345678) & hashMask;
}
コード例 #3
0
ERL_NIF_TERM
erlang_murmurhash64b_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 = MurmurHash64B(bin.data, bin.size, 0);

    return enif_make_uint64(env, h);
}
コード例 #4
0
ファイル: setting_cache.cpp プロジェクト: Carye/gdipp
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];
}
コード例 #5
0
ファイル: util.c プロジェクト: Kolpashnikova/harry
/**
 * Hashes a string to a 64 bit hash. Utility function to limit
 * the clatter of code.
 * @param s Byte sequence
 * @param l Length of sequence
 * @return hash value
 */
uint64_t hash_str(char *s, int l)
{
    uint64_t ret = 0;

#ifdef ENABLE_MD5HASH
    unsigned char buf[MD5_DIGEST_LENGTH];
#endif

#ifdef ENABLE_MD5HASH
    MD5((unsigned char *) s, l, buf);
    memcpy(&ret, buf, sizeof(int64_t));
#else
    ret = MurmurHash64B(s, l, 0x12345678);
#endif

    return ret;
}
コード例 #6
0
ファイル: ring_murmurhash.c プロジェクト: MajdiSobain/ring
void ring_murmurhash64b(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("murmurhash64b expects the first parameter to be a string");
        return;
    }

    if (!RING_API_ISNUMBER(2)) {
        RING_API_ERROR("murmurhash64b 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("murmurhash64b expects the third parameter to be an integer\n");
        }
    }

    out = MurmurHash64B(key, keylen, seed);

    MH_RETURN_LONG(out, ret_type);
}
コード例 #7
0
ファイル: input_fasta.c プロジェクト: rkabir/sally
/** 
 * Converts a description to a label. The label is computed by matching 
 * a regular expression, either directly if the match is a number or 
 * indirectly by hashing.
 * @param desc Description 
 * @return label value.
 */
static float get_label(char *desc)
{
    char *endptr, *name = desc;
    regmatch_t pmatch[1];
    
    /* No match found */
    if (regexec(&re, desc, 1, pmatch, 0)) 
        return 0;

    name = desc + pmatch[0].rm_so;
    desc[pmatch[0].rm_eo] = 0;
    
    /* Test direct conversion */
    float f = strtof(name, &endptr);
    
    /* Compute hash value */
    if (!endptr || strlen(endptr) > 0) 
        f = MurmurHash64B(name, strlen(name), 0xc0d3bab3) % 0xffff;
    
    return f;
}