Handling of Index. More...
#include "index.h"
Data Structures | |
struct | lzma_index_group_s |
struct | lzma_index_s |
Defines | |
#define | INDEX_GROUP_SIZE 256 |
Number of Records to allocate at once in the unrolled list. | |
Typedefs | |
typedef struct lzma_index_group_s | lzma_index_group |
Functions | |
lzma_vli | lzma_index_memusage (lzma_vli count) |
Calculate memory usage for Index with given number of Records. | |
static void | free_index_list (lzma_index *i, lzma_allocator *allocator) |
lzma_index * | lzma_index_init (lzma_index *i, lzma_allocator *allocator) |
Allocate and initialize a new lzma_index structure. | |
void | lzma_index_end (lzma_index *i, lzma_allocator *allocator) |
Deallocate the Index. | |
lzma_vli | lzma_index_count (const lzma_index *i) |
Get the number of Records. | |
lzma_vli | lzma_index_size (const lzma_index *i) |
Get the size of the Index field as bytes. | |
lzma_vli | lzma_index_total_size (const lzma_index *i) |
Get the total size of the Blocks. | |
lzma_vli | lzma_index_stream_size (const lzma_index *i) |
Get the total size of the Stream. | |
lzma_vli | lzma_index_file_size (const lzma_index *i) |
Get the total size of the file. | |
lzma_vli | lzma_index_uncompressed_size (const lzma_index *i) |
Get the uncompressed size of the Stream. | |
uint32_t | lzma_index_padding_size (const lzma_index *i) |
static lzma_ret | index_append_real (lzma_index *i, lzma_allocator *allocator, lzma_vli unpadded_size, lzma_vli uncompressed_size, bool is_padding) |
lzma_ret | lzma_index_append (lzma_index *i, lzma_allocator *allocator, lzma_vli unpadded_size, lzma_vli uncompressed_size) |
Add a new Record to an Index. | |
static bool | init_current (lzma_index *i) |
Initialize i->current to point to the first Record. | |
static void | previous_group (lzma_index *i) |
Go backward to the previous group. | |
static void | next_group (lzma_index *i) |
Go forward to the next group. | |
static void | set_info (const lzma_index *i, lzma_index_record *info) |
Set *info from i->current. | |
lzma_bool | lzma_index_read (lzma_index *i, lzma_index_record *info) |
Get the next Record from the Index. | |
void | lzma_index_rewind (lzma_index *i) |
Rewind the Index. | |
lzma_bool | lzma_index_locate (lzma_index *i, lzma_index_record *info, lzma_vli target) |
Locate a Record. | |
lzma_ret | lzma_index_cat (lzma_index *restrict dest, lzma_index *restrict src, lzma_allocator *allocator, lzma_vli padding) |
lzma_index * | lzma_index_dup (const lzma_index *src, lzma_allocator *allocator) |
Duplicate an Index list. | |
lzma_bool | lzma_index_equal (const lzma_index *a, const lzma_index *b) |
Compare if two Index lists are identical. |
Handling of Index.
#define INDEX_GROUP_SIZE 256 |
Number of Records to allocate at once in the unrolled list.
Referenced by index_append_real(), and lzma_index_memusage().
Calculate memory usage for Index with given number of Records.
On disk, the size of the Index field depends on both the number of Records stored and how big values the Records store (due to variable-length integer encoding). When the Index is kept in lzma_index structure, the memory usage depends only on the number of Records stored in the Index. The size in RAM is almost always a lot bigger than in encoded form on disk.
This function calculates an approximate amount of memory needed hold the given number of Records in lzma_index structure. This value may vary between liblzma versions if the internal implementation is modified.
If you want to know how much memory an existing lzma_index structure is using, use lzma_index_memusage(lzma_index_count(i)).
References INDEX_GROUP_SIZE, and LZMA_VLI_MAX.
Referenced by lzma_index_buffer_decode().
lzma_index* lzma_index_init | ( | lzma_index * | i, | |
lzma_allocator * | allocator | |||
) |
Allocate and initialize a new lzma_index structure.
If i is NULL, a new lzma_index structure is allocated, initialized, and a pointer to it returned. If allocation fails, NULL is returned.
If i is non-NULL, it is reinitialized and the same pointer returned. In this case, return value cannot be NULL or a different pointer than the i that was given as an argument.
References lzma_alloc().
Referenced by lzma_stream_buffer_encode().
void lzma_index_end | ( | lzma_index * | i, | |
lzma_allocator * | allocator | |||
) |
Deallocate the Index.
If i is NULL, this does nothing.
Referenced by lzma_index_buffer_decode(), lzma_index_dup(), and lzma_stream_buffer_encode().
lzma_vli lzma_index_count | ( | const lzma_index * | i | ) |
Get the number of Records.
lzma_vli lzma_index_size | ( | const lzma_index * | i | ) |
Get the size of the Index field as bytes.
This is needed to verify the Backward Size field in the Stream Footer.
Referenced by lzma_index_append(), lzma_index_buffer_encode(), and lzma_stream_buffer_encode().
lzma_vli lzma_index_total_size | ( | const lzma_index * | i | ) |
Get the total size of the Blocks.
This doesn't include the Stream Header, Stream Footer, Stream Padding, or Index fields.
lzma_vli lzma_index_stream_size | ( | const lzma_index * | i | ) |
Get the total size of the Stream.
If multiple Indexes have been combined, this works as if the Blocks were in a single Stream.
References LZMA_STREAM_HEADER_SIZE.
lzma_vli lzma_index_file_size | ( | const lzma_index * | i | ) |
Get the total size of the file.
When no Indexes have been combined with lzma_index_cat(), this function is identical to lzma_index_stream_size(). If multiple Indexes have been combined, this includes also the headers of each separate Stream and the possible Stream Padding fields.
References LZMA_STREAM_HEADER_SIZE.
Referenced by lzma_index_append().
lzma_vli lzma_index_uncompressed_size | ( | const lzma_index * | i | ) |
Get the uncompressed size of the Stream.
uint32_t lzma_index_padding_size | ( | const lzma_index * | i | ) |
Get the size of the Index Padding field. This is needed by Index encoder and decoder, but applications should have no use for this.
References lzma_index_s::count, lzma_index_s::index_list_size, and LZMA_VLI_C.
static lzma_ret index_append_real | ( | lzma_index * | i, | |
lzma_allocator * | allocator, | |||
lzma_vli | unpadded_size, | |||
lzma_vli | uncompressed_size, | |||
bool | is_padding | |||
) | [static] |
Appends a new Record to the Index. If needed, this allocates a new Record group.
References lzma_index_s::head, INDEX_GROUP_SIZE, lzma_index_group_s::last, lzma_alloc(), LZMA_MEM_ERROR, LZMA_OK, lzma_index_group_s::next, lzma_index_group_s::paddings, lzma_index_group_s::prev, lzma_index_s::tail, lzma_index_group_s::uncompressed_sums, and lzma_index_group_s::unpadded_sums.
Referenced by lzma_index_append().
lzma_ret lzma_index_append | ( | lzma_index * | i, | |
lzma_allocator * | allocator, | |||
lzma_vli | unpadded_size, | |||
lzma_vli | uncompressed_size | |||
) |
Add a new Record to an Index.
i | Pointer to a lzma_index structure | |
allocator | Pointer to lzma_allocator, or NULL to use malloc() | |
unpadded_size | Unpadded Size of a Block. This can be calculated with lzma_block_unpadded_size() after encoding or decoding the Block. | |
uncompressed_size | Uncompressed Size of a Block. This can be taken directly from lzma_block structure after encoding or decoding the Block. |
Appending a new Record does not affect the read position.
References index_append_real(), LZMA_DATA_ERROR, lzma_index_file_size(), lzma_index_size(), LZMA_OK, LZMA_PROG_ERROR, LZMA_VLI_MAX, and lzma_vli_size().
Referenced by lzma_stream_buffer_encode().
static bool init_current | ( | lzma_index * | i | ) | [static] |
Initialize i->current to point to the first Record.
References lzma_index_s::count, lzma_index_s::current, lzma_index_s::group, lzma_index_s::head, LZMA_STREAM_HEADER_SIZE, lzma_index_s::record, lzma_index_s::stream_offset, and lzma_index_s::uncompressed_offset.
Referenced by lzma_index_locate(), and lzma_index_read().
static void previous_group | ( | lzma_index * | i | ) | [static] |
Go backward to the previous group.
References lzma_index_s::current, lzma_index_s::group, lzma_index_group_s::last, lzma_index_group_s::prev, lzma_index_s::record, lzma_index_s::stream_offset, lzma_index_s::uncompressed_offset, lzma_index_group_s::uncompressed_sums, and lzma_index_group_s::unpadded_sums.
Referenced by lzma_index_locate().
static void next_group | ( | lzma_index * | i | ) | [static] |
Go forward to the next group.
References lzma_index_s::current, lzma_index_s::group, lzma_index_group_s::last, lzma_index_group_s::next, lzma_index_s::record, lzma_index_s::stream_offset, lzma_index_s::uncompressed_offset, lzma_index_group_s::uncompressed_sums, and lzma_index_group_s::unpadded_sums.
Referenced by lzma_index_locate(), and lzma_index_read().
static void set_info | ( | const lzma_index * | i, | |
lzma_index_record * | info | |||
) | [static] |
Set *info from i->current.
References lzma_index_s::current, lzma_index_s::group, lzma_index_s::record, lzma_index_s::stream_offset, lzma_index_record::stream_offset, lzma_index_record::total_size, lzma_index_s::uncompressed_offset, lzma_index_record::uncompressed_offset, lzma_index_record::uncompressed_size, lzma_index_group_s::uncompressed_sums, lzma_index_record::unpadded_size, and lzma_index_group_s::unpadded_sums.
Referenced by lzma_index_locate(), and lzma_index_read().
lzma_bool lzma_index_read | ( | lzma_index * | i, | |
lzma_index_record * | info | |||
) |
Get the next Record from the Index.
References init_current(), next_group(), and set_info().
void lzma_index_rewind | ( | lzma_index * | i | ) |
Rewind the Index.
Rewind the Index so that next call to lzma_index_read() will return the first Record.
lzma_bool lzma_index_locate | ( | lzma_index * | i, | |
lzma_index_record * | record, | |||
lzma_vli | target | |||
) |
Locate a Record.
When the Index is available, it is possible to do random-access reading with granularity of Block size.
i | Pointer to lzma_index structure | |
record | Pointer to a structure to hold the search results | |
target | Uncompressed target offset which the caller would like to locate from the Stream |
If the target is smaller than the uncompressed size of the Stream (can be checked with lzma_index_uncompressed_size()):
If target is greater than the uncompressed size of the Stream, *record and the read position are not modified, and this function returns true.
References init_current(), next_group(), previous_group(), and set_info().
lzma_index* lzma_index_dup | ( | const lzma_index * | i, | |
lzma_allocator * | allocator | |||
) |
Duplicate an Index list.
Makes an identical copy of the Index. Also the read position is copied.
References lzma_index_s::current, lzma_index_s::group, lzma_index_s::head, lzma_index_group_s::last, lzma_alloc(), lzma_index_end(), lzma_index_group_s::next, lzma_index_group_s::paddings, lzma_index_group_s::prev, lzma_index_s::tail, lzma_index_group_s::uncompressed_sums, and lzma_index_group_s::unpadded_sums.
lzma_bool lzma_index_equal | ( | const lzma_index * | a, | |
const lzma_index * | b | |||
) |
Compare if two Index lists are identical.
Read positions are not compared.
References lzma_index_group_s::last, lzma_index_group_s::next, lzma_index_group_s::paddings, lzma_index_group_s::uncompressed_sums, and lzma_index_group_s::unpadded_sums.