/* * Initialize store */ static void init_term_store(term_store_t *store) { uint32_t n; n = TERM_STORE_DEF_SIZE; assert(n < TERM_STORE_MAX_SIZE); store->size = n; store->nterms = 0; store->term = (term_t *) safe_malloc(n * sizeof(term_t)); n = TERM_STORE_DEF_MSIZE; store->max_term = n; store->mark = allocate_bitvector0(n); }
/* * Initialize a: * - n = minimal size requested * - if n is 0, the default size is used * - all blocks are marked as clean */ void init_sparse_array(sparse_array_t *a, uint32_t n) { uint32_t nblocks; if (n == 0) { nblocks = DEF_SPARSE_ARRAY_NBLOCKS; } else { nblocks = (n + (BSIZE - 1)) >> BSIZE_NBITS; assert(n <= nblocks * BSIZE); if (nblocks > MAX_NBLOCKS) { out_of_memory(); } } // adjust n to a multiple of the block size n = nblocks * BSIZE; a->data = (uint32_t *) safe_malloc(n * sizeof(uint32_t)); a->clean = allocate_bitvector0(nblocks); // all dirty a->nblocks = nblocks; a->nelems = 0; }