Example #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);
	  }
  }
}
Example #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));
    }
}
Example #3
0
static Node *mainposition (const Table *t, const Tvalue *key)
{
	switch (ttype(key)) {
	case KTAP_TNUMBER:
		return hashnum(t, nvalue(key));
	case KTAP_TLNGSTR: {
		Tstring *s = rawtsvalue(key);
		if (s->tsv.extra == 0) {  /* no hash? */
			s->tsv.hash = kp_string_hash(getstr(s), s->tsv.len, s->tsv.hash);
			s->tsv.extra = 1;  /* now it has its hash */
		}
		return hashstr(t, rawtsvalue(key));
		}
	case KTAP_TSHRSTR:
		return hashstr(t, rawtsvalue(key));
	case KTAP_TBOOLEAN:
		return hashboolean(t, bvalue(key));
	case KTAP_TLIGHTUSERDATA:
		return hashpointer(t, pvalue(key));
	case KTAP_TLCF:
		return hashpointer(t, fvalue(key));
	default:
		return hashpointer(t, gcvalue(key));
	}
}
Example #4
0
/*
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
*/
static Node *mainposition (const Table *t, const TValue *key) {
    switch (ttype(key)) {
    case LV_TNUMBER:
        return hashnum(t, nvalue(key));
    case LV_TSTRING:
        return hashstr(t, rawtsvalue(key));
    case LV_TBOOLEAN:
        return hashboolean(t, bvalue(key));
    case LV_TLIGHTUSERDATA:
        return hashpointer(t, pvalue(key));
    default:
        return hashpointer(t, gcvalue(key));
    }
}