378
377
create_delta_index(const struct source_info *src,
379
378
struct delta_index *old,
380
struct delta_index **fresh)
379
struct delta_index **fresh,
382
382
unsigned int i, hsize, hmask, num_entries, prev_val, *hash_count;
383
383
unsigned int total_num_entries, stride;
392
392
buffer = src->buf;
394
394
/* Determine index hash size. Note that indexing skips the
395
first byte to allow for optimizing the Rabin's polynomial
396
initialization in create_delta(). */
395
first byte so we subtract 1 to get the edge cases right.
397
397
stride = RABIN_WINDOW;
398
398
num_entries = (src->size - 1) / RABIN_WINDOW;
399
if (num_entries > MAX_NUM_ENTRIES) {
399
if (max_entries > 0 && num_entries > max_entries) {
400
400
/* Limit the max number of matching entries. This reduces the 'best'
401
401
* possible match, but means we don't consume all of ram.
403
// fprintf(stderr, "limiting num_entries to %d\n", MAX_NUM_ENTRIES);
404
num_entries = MAX_NUM_ENTRIES;
405
stride = (src->size) / num_entries;
403
num_entries = max_entries;
404
stride = (src->size - 1) / num_entries;
408
407
total_num_entries = num_entries + old->num_entries;
486
485
unsigned int hsize)
488
487
unsigned int hash_offset, hmask, memsize;
489
struct index_entry *entry, *last_entry;
488
struct index_entry *entry;
490
489
struct index_entry_linked_list *out_entry, **hash;
506
505
/* We know that entries are in the order we want in the output, but they
507
506
* aren't "grouped" by hash bucket yet.
509
last_entry = entries + num_entries;
510
508
for (entry = entries + num_entries - 1; entry >= entries; --entry) {
511
509
hash_offset = entry->val & hmask;
512
510
out_entry->p_entry = entry;
531
529
unsigned int i, j, hsize, hmask, total_num_entries;
532
530
struct delta_index *index;
533
531
struct index_entry *entry, *packed_entry, **packed_hash;
534
struct index_entry *last_entry, null_entry = {0};
532
struct index_entry null_entry = {0};
536
534
unsigned long memsize;
537
535
struct index_entry_linked_list *unpacked_entry, **mini_hash;
1110
1107
return DELTA_OK;
1112
get_entry_summary(const struct delta_index *index, int pos,
1113
unsigned int *text_offset, unsigned int *hash_val)
1116
const struct index_entry *entry;
1117
const struct index_entry *start_of_entries;
1118
unsigned int offset;
1119
if (pos < 0 || text_offset == NULL || hash_val == NULL
1124
hsize = index->hash_mask + 1;
1125
start_of_entries = (struct index_entry *)(((struct index_entry **)index->hash) + (hsize + 1));
1126
entry = start_of_entries + pos;
1127
if (entry > index->last_entry) {
1130
if (entry->ptr == NULL) {
1134
offset = entry->src->agg_offset;
1135
offset += (entry->ptr - ((unsigned char *)entry->src->buf));
1136
*text_offset = offset;
1137
*hash_val = entry->val;
1144
get_hash_offset(const struct delta_index *index, int pos,
1145
unsigned int *entry_offset)
1148
const struct index_entry *entry;
1149
const struct index_entry *start_of_entries;
1150
if (pos < 0 || index == NULL || entry_offset == NULL)
1154
hsize = index->hash_mask + 1;
1155
start_of_entries = (struct index_entry *)(((struct index_entry **)index->hash) + (hsize + 1));
1159
entry = index->hash[pos];
1160
if (entry == NULL) {
1163
*entry_offset = (entry - start_of_entries);
1170
rabin_hash(const unsigned char *data)
1173
unsigned int val = 0;
1174
for (i = 0; i < RABIN_WINDOW; i++)
1175
val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT];
1113
1179
/* vim: et ts=4 sw=4 sts=4