gburd/full-merge #8
1 changed files with 17 additions and 13 deletions
|
@ -933,24 +933,28 @@ __sm_remove_data(sparsemap_t *map, size_t offset, size_t gap_size)
|
||||||
void
|
void
|
||||||
__sm_merge_chunk(sparsemap_t *map, sparsemap_idx_t idx, sparsemap_idx_t capacity, __sm_chunk_t *dst_chunk, __sm_chunk_t *src_chunk)
|
__sm_merge_chunk(sparsemap_t *map, sparsemap_idx_t idx, sparsemap_idx_t capacity, __sm_chunk_t *dst_chunk, __sm_chunk_t *src_chunk)
|
||||||
{
|
{
|
||||||
int rc;
|
|
||||||
for (sparsemap_idx_t j = 0; j < capacity; j++) {
|
for (sparsemap_idx_t j = 0; j < capacity; j++) {
|
||||||
bool retried = false;
|
sparsemap_idx_t offset = __sm_get_chunk_offset(map, idx + j);
|
||||||
size_t position;
|
if (__sm_chunk_is_set(src_chunk, j)) {
|
||||||
sm_bitvec_t fill;
|
size_t position;
|
||||||
if (__sm_chunk_is_set(src_chunk, j) && !__sm_chunk_is_set(dst_chunk, j)) {
|
sm_bitvec_t fill;
|
||||||
retry:;
|
switch (__sm_chunk_set(dst_chunk, j, true, &position, &fill, false)) {
|
||||||
rc = __sm_chunk_set(dst_chunk, j, true, &position, &fill, retried);
|
case SM_NEEDS_TO_GROW:
|
||||||
if (rc == SM_NEEDS_TO_GROW) {
|
|
||||||
sparsemap_idx_t offset = __sm_get_chunk_offset(map, j + idx);
|
|
||||||
offset += sizeof(sm_idx_t) + position * sizeof(sm_bitvec_t);
|
offset += sizeof(sm_idx_t) + position * sizeof(sm_bitvec_t);
|
||||||
__sm_insert_data(map, offset, (uint8_t *)&fill, sizeof(sm_bitvec_t));
|
__sm_insert_data(map, offset, (uint8_t *)&fill, sizeof(sm_bitvec_t));
|
||||||
if (!retried) {
|
__sm_chunk_set(dst_chunk, j, true, &position, &fill, true);
|
||||||
retried = true;
|
break;
|
||||||
goto retry;
|
case SM_NEEDS_TO_SHRINK:
|
||||||
|
if (__sm_chunk_is_empty(src_chunk)) {
|
||||||
|
__sm_assert(position == 1);
|
||||||
|
__sm_remove_data(map, offset, sizeof(sm_idx_t) + sizeof(sm_bitvec_t) * 2);
|
||||||
|
__sm_set_chunk_count(map, __sm_get_chunk_count(map) - 1);
|
||||||
|
} else {
|
||||||
|
offset += sizeof(sm_idx_t) + position * sizeof(sm_bitvec_t);
|
||||||
|
__sm_remove_data(map, offset, sizeof(sm_bitvec_t));
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
__sm_assert(rc == SM_OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue