/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to diff-delta.c

  • Committer: John Arbash Meinel
  • Date: 2009-03-03 18:10:57 UTC
  • mto: (0.17.31 trunk)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090303181057-i1239vipqi27fxbs
Remove the multi-index handling now that we have index combining instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
 
126
126
struct delta_index {
127
127
        unsigned long memsize; /* Total bytes pointed to by this index */
128
 
        struct source_info *src; /* Information about the referenced source */
 
128
        const struct source_info *last_src; /* Information about the referenced source */
129
129
        unsigned int hash_mask; /* val & hash_mask gives the hash index for a given
130
130
                                                           entry */
131
131
        unsigned int num_entries; /* The total number of entries in this index */
348
348
                                                                                   total_num_entries);
349
349
        free(hash_count);
350
350
        index = pack_delta_index(hash, hsize, total_num_entries);
351
 
        index->src = src;
 
351
        index->last_src = src;
352
352
        free(hash);
353
353
        if (!index) {
354
354
                return NULL;
376
376
#define MAX_OP_SIZE     (5 + 5 + 1 + RABIN_WINDOW + 7)
377
377
 
378
378
void *
379
 
create_delta(struct delta_index **indexes,
380
 
                         unsigned int num_indexes,
 
379
create_delta(const struct delta_index *index,
381
380
                         const void *trg_buf, unsigned long trg_size,
382
381
                         unsigned long *delta_size, unsigned long max_size)
383
382
{
384
 
        unsigned int i, j, outpos, outsize, moff, msize, val;
385
 
        const struct delta_index *index;
 
383
        unsigned int i, outpos, outsize, moff, msize, val;
386
384
        const struct source_info *msource;
387
385
        int inscnt;
388
386
        const unsigned char *ref_data, *ref_top, *data, *top;
391
389
 
392
390
        if (!trg_buf || !trg_size)
393
391
                return NULL;
394
 
        if (num_indexes == 0)
 
392
        if (index == NULL)
395
393
                return NULL;
396
394
 
397
395
        outpos = 0;
403
401
                return NULL;
404
402
 
405
403
        /* store reference buffer size */
406
 
        i = 0;
407
 
        index = indexes[0];
408
 
        for (j = 0; j < num_indexes; ++j) {
409
 
                index = indexes[j];
410
 
                i += index->src->size;
411
 
        }
412
 
        assert(i <= index->src->size + index->src->agg_offset);
413
 
        i = index->src->size + index->src->agg_offset;
414
 
        source_size = i;
 
404
        source_size = index->last_src->size + index->last_src->agg_offset;
 
405
        i = source_size;
415
406
        while (i >= 0x80) {
416
407
                out[outpos++] = i | 0x80;
417
408
                i >>= 7;
456
447
                        /* Shift the window by one byte. */
457
448
                        val ^= U[data[-RABIN_WINDOW]];
458
449
                        val = ((val << 8) | *data) ^ T[val >> RABIN_SHIFT];
459
 
                        for (j = 0; j < num_indexes; ++j) {
460
 
                                index = indexes[j];
461
 
                                i = val & index->hash_mask;
462
 
                                /* TODO: When using multiple indexes like this, the hash tables
463
 
                                 *               mapping val => index_entry become less efficient.
464
 
                                 *               You end up getting a lot more collisions in the hash,
465
 
                                 *               which doesn't actually lead to a entry->val match.
 
450
                        i = val & index->hash_mask;
 
451
                        /* TODO: When using multiple indexes like this, the hash tables
 
452
                         *               mapping val => index_entry become less efficient.
 
453
                         *               You end up getting a lot more collisions in the hash,
 
454
                         *               which doesn't actually lead to a entry->val match.
 
455
                         */
 
456
                        for (entry = index->hash[i]; entry < index->hash[i+1];
 
457
                                 entry++) {
 
458
                                const unsigned char *ref;
 
459
                                const unsigned char *src;
 
460
                                unsigned int ref_size;
 
461
                                if (entry->val != val)
 
462
                                        continue;
 
463
                                ref = entry->ptr;
 
464
                                src = data;
 
465
                                ref_data = entry->src->buf;
 
466
                                ref_top = ref_data + entry->src->size;
 
467
                                ref_size = ref_top - ref;
 
468
                                /* ref_size is the longest possible match that we could make
 
469
                                 * here. If ref_size <= msize, then we know that we cannot
 
470
                                 * match more bytes with this location that we have already
 
471
                                 * matched.
466
472
                                 */
467
 
                                for (entry = index->hash[i]; entry < index->hash[i+1];
468
 
                                         entry++) {
469
 
                                        const unsigned char *ref;
470
 
                                        const unsigned char *src;
471
 
                                        unsigned int ref_size;
472
 
                                        if (entry->val != val)
473
 
                                                continue;
474
 
                                        ref = entry->ptr;
475
 
                                        src = data;
476
 
                                        ref_data = entry->src->buf;
477
 
                                        ref_top = ref_data + entry->src->size;
478
 
                                        ref_size = ref_top - ref;
479
 
                                        /* ref_size is the longest possible match that we could make
480
 
                                         * here. If ref_size <= msize, then we know that we cannot
481
 
                                         * match more bytes with this location that we have already
482
 
                                         * matched.
483
 
                                         */
484
 
                                        if (ref_size > top - src)
485
 
                                                ref_size = top - src;
486
 
                                        if (ref_size <= msize)
 
473
                                if (ref_size > top - src)
 
474
                                        ref_size = top - src;
 
475
                                if (ref_size <= msize)
 
476
                                        break;
 
477
                                /* See how many bytes actually match at this location. */
 
478
                                while (ref_size-- && *src++ == *ref)
 
479
                                        ref++;
 
480
                                if (msize < ref - entry->ptr) {
 
481
                                        /* this is our best match so far */
 
482
                                        msize = ref - entry->ptr;
 
483
                                        msource = entry->src;
 
484
                                        moff = entry->ptr - ref_data;
 
485
                                        if (msize >= 4096) /* good enough */
487
486
                                                break;
488
 
                                        /* See how many bytes actually match at this location. */
489
 
                                        while (ref_size-- && *src++ == *ref)
490
 
                                                ref++;
491
 
                                        if (msize < ref - entry->ptr) {
492
 
                                                /* this is our best match so far */
493
 
                                                msize = ref - entry->ptr;
494
 
                                                msource = entry->src;
495
 
                                                moff = entry->ptr - ref_data;
496
 
                                                if (msize >= 4096) /* good enough */
497
 
                                                        break;
498
 
                                        }
499
487
                                }
500
488
                        }
501
489
                }