Beispiel #1
0
    inline boost::uint64_t hash_value(std::pair<A, B> const& value, boost::uint64_t seed)
    {
        seed = hash_value(value.first, seed);
        seed = hash_value(value.second, seed);

        return seed;
    }
Beispiel #2
0
Game::Game(const PTree& root) :
    background_tiles(get_background_tiles(root.get_child("game.board"))),
    hashed_background_tiles(make_hashed_pair(background_tiles)),
    turn_max(root.get<int>("game.maxTurns")),
    turn(root.get<int>("game.turn")),
    state(root, hashed_background_tiles)
{
    assert( state == state );
    assert( hash_value(state) == hash_value(state) );

    int kk = 0;
    const PTree& child_heroes = root.get_child("game.heroes");
    for (PTree::const_iterator ti=child_heroes.begin(), tie=child_heroes.end(); ti!=tie; ti++)
    {
#if !defined(NDEBUG)
        const int id = ti->second.get<int>("id");
        assert( kk+1 == id );
#endif

        const_cast<HeroInfo&>(hero_infos[kk]) = HeroInfo(ti->second);

        assert( kk < 4 );
        kk++;
    }

}
Beispiel #3
0
    inline boost::uint64_t hash_value(const boost::posix_time::ptime& value, boost::uint64_t seed)
    {
        seed = hash_value(value.date(), seed);
        seed = hash_value(value.time_of_day(), seed);

        return seed;
    }
ULONG PathDataCacheKey::UpdateHashValue()
{
    const STSStyle& style = m_style.get();
    m_hash_value = m_str_id;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += hash_value(m_scalex);
    m_hash_value += (m_hash_value<<5);
    m_hash_value += hash_value(m_scaley);
    m_hash_value += (m_hash_value<<5);
    m_hash_value += style.charSet;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += CStringElementTraits<CString>::Hash(style.fontName);
    m_hash_value += (m_hash_value<<5);
    m_hash_value += style.fontSize;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += style.fontSpacing;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += style.fontWeight;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += style.fItalic;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += style.fUnderline;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += style.fStrikeOut;
    return m_hash_value;
}
ULONG ClipperTraits::Hash( const CClipper& key )
{
    ULONG hash = key.m_polygon->m_str.GetId();
    hash += (hash<<5);
    hash += key.m_inverse;
    hash += (hash<<5);
    hash += key.m_effectType;
    hash += (hash<<5);
    hash += key.m_size.cx;
    hash += (hash<<5);
    hash += key.m_size.cy;
    hash += (hash<<5);
    hash += hash_value(key.m_polygon->m_scalex);
    hash += (hash<<5);
    hash += hash_value(key.m_polygon->m_scaley);

    for (int i=0;i<sizeof(key.m_effect.param)/sizeof(key.m_effect.param[0]);i++)
    {
        hash += (hash<<5);
        hash += key.m_effect.param[i];
    }
    for (int i=0;i<sizeof(key.m_effect.t)/sizeof(key.m_effect.t[0]);i++)
    {
        hash += (hash<<5);
        hash += key.m_effect.t[i];
    }
    return hash;
}
bool priority_order(const Value_Type& t1, const Value_Type& t2)
{
   std::size_t hash1 = hash_value(t1);
   boost::hash_combine(hash1, &t1);
   std::size_t hash2 = hash_value(t2);
   boost::hash_combine(hash2, &t2);
   return hash1 < hash2;
}
Beispiel #7
0
bool priority_order( const testvalue<Hooks, ConstantTimeSize> &t1
                   , const testvalue<Hooks, ConstantTimeSize> &t2)
{
   std::size_t hash1 = hash_value(t1);
   boost::hash_combine(hash1, &t1);
   std::size_t hash2 = hash_value(t2);
   boost::hash_combine(hash2, &t2);
   return hash1 < hash2;
}
Beispiel #8
0
std::size_t
hash_value(Term const& x)
{
  if (Name const* n = as<Name>(&x))
    return hash_value(*n);
  if (Type const* t = as<Type>(&x))
    return hash_value(*t);
  if (Expr const* e = as<Expr>(&x))
    return hash_value(*e);
  if (Decl const* d = as<Decl>(&x))
    return hash_value(*d);
  lingo_unreachable();
}
Beispiel #9
0
void test_edge_hash_and_null(const P& p)
{
  typedef boost::graph_traits<P> GT;
  typedef typename GT::halfedge_descriptor halfedge_descriptor;
  typedef typename GT::vertex_descriptor vertex_descriptor;
  typedef typename GT::face_descriptor face_descriptor;

  BOOST_FOREACH(halfedge_descriptor h, halfedges(p))
  {
    assert(
      hash_value( edge(h,p) ) ==
      hash_value( edge(opposite(h,p),p) ) );
  }
ULONG TextInfoCacheKey::UpdateHashValue() 
{
    m_hash_value = m_str_id;
    m_hash_value += (m_hash_value<<5);
    m_hash_value += hash_value( static_cast<const STSStyleBase&>(m_style.get()) );
    m_hash_value += (m_hash_value<<5);
    m_hash_value += hash_value( m_style.get().fontScaleX );
    m_hash_value += (m_hash_value<<5);
    m_hash_value += hash_value( m_style.get().fontScaleY );
    m_hash_value += (m_hash_value<<5);
    m_hash_value += hash_value( m_style.get().fontSpacing );
    return m_hash_value;
}
Beispiel #11
0
TEST_F(TestTile, hash_value) {
    Tile test_tile;
    test_tile.flowcell = "a";
    test_tile.lane = 1;
    test_tile.id = 1101;
    test_tile.subtile_x = 1;
    test_tile.subtile_y = 5;

    Tile test_tile2 = test_tile;

    ASSERT_TRUE(hash_value(test_tile) == hash_value(test_tile2));

    test_tile2.subtile_y = 6;
    ASSERT_FALSE(hash_value(test_tile) == hash_value(test_tile2));
}
Beispiel #12
0
bool
hash_add(struct hash *hash, const void *key, void *value, bool replace)
{
    uint32_t hv;
    struct hash_bucket *bucket;
    struct hash_element *he;
    bool ret = false;

    hv = hash_value(hash, key);
    bucket = &hash->buckets[hv & hash->mask];

    if ((he = hash_lookup_fast(hash, bucket, key, hv))) /* already exists? */
    {
        if (replace)
        {
            he->value = value;
            ret = true;
        }
    }
    else
    {
        hash_add_fast(hash, bucket, key, hv, value);
        ret = true;
    }

    return ret;
}
Beispiel #13
0
const TargetPhraseCollection *PhraseDictionary::GetTargetPhraseCollectionLEGACY(const Phrase& src) const
{
  const TargetPhraseCollection *ret;
  if (m_maxCacheSize) {
    CacheColl &cache = GetCache();

    size_t hash = hash_value(src);

    std::map<size_t, std::pair<const TargetPhraseCollection*, clock_t> >::iterator iter;

    iter = cache.find(hash);

    if (iter == cache.end()) {
      // not in cache, need to look up from phrase table
      ret = GetTargetPhraseCollectionNonCacheLEGACY(src);
      if (ret) {
        ret = new TargetPhraseCollection(*ret);
      }

      std::pair<const TargetPhraseCollection*, clock_t> value(ret, clock());
      cache[hash] = value;
    } else {
      // in cache. just use it
      std::pair<const TargetPhraseCollection*, clock_t> &value = iter->second;
      value.second = clock();

      ret = value.first;
    }
  } else {
    // don't use cache. look up from phrase table
    ret = GetTargetPhraseCollectionNonCacheLEGACY(src);
  }

  return ret;
}
Beispiel #14
0
void HashTable::rehash()
{
    size_t new_size, i;
    HashNode **new_buckets = NULL;

    new_size = hash_size(this->entries * 2 / (this->high + this->low));
    if (new_size == this->num_buckets)
    {
        return;
    }
    new_buckets = (HashNode **)calloc(new_size, sizeof(HashNode *));

    for (i = 0; i < this->num_buckets; i++)
    {
        HashNode *entry = this->buckets[i];
        while (entry)
        {
            HashNode *nhe = entry->next_in_bucket;
            uint32_t hv = hash_value(entry->name, new_size);
            entry->next_in_bucket = new_buckets[hv];
            new_buckets[hv] = entry;
            entry = nhe;
        }
    }

    this->num_buckets = new_size;
    free(this->buckets);
    this->buckets = new_buckets;
    this->resized_count++;
}
Beispiel #15
0
size_t
hash_value(const UsdSkelSkeletonQuery& query)
{
    size_t hash = hash_value(query._definition);
    boost::hash_combine(hash, query._animQuery);
    return hash;
}
Beispiel #16
0
/*
 * Requires:
 *  Nothing.
 *
 * Effects:
 *  Searches the hash table "ht" for the string "key".  If "key" is found,
 *  returns its associated value.  Otherwise, returns NULL.
 */
void *
hash_table_lookup(struct hash_table *ht, int key)
{
    hash_table_mapping *elem;
    unsigned int index;

    /*
     * Compute the array index of the collision chain in which "key"
     * should be found.
     */
    index = hash_value(key, ht) % ht->size;
    /* 
     * Iterate over that collision chain.
     */
    for (elem = ht->head[index]; elem != NULL; elem = elem->next) {
        /*
         * If "key" matches the element's key, then return the
         * element's value.
         */
        if (elem->key == key)
            return (elem->value);
    }
    /*
     * Otherwise, return NULL to indicate that "key" was not found.
     */
    return (NULL);
}
Beispiel #17
0
    bool add( const char *filename ) {
        std::streampos size = file_size( filename );

        if( size > 0xffffffff ) { // WTF? tellg should return -1, instead it returns '-1 with sign bit set to zero...'
            std::cout << "ignore " << filename << "\n";
            return false;
        }
        
        uint64_t name_hash = hash_value( filename );
        size_t bucket = name_hash % table_size_;
        
        // remember current 'next pointer' for writing later 
        ptrs_.push_back( std::make_pair( link_offsets_[bucket], append_pos_ ) );
        
        
        // statistics: count as 'extra hop' if link_offset_[bucket] does not point into hash table (i.e., the bucket is non-empty)
        if( link_offsets_[bucket] >= table_size_ * int_size ) {
            ++num_extra_hops_;
        }
        
        // update 'next pointer'
        link_offsets_[bucket] = append_pos_;
        
        // remember file content location (starts after the chaining link)
        size_t file_pos = append_pos_ + int_size;
        file_dest_.push_back( std::make_pair( std::string(filename), file_pos ));

        file_pos += strlen(filename) + 1 + 8;
        file_pos = align( file_pos );
//         std::cout << "file pos: " << file_pos << "\n";
        append_pos_ = file_pos + size;
        
        return true;
    }
Beispiel #18
0
int add_to_sers(char const *host, int fd)
{
	int index = sers.index;
	int i;
	int const host_hash = hash_value(host);

	/* 未使用,需要初始化 */
	if (0 == index) {
		for (i = 0; i < SERVERS; i ++) {
			sers.ser[i].fd = -1;
			sers.ser[i].hash_key = -1;
		}
	}

	/* 找到被删除的空位 */
	for (i = 0; i < index && i < SERVERS; i ++)
		if (0 > sers.ser[i].fd) {		/* 删除后留下的空位fd为负 */
			sers.ser[i].fd = fd;
			sers.ser[i].hash_key = host_hash;
			return 0;
		}
	/* 估计的SERVERS过小 */
	if (i >= SERVERS)
		return -1;
	/* 没有空位 */
	sers.ser[i].fd = fd;
	sers.ser[i].hash_key = host_hash;
	sers.index ++;

	return 0;
}
Beispiel #19
0
symbol_st *lookup(char *name)
{
	int total = NHASH;
	symbol_st *psym = NULL;

	if(name == NULL) {
		yyerror("invalid input name!");		
		return NULL;
	}

	psym = &symbol_table[hash_value(name)%NHASH];	
	while(total-- > 0) {
		if(psym->name == NULL) {
			psym->name = strdup(name);		
			return psym;
		} else if(!strcmp(psym->name, name)) {
			return psym;	
		}
		psym++;
		if(psym >= symbol_table + NHASH)
			psym = symbol_table;
	}

	yyerror("the hash table is full!");
	exit(0);
}
Beispiel #20
0
String* String::resize_capacity(STATE, Fixnum* count) {
    native_int sz = count->to_native();

    if(sz < 0) {
        Exception::argument_error(state, "negative byte array size");
    } else if(sz >= INT32_MAX) {
        // >= is used deliberately because we use a size of + 1
        // for the byte array
        Exception::argument_error(state, "too large byte array size");
    }

    CharArray* ba = CharArray::create(state, sz + 1);
    native_int copy_size = sz;
    native_int data_size = as<CharArray>(data_)->size();

    // Check that we don't copy any data outside the existing byte array
    if(unlikely(copy_size > data_size)) {
        copy_size = data_size;
    }
    memcpy(ba->raw_bytes(), byte_address(), copy_size);

    // We've unshared
    shared(state, Qfalse);
    data(state, ba);
    hash_value(state, nil<Fixnum>());

    // If we shrunk it and num_bytes said there was more than there
    // is, clamp it.
    if(num_bytes()->to_native() > sz) {
        num_bytes(state, count);
    }

    return this;
}
Beispiel #21
0
String* String::string_dup(STATE) {
    Module* mod = klass_;
    Class*  cls = try_as_instance<Class>(mod);

    if(unlikely(!cls)) {
        while(!cls) {
            mod = mod->superclass();

            if(mod->nil_p()) rubinius::bug("Object::class_object() failed to find a class");

            cls = try_as_instance<Class>(mod);
        }
    }

    String* so = state->new_object<String>(cls);

    so->set_tainted(is_tainted_p());

    so->num_bytes(state, num_bytes());
    so->data(state, data());
    so->hash_value(state, hash_value());

    so->shared(state, Qtrue);
    shared(state, Qtrue);

    return so;
}
Beispiel #22
0
Hash *copy_frame(Hash *frame){
    Hash *copy = create_empty_frame();

    void add_key_value(void *key){
        void *value = hash_value(frame, key);
        frame_add(copy, key, value);
    }
void symbol_init_hash() {
    int i;
    for(i=0; i<MOD; i++) {
        hash_table[i].flag = 0;	 // marking the entries as unused
    }
    for(i=0; i<30; i++) {
        // Hash this keyword
        int val = hash_value(keyword_list[i])%MOD;
        // Start quadratic probing
        int j;
        for(j=0; j<MOD; j++) {
            val = (val + j + j*j)%MOD;
            if(hash_table[val].flag == 0)
            {
                strcpy(hash_table[val].keyword,keyword_list[i]);
                hash_table[val].flag = 1;
                hash_table[val].pos = i;
                break;
            }
        }
        if(j == MOD)
            printf("%s couldn't be inserted\n", keyword_list[i]);
    }

}
idn_result_t
idn__strhash_put(idn__strhash_t hash, const char *key, void *value) {
	unsigned long h, h_index;
	strhash_entry_t *entry;

	assert(hash != NULL && key != NULL);

	h = hash_value(key);
	h_index = h % hash->nbins;

	if ((entry = find_entry(hash->bins[h_index], key, h)) != NULL) {
		/* Entry exists.  Replace the value. */
		entry->value = value;
	} else {
		/* Create new entry. */
		if ((entry = new_entry(key, value)) == NULL) {
			return (idn_nomemory);
		}
		/* Insert it to the list. */
		entry->next = hash->bins[h_index];
		hash->bins[h_index] = entry;
		hash->nelements++;

		if (hash->nelements > hash->nbins * THRESHOLD) {
			idn_result_t r;
			r = expand_bins(hash, hash->nbins * FACTOR);
			if (r != idn_success) {
				TRACE(("idn__strhash_put: hash table "
					"expansion failed\n"));
			}
		}
	}

	return (idn_success);
}
bool run_test(uint32_t* hash_out) {
    char* data = benchmark_in_situ_copy(file_data, file_size);
    if (!data)
        return false;

    ubjr_context_t* src = ubjr_open_memory((uint8_t*)data, (uint8_t*)(data + file_size));
    ubjr_dynamic_t dynamic = ubjr_read_dynamic(src);
    hash_value(&dynamic, UBJ_MIXED, 0, hash_out);
    ubjr_cleanup_dynamic(&dynamic);

    // ubjr has a bug where it leaks the userdata. it never calls the
    // close_cb, but even if it did, free() in memclose() is
    // commented out. this ugly hack frees it manually.
    free(((void**)src)[4]);

    ubjr_close_context(src);
    benchmark_in_situ_free(data);

    // ubjr_open_memory() sets NULL as the error handling callback.
    // I don't know how it is meant to handle errors, and it seems to
    // have lots of bugs (for example priv_ubjw_read_integer() returns
    // 0 on error, but 0 is also a valid integer.) The return value
    // of memread() is also never checked so if the data is truncated
    // it just continues using uninitialized memory, which seems to
    // easily throw it into an infinite loop or infinite recursion.
    //
    // For now we'll have to skip error checking, but this seems like
    // an unfair advantage for ubj. Data validation is fundamental
    // to security and it affects performance.
    return true;
}
Beispiel #26
0
  String* String::append(STATE, const char* other, std::size_t length) {
    size_t new_size = size() + length;
    size_t capacity = data_->size();

    if(capacity < (new_size + 1)) {
      // capacity needs one extra byte of room for the trailing null
      do {
        // @todo growth should be more intelligent than doubling
        capacity *= 2;
      } while(capacity < (new_size + 1));

      // No need to call unshare and duplicate a ByteArray
      // just to throw it away.
      if(shared_ == Qtrue) shared(state, Qfalse);

      ByteArray *ba = ByteArray::create(state, capacity);
      std::memcpy(ba->bytes, data_->bytes, size());
      data(state, ba);
    } else {
      if(shared_ == Qtrue) unshare(state);
    }

    // Append on top of the null byte at the end of s1, not after it
    std::memcpy(data_->bytes + size(), other, length);

    // The 0-based index of the last character is new_size - 1
    data_->bytes[new_size] = 0;

    num_bytes(state, Integer::from(state, new_size));
    hash_value(state, (Integer*)Qnil);

    return this;
  }
	void reserve(size_type n) {
		if (size_ == 0) {
			elements.resize(n, std::make_pair(res_empty, V()));
			return;
		}

		static container vals;
		vals.resize(0);
		vals.reserve(size_);
		for (size_type i = 0, ie = capacity(); i < ie; ++i) {
			if (elements[i].first != res_empty && elements[i].first != res_del) {
				vals.push_back(elements[i]);
			}
		}

		clear(n);
		size_ = vals.size();
		size_t max = capacity() - 1;
		for (size_type i = 0, ie = vals.size(); i < ie; ++i) {
			size_t spot = hash_value(vals[i].first) & max;
			while (elements[spot].first != res_empty && elements[spot].first != vals[i].first) {
				spot = (spot + 5) & max;
			}
			elements[spot] = vals[i];
		}
	}
Beispiel #28
0
int su_map_has(su_state *s, int idx) {
	value_t v = *STK(-1);
	unsigned hash = hash_value(&v);
	v = map_get(s, STK(TOP(idx))->obj.m, &v, hash);
	s->stack_top--;
	return v.type != SU_INV;
}
Beispiel #29
0
void su_setglobal(su_state *s, const char *name) {
	value_t v;
	unsigned size = strlen(name);
	v.type = SU_STRING;
	v.obj.gc_object = string_from_cache(s, name, size);
	set_global(s, name, hash_value(&v), size, STK(-1));
	su_pop(s, 1);
}
size_t PhraseBasedReorderingState::hash() const
{
  size_t ret;
  ret = hash_value(m_prevRange);
  boost::hash_combine(ret, m_direction);

  return ret;
}