예제 #1
0
/*
 * Resize the array to at least nb blocks
 * - nb must be more than a->nblocks
 */
static void resize_sparse_array(sparse_array_t *a, uint32_t nb) {
  uint32_t i, nblocks, n;
  uint32_t *tmp;

  if (nb > MAX_NBLOCKS) {
    out_of_memory();
  }

  n = a->nblocks;
  nblocks = n;
  nblocks += nblocks>>1; // try 50% larger
  if (nb > nblocks) {
    nblocks = nb;
  } else if (nblocks > MAX_NBLOCKS) {
    nblocks = MAX_NBLOCKS;
  }

  // n = current size, nblocks = new size
  // we avoid realloc here (to save the cost of copying the full array)
  tmp = (uint32_t *) safe_malloc(nblocks * (BSIZE * sizeof(uint32_t)));
  a->clean = extend_bitvector0(a->clean, n, nblocks);

  // copy all clean blocks from a->data to tmp
  n = a->nblocks;
  for (i=0; i<n; i++) {
    if (tst_bit(a->clean, i)) {
      copy_block(tmp, a->data, i);
    }
  }

  safe_free(a->data);
  a->data = tmp;
  a->nblocks = nblocks;
}
예제 #2
0
 * Mark term t
 */
static void term_store_mark_term(term_store_t *store, term_t t) {
  uint32_t n;

  assert(t >= 0);

  n = store->max_term;
  if (t >= n) {
    // make the mark vector large enough to mark t: try to double its size
    // if that's not enough allocate a vector of size
    n += n;
    if (t >= n) {
      n = (t + 8) >> 3; // ceil((t+1)/8)
    }
    store->mark = extend_bitvector0(store->mark, n, store->max_term);
    store->max_term = n;
    assert(t < n);
  }
  set_bit(store->mark, t);
}



/*
 * Check whether t is present in store
 */
static bool term_store_contains_term(term_store_t *store, term_t t) {
  return t < store->max_term && tst_bit(store->mark, t);
}