A Segment Collection manages a collection of segments virtually arranged in a continuous linear space. More...
Data Structures | |
struct | segcol_funcs |
Struct that holds the function pointers for an implementation of segcol_t. More... | |
Typedefs | |
typedef struct segcol | segcol_t |
Opaque type for segment collection ADT. | |
typedef struct segcol_iter | segcol_iter_t |
Opaque type for segment collection iterator. | |
Functions | |
int | segcol_free (segcol_t *segcol) |
Frees the resources of a segcol_t. | |
int | segcol_append (segcol_t *segcol, segment_t *seg) |
Appends a segment to the segcol_t. | |
int | segcol_insert (segcol_t *segcol, off_t offset, segment_t *seg) |
Inserts a segment into the segcol_t. | |
int | segcol_delete (segcol_t *segcol, segcol_t **deleted, off_t offset, off_t length) |
Deletes a logical range from the segcol_t. | |
int | segcol_find (segcol_t *segcol, segcol_iter_t **iter, off_t offset) |
Finds the segment that contains a given logical offset. | |
int | segcol_get_size (segcol_t *segcol, off_t *size) |
Gets the size of the data contained in a segcol_t. | |
Iterator functions | |
| |
int | segcol_iter_new (segcol_t *segcol, segcol_iter_t **iter) |
Gets a new (forward) iterator for a segcol_t. | |
int | segcol_iter_next (segcol_iter_t *iter) |
Moves the segcol_iter_t to the next element. | |
int | segcol_iter_is_valid (segcol_iter_t *iter, int *valid) |
Whether the iter points to a valid element. | |
int | segcol_iter_get_segment (segcol_iter_t *iter, segment_t **seg) |
Gets the segment pointed to by a segcol_iter_t. | |
int | segcol_iter_get_mapping (segcol_iter_t *iter, off_t *mapping) |
Gets the mapping (logical offset) of the segment pointed to by a segcol_iter_t. | |
int | segcol_iter_free (segcol_iter_t *iter) |
Frees a segcol_iter_t. | |
Internal functions | |
| |
int | segcol_create_impl (segcol_t **segcol, void *impl, struct segcol_funcs *funcs) |
Creates a segcol_t using a specific implementation. | |
void * | segcol_get_impl (segcol_t *segcol) |
Gets the implementation of a segcol_t. | |
void * | segcol_iter_get_impl (segcol_iter_t *iter) |
Gets the implementation of a segcol_t. | |
Constructors | |
| |
int | segcol_list_new (segcol_t **segcol) |
Creates a new segcol_t using a linked list implementation. |
A Segment Collection manages a collection of segments virtually arranged in a continuous linear space.
There may be many implementations of the Segment Collection ADT, each with its own performance characteristics. To create a Segment Collection one must use the constructor functions defined in each implementation (eg segcol_list_new()).
A note on error codes: all functions return EINVAL when an invalid range is specified (eg an offset is outside the limits of the virtual space of a Segment Collection).
Appends a segment to the segcol_t.
After the invocation of this function the segcol_t is responsible for the memory handling of the specified segment. The segment should not be further manipulated by the user.
segcol | the segcol_t to append to | |
seg | the segment to append |
Definition at line 127 of file segcol.c.
References segment_get_size().
Referenced by bless_buffer_save(), segcol_add_copy(), segcol_store_in_file(), and segcol_store_in_memory().
int segcol_create_impl | ( | segcol_t ** | segcol, | |
void * | impl, | |||
struct segcol_funcs * | funcs | |||
) |
Creates a segcol_t using a specific implementation.
[out] | segcol | the created segcol_t |
impl | the implementation private data | |
funcs | function pointers to the implementations' functions |
Definition at line 60 of file segcol.c.
Referenced by segcol_list_new().
Deletes a logical range from the segcol_t.
segcol | the segcol_t to delete from | |
[out] | deleted | if it is not NULL, on return it will point to a new segcol_t containing the deleted segments |
offset | the logical offset to start deleting at | |
length | the length of the range to delete |
Definition at line 189 of file segcol.c.
Referenced by segcol_add_copy(), segcol_store_in_file(), and segcol_store_in_memory().
int segcol_find | ( | segcol_t * | segcol, | |
segcol_iter_t ** | iter, | |||
off_t | offset | |||
) |
Finds the segment that contains a given logical offset.
segcol | the segcol_t to search in | |
[out] | iter | a segcol_iter_t pointing to the found segment |
offset | the offset to search for |
Definition at line 210 of file segcol.c.
Referenced by find_seg_entry(), and segcol_foreach().
int segcol_free | ( | segcol_t * | segcol | ) |
Frees the resources of a segcol_t.
After the invocation of this function it is an error to use the freed segcol_t.
segcol | the segcol_t to free |
Definition at line 108 of file segcol.c.
Referenced by bless_buffer_free(), bless_buffer_new(), and bless_buffer_save().
int segcol_get_size | ( | segcol_t * | segcol, | |
off_t * | size | |||
) |
Gets the size of the data contained in a segcol_t.
segcol | the segcol to get the size of | |
[out] | size | the size of the segcol in bytes |
Definition at line 311 of file segcol.c.
Referenced by bless_buffer_get_size(), bless_buffer_save(), segcol_add_copy(), segcol_foreach(), segcol_store_in_file(), and segcol_store_in_memory().
Inserts a segment into the segcol_t.
After the invocation of this function the segcol_t is responsible for the memory handling of the specified segment. The segment should not be further manipulated by the caller.
segcol | the segcol_t to insert into | |
offset | the logical offset at which to insert | |
seg | the segment to insert |
Definition at line 159 of file segcol.c.
References segment_get_size().
Referenced by segcol_add_copy(), segcol_store_in_file(), and segcol_store_in_memory().
int segcol_iter_free | ( | segcol_iter_t * | iter | ) |
Frees a segcol_iter_t.
It is an error to use a segcol_iter_t after freeing it.
iter | the segcol_iter_t to free |
Definition at line 295 of file segcol.c.
Referenced by create_overlap_graph(), find_seg_entry(), segcol_add_copy(), segcol_foreach(), and write_segcol_rest().
int segcol_iter_get_mapping | ( | segcol_iter_t * | iter, | |
off_t * | mapping | |||
) |
Gets the mapping (logical offset) of the segment pointed to by a segcol_iter_t.
iter | the iter to use | |
[out] | mapping | the mapping of the pointed segment or -1 if the iterator is invalid |
Definition at line 281 of file segcol.c.
Referenced by create_overlap_graph(), get_data_from_iter(), segcol_add_copy(), and write_segcol_rest().
int segcol_iter_get_segment | ( | segcol_iter_t * | iter, | |
segment_t ** | seg | |||
) |
Gets the segment pointed to by a segcol_iter_t.
iter | the iter to use | |
[out] | seg | the pointed segment or NULL if the iterator is invalid |
Definition at line 266 of file segcol.c.
Referenced by create_overlap_graph(), get_data_from_iter(), segcol_add_copy(), and write_segcol_rest().
int segcol_iter_is_valid | ( | segcol_iter_t * | iter, | |
int * | valid | |||
) |
Whether the iter points to a valid element.
iter | the segcol_iter_t to check | |
[out] | valid | 1 if the segcol_iter_t is valid, 0 otherwise |
Definition at line 253 of file segcol.c.
Referenced by create_overlap_graph(), find_seg_entry(), segcol_add_copy(), segcol_foreach(), and write_segcol_rest().
int segcol_iter_new | ( | segcol_t * | segcol, | |
segcol_iter_t ** | iter | |||
) |
Gets a new (forward) iterator for a segcol_t.
segcol | the segcol_t | |
[out] | iter | a forward segcol_iter_t |
Definition at line 223 of file segcol.c.
Referenced by create_overlap_graph(), segcol_add_copy(), and write_segcol_rest().
int segcol_iter_next | ( | segcol_iter_t * | iter | ) |
Moves the segcol_iter_t to the next element.
iter | the segcol_iter_t to move |
Definition at line 240 of file segcol.c.
Referenced by create_overlap_graph(), segcol_add_copy(), segcol_foreach(), and write_segcol_rest().
int segcol_list_new | ( | segcol_t ** | segcol | ) |
Creates a new segcol_t using a linked list implementation.
[out] | segcol | the created segcol_t |
Definition at line 241 of file segcol_list.c.
References list_free(), list_new, segcol_create_impl(), and segcol_list_clear_cache().
Referenced by bless_buffer_new(), and bless_buffer_save().