Пример #1
0
/*
** returns the 'main' position of an element in a table (that is,
** the index of its hash value). The key comes broken (tag in 'ktt'
** and value in 'vkl') so that we can call it on keys inserted into
** nodes.
*/
static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
  switch (withvariant(ktt)) {
    case LUA_TNUMINT:
      return hashint(t, ivalueraw(*kvl));
    case LUA_TNUMFLT:
      return hashmod(t, l_hashfloat(fltvalueraw(*kvl)));
    case LUA_TSHRSTR:
      return hashstr(t, tsvalueraw(*kvl));
    case LUA_TLNGSTR:
      return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl)));
    case LUA_TBOOLEAN:
      return hashboolean(t, bvalueraw(*kvl));
    case LUA_TLIGHTUSERDATA:
      return hashpointer(t, pvalueraw(*kvl));
    case LUA_TLCF:
      return hashpointer(t, fvalueraw(*kvl));
	default: {
		  GCObject *o;
		  lua_assert(!ttisdeadkey(kvl));
		  o = gcvalueraw(*kvl);
		  if (o->gchash == 0)
			  return hashpointer(t, o);
		  return hashint(t, withvariant(ktt) * o->gchash);
	  }
  }
}
Пример #2
0
/*
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
**
** Floating point numbers with integer value give the hash position of the
** integer (so they use the same table position).
*/
static Node *mainposition (const Table *t, const TValue *key) {
    switch (ttype(key)) {
#ifdef LUA_TINT
    case LUA_TINT:
        return hashint(t,ivalue(key));
#endif
    case LUA_TNUMBER: {
#ifdef LUA_TINT
        lua_Integer i;
        if (tt_integer_valued(key,&i))
            return hashint(t, i);
# ifdef LNUM_COMPLEX
        /* Complex numbers are hashed by their scalar part. Pure imaginary values
         * with scalar 0 or -0 should give same hash.
         */
        if (nvalue_img_fast(key)!=0 && luai_numeq(nvalue_fast(key),0))
            return gnode(t, 0);  /* 0 and -0 to give same hash */
# endif
#else
        if (luai_numeq(nvalue(key),0)) return gnode(t, 0);  /* 0 and -0 to give same hash */
#endif
        return hashnum(t,nvalue_fast(key));
    }
    case LUA_TSTRING:
        return hashstr(t, rawtsvalue(key));
    case LUA_TBOOLEAN:
        return hashboolean(t, bvalue(key));
    case LUA_TLIGHTUSERDATA:
        return hashpointer(t, pvalue(key));
    default:
        return hashpointer(t, gcvalue(key));
    }
}
Пример #3
0
dtNode* dtNodePool::getNode(unsigned int id)
{
	unsigned int bucket = hashint(id) & (m_hashSize-1);
	unsigned short i = m_first[bucket];
	dtNode* node = 0;
	while (i != DT_NULL_IDX)
	{
		if (m_nodes[i].id == id)
			return &m_nodes[i];
		i = m_next[i];
	}
	
	if (m_nodeCount >= m_maxNodes)
		return 0;
	
	i = (unsigned short)m_nodeCount;
	m_nodeCount++;
	
	// Init node
	node = &m_nodes[i];
	node->pidx = 0;
	node->cost = 0;
	node->total = 0;
	node->id = id;
	node->flags = 0;
	
	m_next[i] = m_first[bucket];
	m_first[bucket] = i;
	
	return node;
}
ALWAYS_INLINE
void BaseSet::addImpl(int64_t k) {
  if (!raw) {
    mutate();
  }
  auto h = hashint(k);
  auto p = findForInsert(k, h);
  assert(p);
  if (validPos(*p)) {
    // When there is a conflict, the add() API is supposed to replace the
    // existing element with the new element in place. However since Sets
    // currently only support integer and string elements, there is no way
    // user code can really tell whether the existing element was replaced
    // so for efficiency we do nothing.
    return;
  }
  if (UNLIKELY(isFull())) {
    makeRoom();
    p = findForInsert(k, h);
  }
  auto& e = allocElm(p);
  e.setIntKey(k, h);
  e.data.m_type = KindOfInt64;
  e.data.m_data.num = k;
  updateNextKI(k);
  if (!raw) {
    ++m_version;
  }
}
Пример #5
0
const dtNode* dtNodePool::findNode(unsigned int id) const
{
	unsigned int bucket = hashint(id) & (m_hashSize-1);
	unsigned short i = m_first[bucket];
	while (i != DT_NULL_IDX)
	{
		if (m_nodes[i].id == id)
			return &m_nodes[i];
		i = m_next[i];
	}
	return 0;
}
Пример #6
0
int main( ) {
  for ( int i = 0; i < 100; ++ i ) {
      printf( "%d\n", hashint( i ) );

      struct intholder z;
      z.a  = i;
      printf( "%d\n", hashzone( &z, sizeof(z)) );
          
  
  }

}
Пример #7
0
Файл: font.c Проект: nenau/naev
/**
 * @brief Gets or caches a glyph to render.
 */
static glFontGlyph* gl_fontGetGlyph( glFontStash *stsh, uint32_t ch )
{
   int i;
   unsigned int h;

   /* Use hash table and linked lists to find the glyph. */
   h = hashint(ch) & (HASH_LUT_SIZE-1);
   i = stsh->lut[h];
   while (i != -1) {
      if (stsh->glyphs[i].codepoint == ch)
         return &stsh->glyphs[i];
      i = stsh->glyphs[i].next;
   }

   /* Glyph not found, have to generate. */
   glFontGlyph *glyph;
   font_char_t ft_char;
   int idx;

   /* Load data from freetype. */
   font_makeChar( stsh, &ft_char, ch );

   /* Create new character. */
   glyph = &array_grow( &stsh->glyphs );
   glyph->codepoint = ch;
   glyph->tex   = NULL;
   glyph->adv_x = ft_char.adv_x;
   glyph->adv_y = ft_char.adv_y;
   glyph->next  = -1;
   idx = glyph - stsh->glyphs;

   /* Insert in linked list. */
   i = stsh->lut[h];
   if (i == -1) {
      stsh->lut[h] = idx;
   }
   else {
      while (i != -1) {
         if (stsh->glyphs[i].next == -1) {
            stsh->glyphs[i].next = idx;
            break;
         }
         i = stsh->glyphs[i].next;
      }
   }

   /* Find empty texture and render char. */
   gl_fontAddGlyphTex( stsh, &ft_char, glyph );

   return glyph;
}
void MixedArrayOffsetProfile::update(const ArrayData* ad,
                                     const StringData* sd,
                                     bool checkForInt) {
  auto const pos = [&]() -> int32_t {
    if (!ad->isMixed()) return -1;
    auto const a = MixedArray::asMixed(ad);

    int64_t i;
    return checkForInt && ad->convertKey(sd, i)
      ? a->find(i, hashint(i))
      : a->find(sd, sd->hash());
  }();
  update(pos, 1);
}
Пример #9
0
	u32 hash() const { return ( mIP.hash() ^ hashint(mPort) ); }
Пример #10
0
	u32 hash() const { return ( hashint(mInt) ); }
void MixedArrayOffsetProfile::update(const ArrayData* ad, int64_t i) {
  auto const pos = ad->isMixed()
    ? MixedArray::asMixed(ad)->find(i, hashint(i))
    : -1;
  update(pos, 1);
}