212
212
pack_delta_index(struct unpacked_index_entry **hash, unsigned int hsize,
213
213
unsigned int num_entries, struct delta_index *old_index)
215
unsigned int i, j, hmask, memsize, to_copy, fit_in_old, copied_count;
215
unsigned int i, j, hmask, memsize, fit_in_old, copied_count;
216
216
struct unpacked_index_entry *entry;
217
217
struct delta_index *index;
218
218
struct index_entry *packed_entry, **packed_hash, *old_entry, *copy_from;
275
275
if (fit_in_old) {
276
276
fprintf(stderr, "Fit all %d entries into old index\n",
278
/* No need to allocate a new buffer */
280
281
fprintf(stderr, "Fit only %d entries into old index,"
323
324
j = i & old_index->hash_mask;
324
325
copy_from = old_index->hash[j];
326
326
for (old_entry = old_index->hash[j];
327
327
old_entry < old_index->hash[j + 1] && old_entry->ptr != NULL;
329
329
if ((old_entry->val & hmask) == i) {
332
/* We reached the end of a string of entries that should
333
* be copied. Copy the group, and then move the pointers.
336
memcpy(packed_entry, copy_from,
337
sizeof(*old_entry)*to_copy);
338
packed_entry += to_copy;
341
/* Don't copy *this* entry, and start the copy after this */
342
copy_from = old_entry + 1;
330
*packed_entry++ = *old_entry;
346
memcpy(packed_entry, copy_from,
347
sizeof(*old_entry)*to_copy);
348
packed_entry += to_copy;
352
334
for (entry = hash[i]; entry; entry = entry->next) {
353
335
*packed_entry++ = entry->entry;
337
/* TODO: At this point packed_entry - packed_hash[i] is the number of
338
* records that we have inserted into this hash bucket.
339
* We should *really* consider doing some limiting along the
340
* lines of limit_hash_buckets() to avoid pathological behavior.
355
342
/* Now add extra 'NULL' entries that we can use for future expansion. */
356
343
for (j = 0; j < EXTRA_NULLS; ++j ) {
357
344
*packed_entry++ = null_entry;