void destroy_indirect_table(indirect_table *tab) { int i; indirect_buckets *buckets, *prev; indirect_array *arr = &tab->array; #ifdef O_PLMT simpleMutexDelete(&tab->mutex); #endif clean_block(arr->preallocated, PREALLOCATED_INDIRECT_BLOCKS); for(i=MSB(PREALLOCATED_INDIRECT_BLOCKS); i<MAX_INDIRECT_BLOCKS; i++) { if ( arr->blocks[i] ) { size_t bs = (size_t)1<<i; indirect *block = arr->blocks[i]+bs; clean_block(block, bs); PL_free(block); } } for(buckets = tab->table; buckets; buckets = prev) { prev = buckets->prev; PL_free(buckets->buckets); PL_free(buckets); } PL_free(tab); }
/* * Increment a[i] */ void sparse_array_incr(sparse_array_t *a, uint32_t i) { uint32_t k; k = block_of_index(i); if (k >= a->nblocks) { resize_sparse_array(a, k+1); } if (tst_bit(a->clean, k) && a->data[i] < UINT32_MAX) { if (a->data[i] == 0) { a->nelems ++; } a->data[i] ++; } else { set_bit(a->clean, k); clean_block(a->data, k); a->data[i] = 1; a->nelems ++; } }