377
377
create_delta_index(const struct source_info *src,
378
378
struct delta_index *old,
379
struct delta_index **fresh,
380
int max_bytes_to_index)
379
struct delta_index **fresh)
382
381
unsigned int i, hsize, hmask, num_entries, prev_val, *hash_count;
383
unsigned int total_num_entries, stride, max_entries;
382
unsigned int total_num_entries;
384
383
const unsigned char *data, *buffer;
385
384
struct delta_index *index;
386
385
struct unpacked_index_entry *entry, **hash;
392
391
buffer = src->buf;
394
393
/* Determine index hash size. Note that indexing skips the
395
first byte so we subtract 1 to get the edge cases right.
397
stride = RABIN_WINDOW;
394
first byte to allow for optimizing the Rabin's polynomial
395
initialization in create_delta(). */
398
396
num_entries = (src->size - 1) / RABIN_WINDOW;
399
if (max_bytes_to_index > 0) {
400
max_entries = (unsigned int) (max_bytes_to_index / RABIN_WINDOW);
401
if (num_entries > max_entries) {
402
/* Limit the max number of matching entries. This reduces the 'best'
403
* possible match, but means we don't consume all of ram.
405
num_entries = max_entries;
406
stride = (src->size - 1) / num_entries;
410
398
total_num_entries = num_entries + old->num_entries;
441
429
/* then populate the index for the new data */
443
for (data = buffer + num_entries * stride - RABIN_WINDOW;
431
for (data = buffer + num_entries * RABIN_WINDOW - RABIN_WINDOW;
433
data -= RABIN_WINDOW) {
446
434
unsigned int val = 0;
447
435
for (i = 1; i <= RABIN_WINDOW; i++)
448
436
val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT];
488
476
unsigned int hsize)
490
478
unsigned int hash_offset, hmask, memsize;
491
struct index_entry *entry;
479
struct index_entry *entry, *last_entry;
492
480
struct index_entry_linked_list *out_entry, **hash;
508
496
/* We know that entries are in the order we want in the output, but they
509
497
* aren't "grouped" by hash bucket yet.
499
last_entry = entries + num_entries;
511
500
for (entry = entries + num_entries - 1; entry >= entries; --entry) {
512
501
hash_offset = entry->val & hmask;
513
502
out_entry->p_entry = entry;
532
521
unsigned int i, j, hsize, hmask, total_num_entries;
533
522
struct delta_index *index;
534
523
struct index_entry *entry, *packed_entry, **packed_hash;
535
struct index_entry null_entry = {0};
524
struct index_entry *last_entry, null_entry = {0};
537
526
unsigned long memsize;
538
527
struct index_entry_linked_list *unpacked_entry, **mini_hash;
1115
1100
return DELTA_OK;
1120
get_entry_summary(const struct delta_index *index, int pos,
1121
unsigned int *text_offset, unsigned int *hash_val)
1124
const struct index_entry *entry;
1125
const struct index_entry *start_of_entries;
1126
unsigned int offset;
1127
if (pos < 0 || text_offset == NULL || hash_val == NULL
1132
hsize = index->hash_mask + 1;
1133
start_of_entries = (struct index_entry *)(((struct index_entry **)index->hash) + (hsize + 1));
1134
entry = start_of_entries + pos;
1135
if (entry > index->last_entry) {
1138
if (entry->ptr == NULL) {
1142
offset = entry->src->agg_offset;
1143
offset += (entry->ptr - ((unsigned char *)entry->src->buf));
1144
*text_offset = offset;
1145
*hash_val = entry->val;
1152
get_hash_offset(const struct delta_index *index, int pos,
1153
unsigned int *entry_offset)
1156
const struct index_entry *entry;
1157
const struct index_entry *start_of_entries;
1158
if (pos < 0 || index == NULL || entry_offset == NULL)
1162
hsize = index->hash_mask + 1;
1163
start_of_entries = (struct index_entry *)(((struct index_entry **)index->hash) + (hsize + 1));
1167
entry = index->hash[pos];
1168
if (entry == NULL) {
1171
*entry_offset = (entry - start_of_entries);
1178
rabin_hash(const unsigned char *data)
1181
unsigned int val = 0;
1182
for (i = 0; i < RABIN_WINDOW; i++)
1183
val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT];
1187
1103
/* vim: et ts=4 sw=4 sts=4