Array processing method and device, electronic equipment and storage medium

By setting reference space at the end of the array, dynamically expanding the capacity, and creating an expanded array linked list or reference table, the problem of system performance degradation caused by array expansion under limited smart card resources is solved, and efficient array expansion and space utilization are achieved.

CN120743350APending Publication Date: 2025-10-03EASTCOMPEACE TECH
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202510870809.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

In the existing technology, under the condition of limited smart card resources, array expansion will lead to reduced system performance and the need to frequently call the garbage collector, affecting the system operation speed and space utilization efficiency.

Method used

By setting reference space at the end of the array, dynamic expansion processing is performed, an expanded array is created, and reference space is set at the end of the expanded array to form an array linked list or reference table, thereby realizing dynamic expansion of the array and avoiding data copying and calling of the garbage collector.

Benefits of technology

While maintaining good system performance, the array can be dynamically expanded, avoiding data copying and space fragmentation, and improving system operation efficiency and space utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120743350A_ABST
    Figure CN120743350A_ABST
Patent Text Reader

Abstract

The invention discloses an array processing method and device, electronic equipment and a storage medium, and relates to the technical field of array processing. The method comprises the following steps: creating an initial array according to a preset initial capacity, and setting a first reference space at the tail end of the initial array; wherein the first reference space is used for storing a first address of a capacity expansion array or an array reference table; in the process of storing the target data in the initial array, when it is judged that the capacity of the initial array is full and the target data is not completely stored, array dynamic capacity expansion processing is conducted on the basis of the first reference space, the expanded array is obtained, and the target data continues to be stored in the expanded array. According to the method and the device, the array dynamic capacity expansion can be realized under the condition of maintaining good system performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of array processing technology, and in particular to an array processing method and its device, electronic device, and storage medium. Background Art

[0002] Array expansion dynamically increases the array's capacity when the number of elements to be stored exceeds the array's current capacity after a certain amount of space has been allocated. This expansion plan must balance system speed and space usage within the constraints of smart card resources. The expansion process is implemented by the virtual machine and is transparent to the user.

[0003] In related technologies, when an array is expanded, a new array is created and the contents of the original array are copied to the new array. This solution incurs the overhead of data copying, and the space occupied by the original array cannot be released immediately and must be recycled by the garbage collector before it can be released. Frequent calls to the garbage collector on smart cards will greatly degrade system performance. Summary of the Invention

[0004] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes an array processing method and apparatus, electronic device, and storage medium thereof, which can achieve dynamic array expansion while maintaining good system performance.

[0005] In a first aspect, an embodiment of the present application provides an array processing method, comprising:

[0006] An initial array is created according to a preset initial capacity, and a first reference space is set at the end of the initial array; wherein the first reference space is used to store the first address of the expanded array or the array reference table;

[0007] In the process of storing target data in the initial array, when it is determined that the capacity of the initial array is full and the target data is not completely stored, the array is dynamically expanded based on the first reference space to obtain an expanded array, and the target data continues to be stored in the expanded array.

[0008] According to some embodiments of the present application, dynamically expanding the array based on the first reference space to obtain an expanded array, and continuing to store the target data in the expanded array includes:

[0009] Creating a first expansion array according to a preset single expansion capacity, and setting a second reference space at the end of the first expansion array; wherein the second reference space is used to store the first address of the next expansion array;

[0010] Storing the first address of the first expanded array in the first reference space to obtain the expanded first array;

[0011] In the expanded first array, continuing to store the target data starting from a position where the index number of the first expanded array is zero;

[0012] In the process of continuing to store the target data in the first expansion array, when the capacity of the first expansion array is full and the target data is not completely stored, the first expansion process is continued based on the second reference space.

[0013] According to some embodiments of the present application, continuing the first expansion process based on the second reference space includes:

[0014] Creating a second expansion array according to a preset single expansion capacity, and setting a third reference space at the end of the second expansion array; wherein the third reference space is used to store the first address of the next expansion array;

[0015] Storing the first address of the second expanded array in the second reference space to obtain the expanded second array;

[0016] In the expanded second array, continuing to store the target data starting from a position where the index number of the second expanded array is zero;

[0017] In the process of continuing to store the target data in the second expansion array, when the capacity of the second expansion array is full and the target data is not completely stored, the first expansion processing is continued based on the third reference space; when the target data is completely stored, the data storage and the first expansion processing are ended.

[0018] According to some embodiments of the present application, dynamically expanding the array based on the first reference space to obtain an expanded array, and continuing to store the target data in the expanded array includes:

[0019] Creating an array reference table according to a number threshold, and storing the first address of the array reference table in the first reference space; wherein the array reference table is an array having a length equal to the number threshold;

[0020] Perform statistical processing to obtain the current number of expansions;

[0021] When it is determined that the current expansion number is less than the number threshold, creating a third expansion array according to the preset single expansion capacity;

[0022] Storing the first address of the third expanded array at the position where the index number of the array reference table is zero, to obtain the expanded third array;

[0023] In the expanded third array, continuing to store the target data starting from a position where the index number of the third expanded array is zero;

[0024] In the process of continuing to store the target data in the third expanded array, when the capacity of the third expanded array is full, a second expansion process is performed based on the array reference table.

[0025] According to some embodiments of the present application, performing the second expansion process based on the array reference table includes:

[0026] Perform statistical processing on the number of times to obtain the updated current expansion number;

[0027] When the updated current expansion number is less than the number threshold, creating a fourth expansion array according to the preset single expansion capacity;

[0028] The first address of the fourth expanded array is stored in the array reference table to obtain the expanded fourth array.

[0029] According to some embodiments of the present application, after obtaining the updated current expansion times, the method further includes:

[0030] When the current expansion times after the update is not less than the times threshold, stop expansion;

[0031] Generates and sends an array out of space alert.

[0032] According to some embodiments of the present application, after continuing to store the target data in the expanded array, the method further includes:

[0033] When the dynamic expansion of the array is completed, when accessing an array element in the expanded array, determining the element index number of the target element to be accessed;

[0034] When it is determined according to the element index number that the target element is located in the initial array, directly accessing the target element in the initial array;

[0035] When it is determined according to the element index number that the target element is not located in the initial array, a target expansion array is searched from a plurality of candidate expansion arrays according to the element index number and a preset index formula, and a target index number is determined;

[0036] In the target expanded array, the target element is accessed according to the target index number.

[0037] In a second aspect, an embodiment of the present application provides an array processing device, comprising at least one processor and a memory for communicating with the at least one processor; the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the array processing method as described in any one of the embodiments of the first aspect.

[0038] In a third aspect, an embodiment of the present application provides an electronic device, comprising the array processing device as described in the embodiment of the second aspect.

[0039] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the array processing method as described in any one of the embodiments of the first aspect.

[0040] The embodiment of the present application includes: in the process of using an array to store data, first, an initial array is created according to a preset initial capacity, and a first reference space is set at the end of the initial array; wherein the first reference space is used to store the first address of the expanded array or array reference table; in the process of storing target data in the initial array, when it is determined that the capacity of the initial array is full and the target data is not completely stored, the array is dynamically expanded based on the first reference space to obtain the expanded array, and the target data is continued to be stored in the expanded array; thereby achieving dynamic expansion of the array; and in this process, there is no need to copy the data of the entire array, no space fragmentation is generated, and there is no need to call the garbage collector for defragmentation and release array space, therefore, it will not cause a decrease in system performance and can maintain good system performance. That is to say, the embodiment of the present application can achieve dynamic expansion of the array while maintaining good system performance.

[0041] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained through the structures particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 This is a schematic flow chart of the steps of an array processing method provided by an embodiment of the present application;

[0043] Figure 2 This is a schematic diagram of a simulation of the memory space state during the first expansion process based on the array linked list provided by an embodiment of the present application;

[0044] Figure 3This is a schematic diagram of a simulation of the memory space state during the first expansion process based on the array linked list provided by another embodiment of the present application;

[0045] Figure 4 This is a schematic diagram of a simulation of the memory space state during the second expansion process based on the array reference table provided by an embodiment of the present application;

[0046] Figure 5 This is a schematic diagram simulating the memory space state during the second capacity expansion process based on the array reference table provided by another embodiment of the present application;

[0047] Figure 6 This is a schematic diagram of the hardware structure of an array processing device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solutions and advantages of this application more clear, this application is further described in detail below with reference to the accompanying drawings and embodiments.

[0049] It should be understood that in the description of this application, descriptions of orientations, such as up, down, front, back, left, right, etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation. Therefore, they cannot be understood as limitations on this application.

[0050] It should be noted that although a logical order is shown in the flowchart in the description of this application, in some cases, the steps shown or described may be performed in an order different from that in the flowchart. In the description of this application, "several" means one or more, and "more" means two or more. The description of "first" and "second" is only used to distinguish technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.

[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.

[0052] The present application provides an array processing method and an array processing device, an electronic device, and a computer-readable storage medium, and relates to the field of array processing technology. The method includes: creating an initial array according to a preset initial capacity, and setting a first reference space at the end of the initial array; wherein the first reference space is used to store the first address of the expanded array or array reference table; in the process of storing target data in the initial array, when it is determined that the capacity of the initial array is full and the target data is not completely stored, the array is dynamically expanded based on the first reference space to obtain the expanded array, and the target data is continued to be stored in the expanded array. The present application can achieve dynamic array expansion while maintaining good system performance.

[0053] The embodiments of the present application are further described below with reference to the accompanying drawings.

[0054] First, as Figure 1 As shown, Figure 1 1 is a flowchart of the steps of an array processing method provided by an embodiment of the present application; the array processing method may include but is not limited to steps S110 to S120.

[0055] Step S110: creating an initial array according to a preset initial capacity, and setting a first reference space at the end of the initial array; wherein the first reference space is used to store the first address of the expanded array or the array reference table.

[0056] Step S120: In the process of storing the target data in the initial array, when it is determined that the capacity of the initial array is full and the target data is not completely stored, the array is dynamically expanded based on the first reference space to obtain the expanded array, and the target data continues to be stored in the expanded array.

[0057] Specifically, by setting a preset initial capacity, the maximum number of data elements that the initial array can store is determined. The preset initial capacity can be determined according to actual needs and is not specifically limited in this application.

[0058] Specifically, the first reference space is a space that occupies two bytes and can store the first address of the expanded array or array reference table, laying a spatial foundation for dynamic array expansion processing.

[0059] Specifically, in step S120, when it is determined that the number of data elements currently stored in the initial array is less than the preset initial capacity, it is determined that the capacity of the initial array is remaining; when it is determined that the number of data elements currently stored in the initial array is equal to the preset initial capacity, it is determined that the capacity of the initial array is not remaining and the capacity of the initial array is full.

[0060] Specifically, the array dynamic expansion processing provided in the embodiment of the present application in step S120 includes: a first expansion processing based on the array linked list and a second expansion processing based on the array reference table.

[0061] The embodiment of the present application, through steps S110 to S120, in the process of using an array to store data, first, creates an initial array according to a preset initial capacity, and sets a first reference space at the end of the initial array; wherein, the first reference space is used to store the first address of the expanded array or array reference table; in the process of storing target data in the initial array, when it is determined that the capacity of the initial array is full and the target data is not completely stored, the array is dynamically expanded based on the first reference space to obtain the expanded array, and the target data is continued to be stored in the expanded array; thereby achieving dynamic expansion of the array; and in this process, there is no need to copy the data of the entire array, no space fragmentation is generated, and there is no need to call the garbage collector for defragmentation and release array space, therefore, it will not cause system performance to degrade, and good system performance can be maintained. Therefore, the embodiment of the present application can achieve dynamic expansion of the array while maintaining good system performance.

[0062] The first expansion process based on the array linked list provided in the embodiment of the present application is described in detail.

[0063] According to some embodiments of the present application, step S120 is further described, wherein the array is dynamically expanded based on the first reference space to obtain an expanded array, and target data is continued to be stored in the expanded array, including but not limited to steps S210 to S240.

[0064] Step S210: creating a first expansion array according to a preset single expansion capacity, and setting a second reference space at the end of the first expansion array; wherein the second reference space is used to store the first address of the next expansion array.

[0065] Step S220: storing the first address of the first expanded array into the first reference space to obtain the expanded first array.

[0066] Step S230: In the expanded first array, continue to store the target data starting from the position where the index number of the first expanded array is zero.

[0067] Step S240: in the process of continuing to store the target data in the first expansion array, when the capacity of the first expansion array is full and the target data is not completely stored, continue the first expansion process based on the second reference space.

[0068] Specifically, by setting a preset single expansion capacity, the maximum number of data elements that the expansion array can store is determined. The preset single expansion capacity can be determined according to actual needs and is not specifically limited in this application.

[0069] Specifically, the second reference space is a space that occupies two bytes and can store the first address of the next expansion array, thereby laying a spatial foundation for the first expansion process based on the array linked list.

[0070] Specifically, the expanded first array obtained in step S220 is an array linked list, including: an initial array, a first reference space, a first expanded array, and a second reference space.

[0071] Specifically, in step S240, if it is determined that the number of data elements currently stored in the first expansion array is less than the preset single expansion capacity, then it is determined that there is remaining capacity in the first expansion array; if it is determined that the number of data elements currently stored in the first expansion array is equal to the preset single expansion capacity, then it is determined that there is no remaining capacity in the first expansion array and that the capacity of the first expansion array is full. Similarly, when determining whether other expansion arrays are full, the judgment is made based on the same method.

[0072] It can be understood that in some embodiments, when the target data is completely stored and the capacity of the first expansion array is still remaining or is just exhausted, no further expansion is performed, and the data storage and the first expansion process are terminated; the final array linked list includes: the initial array, the first reference space, the first expansion array, and the second reference space.

[0073] According to some embodiments of the present application, step S240 is further described, wherein the first expansion process is continued based on the second reference space, including but not limited to steps S310 to S340.

[0074] Step S310: creating a second expansion array according to the preset single expansion capacity, and setting a third reference space at the end of the second expansion array; wherein the third reference space is used to store the first address of the next expansion array.

[0075] Step S320: storing the first address of the second expanded array into the second reference space to obtain the expanded second array.

[0076] Step S330: In the expanded second array, continue to store the target data starting from the position where the index number of the second expanded array is zero.

[0077] Step S340: In the process of continuing to store the target data in the second expansion array, when the capacity of the second expansion array is full and the target data is not completely stored, continue the first expansion process based on the third reference space; when the target data is completely stored, end the data storage and the first expansion process.

[0078] Specifically, the capacity of each expansion array is the same and is determined by a preset single expansion capacity.

[0079] Specifically, the third reference space is a space that occupies two bytes and can store the first address of the next expansion array, laying a spatial foundation for expansion. It should be noted that the number of bytes occupied by each reference space is the same.

[0080] Specifically, the expanded second array obtained in step S320 includes: an initial array, a first reference space, a first expanded array, a second reference space, a second expanded array, and a third reference space.

[0081] It can be understood that, in step S340, the specific process of continuing the first expansion processing based on the third reference space is the same as the process shown in steps S310 to S340, and will not be repeated here.

[0082] It is understandable that in step S340, when the target data is completely stored and the data storage and the first expansion process are completed, the final array linked list storing the target data is obtained.

[0083] Through steps S210 to S240 and S310 to S340, in the process of storing target data, when the current overall array capacity does not meet the storage requirements, the array capacity is dynamically expanded by storing the first address of the next expanded array in the set reference space; and with the creation of each new expanded array, a new reference space will be set up to facilitate stable and continuous dynamic expansion of the array; and finally, an array linked list storing target data is formed to meet the storage requirements. In this process, there is no need to copy the data of the entire array, no space fragmentation will be generated, and there is no need to call the garbage collector for defragmentation and release array space, which will not cause a decrease in system performance and can maintain good system performance. Therefore, the first expansion process based on the array linked list provided in the embodiment of the present application can achieve dynamic expansion of the array while maintaining good system performance.

[0084] Take an example and combine it with actual application scenarios to illustrate the first expansion process based on the array linked list provided in the embodiment of the present application.

[0085] Assume that the initial capacity is set to 10, the single expansion capacity is set to 5, and the expansion size is 5 each time. First, 10 numbers are added to the array: 1, 2, 3, 4, 5, 6, 6, 6, 6, and then the 11th number 100 is added to the array. The array linked list method used for expansion mainly includes the following steps 1 and 2.

[0086] Step 1: Create an initial array with an initial size of 10 according to the preset initial capacity, and apply for 2 more bytes of first reference space to store the first address of the next expanded array. After adding 10 numbers: 1, 2, 3, 4, 5, 6, 6, 6, 6, 6 to the initial array, the simulation diagram of the memory space state is as follows Figure 2 As shown in the figure, the first reference space is followed by the free area of ​​memory.

[0087] Step 2: When the number 100 is added to the initial array, it is determined that the capacity of the initial space is full and there is still storage demand, so a first expansion array of size 5 is created, and an additional second reference space of 2 bytes is requested to store the first address of the next expansion array; the first address of the second expansion array is then stored in the first reference space to obtain the expanded first array; the number 100 is stored in the position with index number zero in the first expansion array. The simulation diagram of the memory space state obtained in this step is as follows Figure 3 As shown in the figure, the first array is in the form of a linked list. The first array includes: the initial array, the first reference space, the first expanded array, and the second reference space. The second reference space is followed by the free area of ​​the memory.

[0088] After the first and second steps, a dynamic expansion is completed. Whenever the expanded array space is full, the expansion will continue according to the second step.

[0089] The second expansion process based on the array reference table provided in the embodiment of the present application is described in detail.

[0090] According to some embodiments of the present application, step S120 is further described, wherein the array is dynamically expanded based on the first reference space to obtain an expanded array, and target data is continued to be stored in the expanded array, including but not limited to steps S410 to S460.

[0091] Step S410: creating an array reference table according to the number threshold, and storing the first address of the array reference table in the first reference space; wherein the array reference table is an array with a length equal to the number threshold.

[0092] Step S420: Perform frequency statistics processing to obtain the current expansion frequency.

[0093] Step S430: When it is determined that the current expansion times are less than the times threshold, a third expansion array is created according to the preset single expansion capacity.

[0094] Step S440: storing the first address of the third expanded array into the position of index zero in the array reference table to obtain the expanded third array.

[0095] Step S450: In the expanded third array, continue to store the target data starting from the position where the index number of the third expanded array is zero.

[0096] Step S460: in the process of continuing to store the target data in the third expanded array, when the capacity of the third expanded array is full, a second expansion process is performed based on the array reference table.

[0097] Specifically, the number threshold is the maximum number of expansions allowed by the second expansion process of this application. By setting the number threshold, the dynamic expansion process of the array is limited and relatively controllable. The number threshold can be set according to actual needs, and the value of the number threshold of this application is not specifically limited. The number threshold should be non-zero and be a positive integer greater than or equal to 1.

[0098] Specifically, the array reference table is an array of reference type with a length equal to the number threshold.

[0099] It is understandable that in step S410, the first address of the array reference table is placed in the first reference space. This step only occurs during the first expansion; that is, the array reference table needs to be introduced during the first expansion to limit the number of subsequent expansions.

[0100] Specifically, the expanded third array obtained in step S440 includes: an initial array, an array reference table, and a third expanded array.

[0101] According to some embodiments of the present application, step S460 is further described, wherein a second expansion process is performed based on the array reference table, including but not limited to steps S510 to S530.

[0102] Step S510: Perform frequency statistics processing to obtain the updated current expansion frequency.

[0103] Step S520: When the updated current expansion times are less than the times threshold, a fourth expansion array is created according to the preset single expansion capacity.

[0104] Step S530: storing the first address of the fourth expanded array into the array reference table to obtain the expanded fourth array.

[0105] According to some embodiments of the present application, after step S510, i.e., after obtaining the updated current expansion count, the array processing method further includes: stopping expansion when the updated current expansion count is not less than a threshold; and generating and sending an array space shortage alarm, so that relevant engineering personnel are promptly notified of the array space shortage.

[0106] Specifically, the expanded fourth array obtained in step S530 includes: an initial array, an array reference table, a third expanded array, and a fourth expanded array.

[0107] Specifically, after obtaining the expanded fourth array, the target data is continued to be stored in the expanded fourth array starting from the position where the index number of the fourth expanded array is zero; in the process of continuing to store the target data in the fourth expanded array, when the capacity of the fourth expanded array is full, the second expansion processing is continued based on the array reference table; thereby, a limited number of expansions are performed within the maximum number of expansions allowed.

[0108] Through steps S410 to S460 and S510 to S530, in the process of storing target data, when the current overall array capacity does not meet the storage requirements, by setting an array reference table of a certain capacity, and storing the first address of the expanded array in the array reference table, a limited number of expansions are achieved. In this process, there is no need to copy the data of the entire array, no space fragmentation is generated, and no need to call the garbage collector for defragmentation and release array space, which will not cause system performance to degrade and can maintain good system performance. Therefore, the second expansion process based on the array reference table provided in the embodiment of the present application can achieve dynamic expansion of the array while maintaining good system performance.

[0109] In addition, the second capacity expansion process based on the array reference table of the present application can be applied to smart cards. However, the capacity of smart cards is limited. By setting a reasonable capacity expansion number threshold, the capacity of the smart card can be more reasonably utilized.

[0110] Take an example and combine it with actual application scenarios to illustrate the second expansion processing based on the array reference table provided by the embodiment of the present application.

[0111] Assume that the application scenario is: the preset initial capacity is 10, the preset single expansion capacity is 5, that is, the expansion size is 5 each time, and a new parameter: the maximum number of expansions (i.e., the number threshold), is set to 4. The expansion process based on the array reference table mainly includes the following steps 1, 2, and 3.

[0112] Step 1: Create an initial array with an initial size of 10 according to the preset initial capacity, and apply for 2 more bytes of first reference space to store the first address of the array reference table. After adding 10 numbers: 1, 2, 3, 4, 5, 6, 6, 6, 6, 6 to the initial array, the simulation diagram of the memory space state is as follows Figure 2 shown.

[0113] Step 2: When the number 100 is added to the initial array, it is determined that the capacity of the initial space is full and there is still storage demand. First, create an array of reference type with an array size of 4 according to the number threshold. This array is named array reference table, and the first address of the array reference table is placed in the first reference space. The introduction of the array reference table will only occur during the first expansion. The array reference table is used to store the first address of each expanded array. The simulation diagram of the memory space state after the introduction of the array reference table is as follows Figure 4 As shown in the figure, the array reference table is followed by the free area of ​​memory.

[0114] Step 3: Create a third expansion array based on the preset single expansion capacity, and put the first address of the third expansion array into the position with index number 0 in the array reference table to obtain the third array after expansion. In the third array, put the number 100 to be stored into the position with index number 0 in the third expansion array. The simulation diagram of the memory space state obtained in this step is as follows Figure 5 shown.

[0115] Dynamic expansion is completed through steps 1, 2, and 3. Whenever the array space is full, expansion continues according to step 3. If the number of expansions exceeds the threshold of 4, an insufficient array space alarm is issued.

[0116] It should be noted that the first expansion process based on the array linked list and the second expansion process based on the array reference table both require additional space to store the first address of the expanded array, and are therefore suitable for smart cards with relatively large capacities.

[0117] It is understood that the array processing method of the embodiment of the present application includes: a first expansion process based on an array linked list, a second expansion process based on an array reference table, and access processing of data elements in the expanded array. For arrays obtained through different expansion processing methods, the method of accessing elements in the array is also different. Specifically, the processing of accessing the expanded array provided by the embodiment of the present application is further explained.

[0118] According to some embodiments of the present application, after step S120 is completed, that is, after continuing to store the target data in the expanded array, the array processing method further includes steps S610 to S640.

[0119] Step S610: When the dynamic expansion of the array is completed, when accessing array elements in the expanded array, the element index number of the target element to be accessed is determined.

[0120] Step S620: When it is determined based on the element index number that the target element is located in the initial array, the target element is directly accessed in the initial array.

[0121] Step S630: When it is determined according to the element index number that the target element is not in the initial array, a target expanded array is found from multiple candidate expanded arrays according to the element index number and a preset index formula, and the target index number is determined.

[0122] Step S640: In the target expanded array, access the target element according to the target index number.

[0123] In some embodiments, further illustrating steps S630 and S640, when accessing an array obtained after the first expansion process, the index formula includes: a loop count calculation formula and a target index calculation formula; step S630 includes but is not limited to:

[0124] First, for the array linked list storing target data obtained after the first expansion process, if the target element to be accessed is not in the initial array, the number of loops is determined according to the loop number calculation formula; wherein, the loop number calculation formula is: loop number = floor((element index + 1 - preset initial capacity) / preset single expansion capacity) + 1.

[0125] Secondly, loop through the array linked list, and after the number of loops, find the target expansion array.

[0126] Next, the corresponding index number in the target expansion array is calculated according to the target index calculation formula; wherein the target index calculation formula is: target index number = (element index + 1 - preset initial capacity) % preset single expansion capacity - 1.

[0127] Finally, the target element is accessed in the target expanded array according to the calculated target index number.

[0128] Let's take an example to illustrate how to access the array obtained after the first expansion process. If the element index number of the target element to be accessed is 10, which exceeds the index number range of the initial array from 0 to 9, it is necessary to loop through the array linked list, looping once to find the target expanded array where the target element is located, and then access the element with the target index number 0 in the target expanded array, that is, access the target element.

[0129] In some embodiments, further illustrating steps S630 and S640, when accessing an array obtained after the second expansion process, the index formula includes: an array reference table index calculation formula and a target index calculation formula; step S630 includes but is not limited to:

[0130] First, for the array obtained after the second expansion process and storing the target data, if the target element to be accessed is not in the initial array, the array reference table index number is determined according to the array reference table index calculation formula; wherein, the array reference table index calculation formula is: array reference table index number = floor((element index + 1-preset initial capacity) / preset single expansion capacity).

[0131] Secondly, the first address of the target expansion array is found in the array reference table according to the calculated index number of the array reference table, and the target expansion array is determined based on the first address of the target expansion array.

[0132] Then, the corresponding index number in the target expansion array is calculated according to the target index calculation formula; wherein the target index calculation formula is: target index number = (element index + 1 - preset initial capacity) % preset single expansion capacity - 1.

[0133] Finally, the target element is accessed in the target expanded array according to the calculated target index number.

[0134] Let's take an example to illustrate how to access the array obtained after the second expansion process. For example, to access the target element with index number 18, you need to access the array reference table with index number 1 to obtain the first address, access the target expanded array based on the obtained first address, and then access the target element with index number 3 in the target expanded array.

[0135] It should be noted that the floor operator used in the loop count calculation formula, target index calculation formula, and array reference table index calculation formula refers to the "round down" operation; that is, a real number (integer or decimal) is rounded down to the nearest integer; this integer is less than or equal to the original value.

[0136] Through steps S610 to S640, the target element is found quickly and conveniently in the expanded array based on the element index number, thereby improving the efficiency and accuracy of accessing the array elements.

[0137] It can be understood that the first expansion process based on the array linked list and the second expansion process based on the array reference table both realize dynamic expansion based on the first reference space in the initial array; the difference is that in the first expansion process, a new reference space will be set up with the creation of each new expanded array, so as to stably and continuously carry out dynamic expansion of the array; and in the second expansion process, an array reference table of a certain capacity is set up, and the first address of the expanded array is stored in the array reference table to achieve a limited number of expansions; when the number of expansions is large, the element search speed is improved by searching the array reference table.

[0138] like Figure 6As shown, the present invention also provides an array processing device, comprising:

[0139] The processor 601 may be implemented as a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.

[0140] The memory 602 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 602 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 602 and is called by the processor 601 to execute the array processing method of the embodiments of this application.

[0141] Input / output interface 603, used to implement information input and output;

[0142] Communication interface 604, used to implement communication interaction between the apparatus and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WiFi, Bluetooth, etc.);

[0143] Bus 605 , which transmits information between various components of the device (e.g., processor 601 , memory 602 , input / output interface 603 , and communication interface 604 );

[0144] The processor 601 , the memory 602 , the input / output interface 603 and the communication interface 604 are connected to each other in communication within the device via a bus 605 .

[0145] An embodiment of the present application further provides an electronic device, comprising the array processing device as described above.

[0146] An embodiment of the present application further provides a storage medium, which is a computer-readable storage medium and stores a computer program. When the computer program is executed by a processor, the above-mentioned array processing method is implemented.

[0147] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory optionally includes a memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of the above-mentioned networks include but are not limited to the Internet, an intranet, a local area network, a mobile communication network and a combination thereof. The device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and are located in one place, or may be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.

[0148] Those skilled in the art will appreciate that all or some of the steps and systems in the method disclosed above can be implemented as software, firmware, hardware, and appropriate combinations thereof. Some physical components or all physical components can be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, and the computer-readable medium can include computer storage media (or non-transitory media) and communication media (or temporary media). As known to those skilled in the art, the term computer storage media is included in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data) and is volatile and non-volatile, removable, and non-removable. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory, or other memory technology, CD-ROM, digital versatile disks (DVD), or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage, or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, as is well known to those skilled in the art, communication media typically includes computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0149] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above implementation mode. Technical personnel familiar with the field can also make various equivalent modifications or substitutions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the present application.

Claims

1. An array processing method, characterized in that: include: An initial array is created according to a preset initial capacity, and a first reference space is set at the end of the initial array; wherein the first reference space is used to store the first address of the expanded array or the array reference table; In the process of storing target data in the initial array, when it is determined that the capacity of the initial array is full and the target data is not completely stored, the array is dynamically expanded based on the first reference space to obtain an expanded array, and the target data continues to be stored in the expanded array.

2. The array processing method according to claim 1, wherein: The dynamically expanding the array based on the first reference space to obtain an expanded array, and continuing to store the target data in the expanded array, includes: Creating a first expansion array according to a preset single expansion capacity, and setting a second reference space at the end of the first expansion array; wherein the second reference space is used to store the first address of the next expansion array; Storing the first address of the first expanded array in the first reference space to obtain the expanded first array; In the expanded first array, continuing to store the target data starting from a position where the index number of the first expanded array is zero; In the process of continuing to store the target data in the first expansion array, when the capacity of the first expansion array is full and the target data is not completely stored, the first expansion process is continued based on the second reference space.

3. The array processing method according to claim 2, wherein: The continuing the first capacity expansion process based on the second reference space includes: Creating a second expansion array according to a preset single expansion capacity, and setting a third reference space at the end of the second expansion array; wherein the third reference space is used to store the first address of the next expansion array; Storing the first address of the second expanded array in the second reference space to obtain the expanded second array; In the expanded second array, continuing to store the target data starting from a position where the index number of the second expanded array is zero; In the process of continuing to store the target data in the second expansion array, when the capacity of the second expansion array is full and the target data is not completely stored, the first expansion processing is continued based on the third reference space; when the target data is completely stored, the data storage and the first expansion processing are ended.

4. The array processing method according to claim 1, wherein: The dynamically expanding the array based on the first reference space to obtain an expanded array, and continuing to store the target data in the expanded array, includes: Creating an array reference table according to a number threshold, and storing the first address of the array reference table in the first reference space; wherein the array reference table is an array having a length equal to the number threshold; Perform statistical processing to obtain the current number of expansions; When it is determined that the current expansion number is less than the number threshold, creating a third expansion array according to the preset single expansion capacity; Storing the first address of the third expanded array at the position where the index number of the array reference table is zero, to obtain the expanded third array; In the expanded third array, continuing to store the target data starting from a position where the index number of the third expanded array is zero; In the process of continuing to store the target data in the third expanded array, when the capacity of the third expanded array is full, a second expansion process is performed based on the array reference table.

5. The array processing method according to claim 4, characterized in that: The performing the second capacity expansion process based on the array reference table includes: Perform statistical processing on the number of times to obtain the updated current expansion number; When the updated current expansion number is less than the number threshold, creating a fourth expansion array according to the preset single expansion capacity; The first address of the fourth expanded array is stored in the array reference table to obtain the expanded fourth array.

6. The array processing method according to claim 4, characterized in that: After obtaining the updated current expansion number, the method further includes: When the current expansion times after the update is not less than the times threshold, stop expansion; Generates and sends an array out of space alert.

7. The array processing method according to any one of claims 1 to 6, characterized in that: After continuing to store the target data in the expanded array, the method further includes: When the dynamic expansion of the array is completed, when accessing an array element in the expanded array, determining the element index number of the target element to be accessed; When it is determined according to the element index number that the target element is located in the initial array, directly accessing the target element in the initial array; When it is determined according to the element index number that the target element is not located in the initial array, a target expansion array is searched from a plurality of candidate expansion arrays according to the element index number and a preset index formula, and a target index number is determined; In the target expanded array, the target element is accessed according to the target index number.

8. An array processing device, characterized in that: The method comprises at least one processor and a memory for communicating with the at least one processor; the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the array processing method according to any one of claims 1 to 7.

9. An electronic device, characterized in that: Comprising the array processing device as claimed in claim 8.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the array processing method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Data storage method and device and data access method and device

    CN107622020A

  • Annular queue storage method and device, computing equipment and storage medium

    CN111708495A

  • Memory configuration method and device, electronic equipment and storage medium

    CN115237607A

  • Systems and methods for storing data in an integrated array and linked list based structure

    EP3644196A1

  • Key-value store system

    US20190278849A1