220
220
unsigned int i, j, hmask, memsize, fit_in_old, copied_count;
221
221
struct unpacked_index_entry *entry;
222
222
struct delta_index *index;
223
struct index_entry *packed_entry, **packed_hash, *old_entry;
223
struct index_entry *packed_entry, **packed_hash, *old_entry, *copy_from;
224
224
struct index_entry null_entry = {0};
334
334
* old_index->hash_mask? Would it make any real difference?
336
336
j = i & old_index->hash_mask;
337
copy_from = old_index->hash[j];
337
338
for (old_entry = old_index->hash[j];
338
339
old_entry < old_index->hash[j + 1] && old_entry->ptr != NULL;
376
377
create_delta_index(const struct source_info *src,
377
378
struct delta_index *old,
378
struct delta_index **fresh,
379
int max_bytes_to_index)
379
struct delta_index **fresh)
381
381
unsigned int i, hsize, hmask, num_entries, prev_val, *hash_count;
382
unsigned int total_num_entries, stride, max_entries;
382
unsigned int total_num_entries;
383
383
const unsigned char *data, *buffer;
384
384
struct delta_index *index;
385
385
struct unpacked_index_entry *entry, **hash;
391
391
buffer = src->buf;
393
393
/* Determine index hash size. Note that indexing skips the
394
first byte so we subtract 1 to get the edge cases right.
396
stride = RABIN_WINDOW;
394
first byte to allow for optimizing the Rabin's polynomial
395
initialization in create_delta(). */
397
396
num_entries = (src->size - 1) / RABIN_WINDOW;
398
if (max_bytes_to_index > 0) {
399
max_entries = (unsigned int) (max_bytes_to_index / RABIN_WINDOW);
400
if (num_entries > max_entries) {
401
/* Limit the max number of matching entries. This reduces the 'best'
402
* possible match, but means we don't consume all of ram.
404
num_entries = max_entries;
405
stride = (src->size - 1) / num_entries;
409
398
total_num_entries = num_entries + old->num_entries;
440
429
/* then populate the index for the new data */
442
for (data = buffer + num_entries * stride - RABIN_WINDOW;
431
for (data = buffer + num_entries * RABIN_WINDOW - RABIN_WINDOW;
433
data -= RABIN_WINDOW) {
445
434
unsigned int val = 0;
446
435
for (i = 1; i <= RABIN_WINDOW; i++)
447
436
val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT];
487
476
unsigned int hsize)
489
478
unsigned int hash_offset, hmask, memsize;
490
struct index_entry *entry;
479
struct index_entry *entry, *last_entry;
491
480
struct index_entry_linked_list *out_entry, **hash;
507
496
/* We know that entries are in the order we want in the output, but they
508
497
* aren't "grouped" by hash bucket yet.
499
last_entry = entries + num_entries;
510
500
for (entry = entries + num_entries - 1; entry >= entries; --entry) {
511
501
hash_offset = entry->val & hmask;
512
502
out_entry->p_entry = entry;
531
521
unsigned int i, j, hsize, hmask, total_num_entries;
532
522
struct delta_index *index;
533
523
struct index_entry *entry, *packed_entry, **packed_hash;
534
struct index_entry null_entry = {0};
524
struct index_entry *last_entry, null_entry = {0};
536
526
unsigned long memsize;
537
527
struct index_entry_linked_list *unpacked_entry, **mini_hash;
905
891
const unsigned char *ref_data, *ref_top, *data, *top;
906
892
unsigned char *out;
893
unsigned long source_size;
908
895
if (!trg_buf || !trg_size)
909
896
return DELTA_BUFFER_EMPTY;
1050
1039
assert(moff < msource->size);
1051
1040
moff += msource->agg_offset;
1053
<= index->last_src->size + index->last_src->agg_offset);
1041
assert(moff + msize <= source_size);
1054
1042
if (moff & 0x000000ff)
1055
1043
out[outpos++] = moff >> 0, i |= 0x01;
1056
1044
if (moff & 0x0000ff00)
1112
1100
return DELTA_OK;
1117
get_entry_summary(const struct delta_index *index, int pos,
1118
unsigned int *text_offset, unsigned int *hash_val)
1121
const struct index_entry *entry;
1122
const struct index_entry *start_of_entries;
1123
unsigned int offset;
1124
if (pos < 0 || text_offset == NULL || hash_val == NULL
1129
hsize = index->hash_mask + 1;
1130
start_of_entries = (struct index_entry *)(((struct index_entry **)index->hash) + (hsize + 1));
1131
entry = start_of_entries + pos;
1132
if (entry > index->last_entry) {
1135
if (entry->ptr == NULL) {
1139
offset = entry->src->agg_offset;
1140
offset += (entry->ptr - ((unsigned char *)entry->src->buf));
1141
*text_offset = offset;
1142
*hash_val = entry->val;
1149
get_hash_offset(const struct delta_index *index, int pos,
1150
unsigned int *entry_offset)
1153
const struct index_entry *entry;
1154
const struct index_entry *start_of_entries;
1155
if (pos < 0 || index == NULL || entry_offset == NULL)
1159
hsize = index->hash_mask + 1;
1160
start_of_entries = (struct index_entry *)(((struct index_entry **)index->hash) + (hsize + 1));
1164
entry = index->hash[pos];
1165
if (entry == NULL) {
1168
*entry_offset = (entry - start_of_entries);
1175
rabin_hash(const unsigned char *data)
1178
unsigned int val = 0;
1179
for (i = 0; i < RABIN_WINDOW; i++)
1180
val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT];
1184
1103
/* vim: et ts=4 sw=4 sts=4