Talking about the structure and storage realization of sequence table

Sequence table structure

Insert picture description here

Description: The complete information of a sequence table consists of two parts, one is the collection of elements in the table, and the other is the information that needs to be recorded for correct operation, that is, information about the overall situation of the table. This part of information mainly includes the element storage area The capacity of and the number of elements in the current table.

Two basic ways to realize the sequence table

Insert picture description here

  • Figure a shows an integrated structure. The unit for storing table information and the element storage area are arranged in a storage area in a continuous manner. The two parts of data form a complete sequence table object.

The integrated structure has strong integrity and easy management. But because the data element storage area is a part of the table object, after the sequence table is created, the element storage area is fixed.

  • Figure b shows a separated structure. Only information related to the entire table (ie capacity and number of elements) is stored in the table object. The actual data elements are stored in another independent element storage area and are associated with the basic table object through links.

  • Element storage area replacement
    integrated structure. Because the sequence table information area and the data area are continuously stored together, if you want to replace the data area, you can only move it as a whole, that is, the entire sequence table object (referring to the area where the structure information of the sequence table is stored) is changed Up.

  • If you want to replace the data area with the separated structure, you only need to update the link address of the data area in the table information area, and the sequence table object remains unchanged.

  • The element storage area expansion
    adopts a sequence table with a separate structure. If the data area is replaced with a larger storage space, the data storage area can be expanded without changing the table object. All places where this table is used No need to modify. As long as the program's operating environment (computer system) has free storage, this table structure will not cause operations to fail because it is full. People call the sequence table implemented by this technology a dynamic sequence table because its capacity can be dynamically changed during use.

Two strategies for expansion

  • Each expansion adds a fixed number of storage locations, for example: each expansion adds 10 element locations, this strategy can be called linear growth.

Features: Save space, but frequent expansion operations and many operations.

  • Each expansion doubles the capacity, such as doubles the storage space each expansion.

Features: Reduce the number of executions of expansion operations, but may waste space resources. The recommended way to trade space for time.

Guess you like

Origin blog.csdn.net/qq_41475067/article/details/112302461