Exemplo n.º 1
0
Hash *luaH_new(int32 nhash) {
	Hash *t = luaM_new(Hash);
	nhash = luaO_redimension((int32)((float)nhash / REHASH_LIMIT));
	nodevector(t) = hashnodecreate(nhash);
	nhash(t) = nhash;
	nuse(t) = 0;
	t->htag = TagDefault;
	luaO_insertlist(&roottable, (GCnode *)t);
	nblocks += gcsize(nhash);
	return t;
}
Exemplo n.º 2
0
static int newsize (stringtable *tb)
{
  int size = tb->size;
  int realuse = 0;
  int i;
  /* count how many entries are really in use */
  for (i=0; i<size; i++)
    if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY)
      realuse++;
  if (2*(realuse+1) <= size)  /* +1 is the new element */
    return size;  /* don't need to grow, just rehash to clear EMPTYs */
  else
    return luaO_redimension(size);
}
Exemplo n.º 3
0
static void rehash(Hash *t) {
	int32 nold = nhash(t);
	Node *vold = nodevector(t);
	int32 i;
	if (!emptyslots(t))
		nhash(t) = luaO_redimension(nhash(t));
	nodevector(t) = hashnodecreate(nhash(t));
	for (i = 0; i < nold; i++) {
		Node *n = vold + i;
		if (ttype(ref(n)) != LUA_T_NIL && ttype(val(n)) != LUA_T_NIL)
			*node(t, present(t, ref(n))) = *n;  // copy old node to luaM_new hash
	}
	nblocks += gcsize(t->nhash) - gcsize(nold);
	luaM_free(vold);
}
Exemplo n.º 4
0
static int newsize (Hash *t)
{
  Node *v = t->node;
  int size = nhash(t);
  int realuse = 0;
  int i;
  for (i=0; i<size; i++) {
    if (ttype(ref(v+i)) != LUA_T_NIL && ttype(val(v+i)) != LUA_T_NIL)
      realuse++;
  }
  if (2*(realuse+1) <= size)  /* +1 is the new element */
    return size;  /* don't need to grow, just rehash */
  else
    return luaO_redimension(size);
}