275
create_index_from_old_and_hash(const struct delta_index *old,
276
struct unpacked_index_entry **hash,
278
unsigned int num_entries)
280
unsigned int i, memsize, total_num_entries;
281
struct unpacked_index_entry *entry;
282
struct delta_index *index;
283
struct index_entry *packed_entry, **packed_hash, *old_entry;
287
* Now create the packed index in array form
288
* rather than linked lists.
290
total_num_entries = num_entries + old->num_entries;
291
memsize = sizeof(*index)
292
+ sizeof(*packed_hash) * (hsize+1)
293
+ sizeof(*packed_entry) * total_num_entries;
294
mem = malloc(memsize);
300
index->memsize = memsize;
301
index->hash_mask = hsize - 1;
302
index->num_entries = total_num_entries;
306
mem = packed_hash + (hsize+1);
309
fprintf(stderr, "copying %d entries, adding %d\n",
310
old->num_entries, num_entries);
312
for (i = 0; i < hsize; i++) {
314
* Coalesce all entries belonging to one linked list
315
* into consecutive array entries.
316
* The entries in old all come before the entries in hash.
318
packed_hash[i] = packed_entry;
319
old_entry = old->hash[i];
320
to_copy = (old->hash[i+1] - old_entry);
322
memcpy(packed_entry, old_entry, to_copy * sizeof(struct index_entry));
323
packed_entry += to_copy;
325
for (entry = hash[i]; entry; entry = entry->next)
326
*packed_entry++ = entry->entry;
329
/* Sentinel value to indicate the length of the last hash bucket */
330
packed_hash[hsize] = packed_entry;
332
assert(packed_entry - (struct index_entry *)mem == total_num_entries);
333
index->last_entry = (packed_entry - 1);
274
338
struct delta_index * create_delta_index(const struct source_info *src,
275
339
const struct delta_index *old)
494
557
free(hash_count);
560
if (num_entries == 0) {
561
/** Nothing to index **/
497
564
if (old != NULL) {
498
total_num_entries = num_entries + old->num_entries;
499
include_entries_from_index(hash, hash_count, hsize, entry, old);
565
if (hmask == old->hash_mask) {
566
/* The total hash table size didn't change, which means that
567
* entries will end up in the same pages. We can do bulk-copying to
568
* get the final output
570
index = create_index_from_old_and_hash(old, hash, hsize,
577
index->last_src = src;
580
total_num_entries = num_entries + old->num_entries;
581
include_entries_from_index(hash, hash_count, hsize, entry, old);
501
584
total_num_entries = num_entries;