struct mail_index_view *view;
ARRAY_TYPE(mail_index_strmap_rec) recs;
- ARRAY(uint32_t) recs_crc32;
+ ARRAY(uint32_t) recs_hash;
struct hash2_table *hash;
mail_index_strmap_key_cmp_t *key_compare;
struct mail_index_strmap_hash_key {
const char *str;
- uint32_t crc32;
+ uint32_t hash;
};
/* renumber the string indexes when highest string idx becomes larger than
static bool
mail_index_strmap_read_rec_next(struct mail_index_strmap_read_context *ctx,
- uint32_t *crc32_r);
+ uint32_t *hash_r);
static void
mail_index_strmap_set_syscall_error(struct mail_index_strmap *strmap,
{
const struct mail_index_strmap_hash_key *key = _key;
- return key->crc32;
+ return key->hash;
}
static bool
view->next_str_idx = 1;
i_array_init(&view->recs, 64);
- i_array_init(&view->recs_crc32, 64);
+ i_array_init(&view->recs_hash, 64);
view->hash = hash2_create(0, sizeof(struct mail_index_strmap_rec),
mail_index_strmap_hash_key,
mail_index_strmap_hash_cmp, view);
*_view = NULL;
array_free(&view->recs);
- array_free(&view->recs_crc32);
+ array_free(&view->recs_hash);
hash2_destroy(&view->hash);
i_free(view);
}
{
view->remap_cb(NULL, 0, 0, view->cb_context);
array_clear(&view->recs);
- array_clear(&view->recs_crc32);
+ array_clear(&view->recs_hash);
hash2_clear(view->hash);
view->last_added_uid = 0;
static int
mail_index_strmap_read_rec_first(struct mail_index_strmap_read_context *ctx,
- uint32_t *crc32_r)
+ uint32_t *hash_r)
{
size_t size;
uint32_t n, i, count, str_idx;
int ret;
- /* <uid> <n> <crc32>*count <str_idx>*count
+ /* <uid> <n> <hash>*count <str_idx>*count
where
n = 0 -> count=1 (only Message-ID:)
n = 1 -> count=2 (Message-ID: + In-Reply-To:)
return -1;
count = n < 2 ? n + 1 : n;
/* check that rec_size fits */
- if (UINT_MAX / (sizeof(ctx->rec.str_idx) + sizeof(*crc32_r)) < count)
+ if (UINT_MAX / (sizeof(ctx->rec.str_idx) + sizeof(*hash_r)) < count)
return -1;
ctx->view->total_ref_count += count;
- ctx->rec_size = count * (sizeof(ctx->rec.str_idx) + sizeof(*crc32_r));
+ ctx->rec_size = count * (sizeof(ctx->rec.str_idx) + sizeof(*hash_r));
ret = mail_index_strmap_uid_exists(ctx, ctx->rec.uid);
if (ret < 0)
return -1;
/* everything exists. save it. FIXME: these ref_index values
are thread index specific, perhaps something more generic
should be used some day */
- ctx->end = ctx->data + count * sizeof(*crc32_r);
+ ctx->end = ctx->data + count * sizeof(*hash_r);
ctx->next_ref_index = 0;
- if (!mail_index_strmap_read_rec_next(ctx, crc32_r))
+ if (!mail_index_strmap_read_rec_next(ctx, hash_r))
i_unreached();
ctx->next_ref_index = n == 1 ? 1 : 2;
return 1;
static bool
mail_index_strmap_read_rec_next(struct mail_index_strmap_read_context *ctx,
- uint32_t *crc32_r)
+ uint32_t *hash_r)
{
if (ctx->data == ctx->end) {
i_stream_skip(ctx->view->strmap->input, ctx->rec_size);
/* read the record contents */
memcpy(&ctx->rec.str_idx, ctx->str_idx_base, sizeof(ctx->rec.str_idx));
- memcpy(crc32_r, ctx->data, sizeof(*crc32_r));
+ memcpy(hash_r, ctx->data, sizeof(*hash_r));
ctx->rec.ref_index = ctx->next_ref_index++;
ctx->highest_str_idx = ctx->rec.str_idx;
/* get to the next record */
- ctx->data += sizeof(*crc32_r);
+ ctx->data += sizeof(*hash_r);
ctx->str_idx_base += sizeof(ctx->rec.str_idx);
return TRUE;
}
static int
strmap_read_block_next(struct mail_index_strmap_read_context *ctx,
- uint32_t *crc32_r)
+ uint32_t *hash_r)
{
uint32_t uid_diff;
int ret;
- if (mail_index_strmap_read_rec_next(ctx, crc32_r))
+ if (mail_index_strmap_read_rec_next(ctx, hash_r))
return 1;
/* get next UID */
return -1;
ctx->rec.uid += uid_diff;
- ret = mail_index_strmap_read_rec_first(ctx, crc32_r);
+ ret = mail_index_strmap_read_rec_first(ctx, hash_r);
} while (ret == 0);
return ret;
}
static int
strmap_view_sync_block_check_conflicts(struct mail_index_strmap_read_context *ctx,
- uint32_t crc32)
+ uint32_t hash)
{
struct mail_index_strmap_rec *hash_rec;
struct hash2_iter iter;
- if (crc32 == 0) {
+ if (hash == 0) {
/* unique string - there are no conflicts */
return 0;
}
strmap index until X has been expunged. */
i_zero(&iter);
while ((hash_rec = hash2_iterate(ctx->view->hash,
- crc32, &iter)) != NULL &&
+ hash, &iter)) != NULL &&
hash_rec->str_idx != ctx->rec.str_idx) {
- /* CRC32 matches, but string index doesn't */
+ /* hash matches, but string index doesn't */
if (!strmap_view_sync_handle_conflict(ctx, hash_rec, &iter)) {
ctx->lost_expunged_uid = hash_rec->uid;
return -1;
mail_index_strmap_view_sync_block(struct mail_index_strmap_read_context *ctx)
{
struct mail_index_strmap_rec *hash_rec;
- uint32_t crc32, prev_uid = 0;
+ uint32_t hash, prev_uid = 0;
int ret;
- while ((ret = strmap_read_block_next(ctx, &crc32)) > 0) {
+ while ((ret = strmap_read_block_next(ctx, &hash)) > 0) {
if (ctx->rec.uid <= ctx->view->last_added_uid) {
if (ctx->rec.uid < ctx->view->last_added_uid ||
prev_uid != ctx->rec.uid) {
}
prev_uid = ctx->rec.uid;
- if (strmap_view_sync_block_check_conflicts(ctx, crc32) < 0) {
+ if (strmap_view_sync_block_check_conflicts(ctx, hash) < 0) {
ret = -1;
break;
}
/* add the record to records array */
array_push_back(&ctx->view->recs, &ctx->rec);
- array_push_back(&ctx->view->recs_crc32, &crc32);
+ array_push_back(&ctx->view->recs_hash, &hash);
/* add a separate copy of the record to hash */
- hash_rec = hash2_insert_hash(ctx->view->hash, crc32);
+ hash_rec = hash2_insert_hash(ctx->view->hash, hash);
memcpy(hash_rec, &ctx->rec, sizeof(*hash_rec));
}
return strmap_read_block_deinit(ctx, ret, TRUE);
ref_index > view->last_ref_index));
hash_key.str = key;
- hash_key.crc32 = crc32_str_nonzero(key);
+ hash_key.hash = crc32_str_nonzero(key);
old_rec = hash2_lookup(view->hash, &hash_key);
if (old_rec != NULL) {
rec->ref_index = ref_index;
rec->str_idx = str_idx;
array_push_back(&view->recs, rec);
- array_push_back(&view->recs_crc32, &hash_key.crc32);
+ array_push_back(&view->recs_hash, &hash_key.hash);
view->last_added_uid = uid;
view->last_ref_index = ref_index;
rec.ref_index = ref_index;
rec.str_idx = view->next_str_idx++;
array_push_back(&view->recs, &rec);
- array_append_zero(&view->recs_crc32);
+ array_append_zero(&view->recs_hash);
view->last_added_uid = uid;
view->last_ref_index = ref_index;
{
struct mail_index_strmap_read_context ctx;
struct mail_index_strmap_rec *recs, *hash_rec;
- uint32_t prev_uid, str_idx, *recs_crc32, *renumber_map;
+ uint32_t prev_uid, str_idx, *recs_hash, *renumber_map;
unsigned int i, dest, count, count2;
int ret;
renumber_map = i_new(uint32_t, view->next_str_idx);
str_idx = 0; prev_uid = 0;
recs = array_get_modifiable(&view->recs, &count);
- recs_crc32 = array_get_modifiable(&view->recs_crc32, &count2);
+ recs_hash = array_get_modifiable(&view->recs_hash, &count2);
i_assert(count == count2);
for (i = dest = 0; i < count; ) {
renumber_map[recs[i].str_idx] = ++str_idx;
if (i != dest) {
recs[dest] = recs[i];
- recs_crc32[dest] = recs_crc32[i];
+ recs_hash[dest] = recs_hash[i];
}
i++; dest++;
}
i_assert(renumber_map[0] == 0);
array_delete(&view->recs, dest, i-dest);
- array_delete(&view->recs_crc32, dest, i-dest);
+ array_delete(&view->recs_hash, dest, i-dest);
mail_index_strmap_zero_terminate(view);
/* notify caller of the renumbering */
hash2_clear(view->hash);
for (i = 0; i < count; i++) {
recs[i].str_idx = renumber_map[recs[i].str_idx];
- hash_rec = hash2_insert_hash(view->hash, recs_crc32[i]);
+ hash_rec = hash2_insert_hash(view->hash, recs_hash[i]);
memcpy(hash_rec, &recs[i], sizeof(*hash_rec));
}
unsigned int i, uint32_t base_uid)
{
const struct mail_index_strmap_rec *recs;
- const uint32_t *crc32;
+ const uint32_t *hashes;
unsigned int j, n, count, count2, uid_rec_count;
uint32_t block_size;
uint8_t *p, packed[MAIL_INDEX_PACK_MAX_SIZE*2];
/* write records */
recs = array_get(&view->recs, &count);
- crc32 = array_get(&view->recs_crc32, &count2);
+ hashes = array_get(&view->recs_hash, &count2);
i_assert(count == count2);
while (i < count) {
/* @UNSAFE: <uid diff> */
}
view->total_ref_count += uid_rec_count;
- /* <n> <crc32>*count <str_idx>*count -
+ /* <n> <hash>*count <str_idx>*count -
FIXME: thread index specific code */
i_assert(recs[i].ref_index == 0);
if (uid_rec_count == 1) {
mail_index_pack_num(&p, n);
o_stream_nsend(output, packed, p-packed);
for (j = 0; j < uid_rec_count; j++)
- o_stream_nsend(output, &crc32[i+j], sizeof(crc32[i+j]));
+ o_stream_nsend(output, &hashes[i+j], sizeof(hashes[i+j]));
for (j = 0; j < uid_rec_count; j++) {
i_assert(j < 2 || recs[i+j].ref_index == j+1);
o_stream_nsend(output, &recs[i+j].str_idx,
const struct mail_index_strmap_rec *old_recs;
unsigned int i, old_count;
struct ostream *output;
- uint32_t crc32, next_uid;
+ uint32_t hash, next_uid;
bool full_block;
int ret;
full_block = TRUE; ret = 0;
while (i < old_count &&
(ret = strmap_read_block_init(view, &ctx)) > 0) {
- while ((ret = strmap_read_block_next(&ctx, &crc32)) > 0) {
+ while ((ret = strmap_read_block_next(&ctx, &hash)) > 0) {
if (ctx.rec.uid != old_recs[i].uid ||
ctx.rec.str_idx != old_recs[i].str_idx) {
/* mismatch */