~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/delta.h

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
                                 aggregate source */
22
22
};
23
23
 
 
24
/* result type for functions that have multiple failure modes */
 
25
typedef enum {
 
26
    DELTA_OK,             /* Success */
 
27
    DELTA_OUT_OF_MEMORY,  /* Could not allocate required memory */
 
28
    DELTA_INDEX_NEEDED,   /* A delta_index must be passed */
 
29
    DELTA_SOURCE_EMPTY,   /* A source_info had no content */
 
30
    DELTA_SOURCE_BAD,     /* A source_info had invalid or corrupt content */
 
31
    DELTA_BUFFER_EMPTY,   /* A buffer pointer and size */
 
32
    DELTA_SIZE_TOO_BIG,   /* Delta data is larger than the max requested */
 
33
} delta_result;
 
34
 
 
35
 
24
36
/*
25
37
 * create_delta_index: compute index data from given buffer
26
38
 *
27
 
 * This returns a pointer to a struct delta_index that should be passed to
28
 
 * subsequent create_delta() calls, or to free_delta_index().  A NULL pointer
29
 
 * is returned on failure.  The given buffer must not be freed nor altered
30
 
 * before free_delta_index() is called.  The returned pointer must be freed
31
 
 * using free_delta_index().
 
39
 * Returns a delta_result status, when DELTA_OK then *fresh is set to a struct
 
40
 * delta_index that should be passed to subsequent create_delta() calls, or to
 
41
 * free_delta_index().  Other values are a failure, and *fresh is unset.
 
42
 * The given buffer must not be freed nor altered before free_delta_index() is
 
43
 * called. The resultant struct must be freed using free_delta_index().
 
44
 *
 
45
 * :param max_bytes_to_index: Limit the number of regions to sample to this
 
46
 *      amount of text. We will store at most max_bytes_to_index / RABIN_WINDOW
 
47
 *      pointers into the source text.  Useful if src can be unbounded in size,
 
48
 *      and you are willing to trade match accuracy for peak memory.
32
49
 */
33
 
extern struct delta_index *
 
50
extern delta_result
34
51
create_delta_index(const struct source_info *src,
35
 
                   struct delta_index *old);
 
52
                   struct delta_index *old,
 
53
                   struct delta_index **fresh,
 
54
                   int max_bytes_to_index);
36
55
 
37
56
 
38
57
/*
39
58
 * create_delta_index_from_delta: compute index data from given buffer
40
59
 *
41
 
 * This returns a pointer to a struct delta_index that should be passed to
42
 
 * subsequent create_delta() calls, or to free_delta_index().  A NULL pointer
43
 
 * is returned on failure.
 
60
 * Returns a delta_result status, when DELTA_OK then *fresh is set to a struct
 
61
 * delta_index that should be passed to subsequent create_delta() calls, or to
 
62
 * free_delta_index().  Other values are a failure, and *fresh is unset.
44
63
 * The bytes must be in the form of a delta structure, as generated by
45
64
 * create_delta(). The generated index will only index the insert bytes, and
46
65
 * not any of the control structures.
47
66
 */
48
 
extern struct delta_index *
 
67
extern delta_result
49
68
create_delta_index_from_delta(const struct source_info *delta,
50
 
                              struct delta_index *old);
 
69
                              struct delta_index *old,
 
70
                              struct delta_index **fresh);
51
71
/*
52
72
 * free_delta_index: free the index created by create_delta_index()
53
73
 *
67
87
 *
68
88
 * This function may be called multiple times with different buffers using
69
89
 * the same delta_index pointer.  If max_delta_size is non-zero and the
70
 
 * resulting delta is to be larger than max_delta_size then NULL is returned.
71
 
 * On success, a non-NULL pointer to the buffer with the delta data is
72
 
 * returned and *delta_size is updated with its size.  The returned buffer
73
 
 * must be freed by the caller.
 
90
 * resulting delta is to be larger than max_delta_size then DELTA_SIZE_TOO_BIG
 
91
 * is returned.  Otherwise on success, DELTA_OK is returned and *delta_data is
 
92
 * set to a new buffer with the delta data and *delta_size is updated with its
 
93
 * size.  That buffer must be freed by the caller.
74
94
 */
75
 
extern void *
 
95
extern delta_result
76
96
create_delta(const struct delta_index *index,
77
 
         const void *buf, unsigned long bufsize,
78
 
         unsigned long *delta_size, unsigned long max_delta_size);
 
97
             const void *buf, unsigned long bufsize,
 
98
             unsigned long *delta_size, unsigned long max_delta_size,
 
99
             void **delta_data);
79
100
 
80
101
/* the smallest possible delta size is 3 bytes
81
102
 * Target size, Copy command, Copy length
102
123
    return size;
103
124
}
104
125
 
 
126
/*
 
127
 * Return the basic information about a given delta index.
 
128
 * :param index: The delta_index object
 
129
 * :param pos: The offset in the entry list. Start at 0, and walk until you get
 
130
 *      0 as a return code.
 
131
 * :param global_offset: return value, distance to the beginning of all sources
 
132
 * :param hash_val: return value, the RABIN hash associated with this pointer
 
133
 * :param hash_offset: Location for this entry in the hash array.
 
134
 * :return: 1 if pos != -1 (there was data produced)
 
135
 */
 
136
extern int
 
137
get_entry_summary(const struct delta_index *index, int pos,
 
138
                  unsigned int *text_offset, unsigned int *hash_val);
 
139
 
 
140
/*
 
141
 * Determine what entry index->hash[X] points to.
 
142
 */
 
143
extern int
 
144
get_hash_offset(const struct delta_index *index, int pos,
 
145
                unsigned int *entry_offset);
 
146
 
 
147
/*
 
148
 * Compute the rabin_hash of the given data, it is assumed the data is at least
 
149
 * RABIN_WINDOW wide (16 bytes).
 
150
 */
 
151
extern unsigned int
 
152
rabin_hash(const unsigned char *data);
 
153
 
105
154
#endif