Lines Matching defs:index

14                    Do a binary search over the index for an access point
22 // its entirety, and an index built with access points about every SPAN bytes
37 // To use the index, an offset in the uncompressed data is provided, for which
38 // the latest access point at or preceding that offset is located in the index.
39 // The input file is positioned to the specified location in the index, and if
51 // Another way to build an index would be to use inflateCopy(). That would not
55 // index in a file.
68 void deflate_index_free(struct deflate_index *index)
70 if (index != NULL) {
71 free(index->list);
72 free(index);
77 // list and return NULL. index->mode is temporarily the allocated number of
79 // index->mode is set to the mode of inflation.
80 static struct deflate_index *add_point(struct deflate_index *index, int bits,
84 if (index == NULL) {
86 index = malloc(sizeof(struct deflate_index));
87 if (index == NULL)
89 index->have = 0;
90 index->mode = 8;
91 index->list = malloc(sizeof(point_t) * index->mode);
92 if (index->list == NULL) {
93 free(index);
98 else if (index->have == index->mode) {
100 index->mode <<= 1;
101 point_t *next = realloc(index->list, sizeof(point_t) * index->mode);
103 deflate_index_free(index);
106 index->list = next;
110 point_t *next = (point_t *)(index->list) + index->have++;
111 if (index->have < 0) {
113 deflate_index_free(index);
124 // Return the index, which may have been newly allocated or destroyed.
125 return index;
147 struct deflate_index *index = NULL; // list of access points
182 if (mode == RAW && index == NULL)
195 (index == NULL || totout - last >= span)) {
201 index = add_point(index, strm.data_type & 7, totin - strm.avail_in,
203 if (index == NULL) {
223 // An error was encountered. Discard the index and return a negative
225 deflate_index_free(index);
229 // Shrink the index to only the occupied access points and return it.
230 index->mode = mode;
231 index->length = totout;
232 point_t *list = realloc(index->list, sizeof(point_t) * index->have);
236 deflate_index_free(index);
239 index->list = list;
240 *built = index;
241 return index->have;
334 ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index,
337 // Do a quick sanity check on the index.
338 if (index == NULL || index->have < 1 || index->list[0].out != 0)
342 if (len == 0 || offset < 0 || offset >= index->length)
346 int lo = -1, hi = index->have;
347 point_t *point = index->list;
411 if (ret == Z_STREAM_END && index->mode == GZIP) {
495 // Build index.
496 struct deflate_index *index = NULL;
497 int len = deflate_index_build(in, SPAN, &index);
514 fprintf(stderr, "zran: error %d while building index\n", len);
518 fprintf(stderr, "zran: built index with %d access points\n", len);
520 // Use index by reading some bytes from an arbitrary offset.
523 offset = ((index->length + 1) << 1) / 3;
524 ptrdiff_t got = deflate_index_extract(in, index, offset, buf, LEN);
534 deflate_index_free(index);