mt_rehash(mrb_state *mrb, mt_tbl *t)
{
  size_t old_alloc = t->alloc;
  size_t new_alloc = old_alloc+8;
  struct mt_elem *old_table = t->table;

  khash_power2(new_alloc);
  if (old_alloc == new_alloc) return;

  t->alloc = new_alloc;
  t->size = 0;
  t->table = (struct mt_elem*)mrb_calloc(mrb, sizeof(struct mt_elem), new_alloc);

  for (size_t i = 0; i < old_alloc; i++) {
    struct mt_elem *slot = &old_table[i];

    /* key = 0 means empty or deleted */
    if (slot->key != 0) {
      mt_put(mrb, t, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
    }
  }
  mrb_free(mrb, old_table);
}
mt_rehash(mrb_state *mrb, mt_tbl *t)
{
  size_t old_alloc = t->alloc;
  size_t new_alloc = old_alloc+8;
  struct mt_elem *old_table = t->table;

  khash_power2(new_alloc);
  if (old_alloc == new_alloc) return;

  t->alloc = new_alloc;
  t->size = 0;
  t->table = (struct mt_elem*)mrb_calloc(mrb, sizeof(struct mt_elem), new_alloc);

  for (size_t i = 0; i < old_alloc; i++) {
    struct mt_elem *slot = &old_table[i];

     
    if (slot->key != 0) {
      mt_put(mrb, t, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
    }
  }
  mrb_free(mrb, old_table);
}