(3) cvseq Data Structure

Source: Internet
Author: User

Source Code definition

# Define cv_tree_node_fields (node_type )/
Int flags;/* miscellaneous flags .*//
Int header_size;/* size of sequence header .*//
Struct node_type * h_prev;/* previous sequence .*//
Struct node_type * h_next;/* next sequence .*//
Struct node_type * v_prev;/* 2nd previous sequence .*//
Struct node_type * v_next/* 2nd next sequence .*/

Read/write sequence.
Elements can be dynamically inserted to or deleted from the sequence.
# Define cv_sequence_fields ()/
Cv_tree_node_fields (cvseq );/
Int total;/* Total Number of elements .*//
Int elem_size;/* size of sequence element in bytes .*//
Schar * block_max;/* maximal bound of the last block .*//
Schar * PTR;/* Current write pointer .*//
Int delta_elems;/* grow seq this variable at a time .*//
Cvmemstorage * storage;/* Where the seq is stored .*//
Cvseqblock * free_blocks;/* free blocks list .*//
Cvseqblock * First;/* pointer to the first sequence block .*/

Typedef struct cvseq
Cv_sequence_fields ()


There is also a structure sequence block

Typedef struct cvseqblock
Struct cvseqblock * Prev;/* previous sequence block .*/
Struct cvseqblock * Next;/* next sequence block .*/
Int start_index;/* index of the first element in the block + */
/* Sequence-> first-> start_index .*/
Int count;/* Number of elements in the block .*/
Schar * data;/* pointer to the first element of the block .*/


In my understanding

A sequence contains many sequence blocks, and each sequence block stores multiple elements. You can use

The macro cv_tree_node_fields (cvseq) is connected to form various data structures. In the sequence

Multiple sequence blocks are connected by the prev and next pointers in the sequence blocks to form a two-way linked list.


To create a sequence, you need to apply for space allocation from the dynamic storage, and to apply for space from memory for operations such as adding and inserting elements.


Variable in a structure that is hard to understand

Schar * block_max; the farthest address boundary of the allocated space in the last sequence block. It is mainly used to compare it with the next pointer to determine whether the unused space meets the needs of the increased allocation of elements.

Schar * PTR: Specifies the storage location of the current element. It stores new elements in sequence and can be used to store new elements in the address space [PTR, block_max.

Int delta_elems; when the [PTR, block_max) address space is not enough to store new elements, the size of the space requested from the memory is re-applied.

Cvseqblock * free_blocks; empty sequence block list


Int start_index; the index of the first element in each block in the whole sequence element. Generally, the first element of the first block is 0, and the insert/delete operation changes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.