Data processing method and device, electronic device, and storage medium
By dynamic indexing of variable-length arrays on the blockchain, the read speed attenuation problem caused by the degradation of smart contract performance is solved, and more efficient data reading is achieved.
Patent Information
- Application Number
- CN202111539348.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-15
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2041-12-15
AI Technical Summary
When storing similar variable-length arrays on the blockchain, due to the degradation of the performance of smart contracts, the reading speed of elements in the array rapidly decays after the increase in data volume. The existing technology has not yet proposed an effective solution.
When you need to add new elements to the target array, dynamically adjust the index interval according to the change in the length of the array, re-establish the index, and re-index with a larger index interval as the target array, and dynamically adjust the index as the increase of elements in the array.
By dynamically adjusting the index interval, the attenuation rate of the reading speed is reduced, the reading speed of elements in the array is improved, and the problem of rapid attenuation of the reading speed caused by the increasing amount of data in the array is solved.
Smart Images

Figure CN114385628B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data processing method and device, an electronic device, and a storage medium. Background Art
[0002] With the rapid development of the big data era, blockchain technology is increasingly used in data storage. At present, the storage of variable-length arrays on the blockchain generally relies on smart contracts. However, due to the inherent defects of smart contracts, the performance of smart contracts will drop rapidly when the amount of data is large. Storing variable-length arrays in immutable transaction data will cause reading performance problems.
[0003] As the amount of data in the array continues to increase, the speed of reading elements in the array will decrease rapidly.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The present application provides a data processing method and device, an electronic device, and a storage medium to at least solve the technical problem in the related art that the reading speed of elements in the array is rapidly decreasing due to the continuous increase in the amount of data in the array.
[0006] According to one aspect of an embodiment of the present application, a data processing method is provided, including: in the case where it is necessary to append new elements to a target array, determining a second length based on a first length, wherein the first length is the number of elements in the target array before appending the new elements, and the second length is the number of elements in the target array after appending the new elements; determining a first parameter and a second parameter of the target array based on the first length and the second length, wherein the first parameter is the smallest integer not less than the square root of the first length, and the second parameter is the smallest integer not less than the square root of the second length; in the case where the first parameter is smaller than the second parameter, re-indexing the target array with the second interval as the index interval, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is smaller than the second interval.
[0007] According to another aspect of an embodiment of the present application, a data processing device is also provided, including: a determination module, used to determine the second length according to the first length when it is necessary to append new elements to the target array, wherein the first length is the number of elements in the target array before appending the new elements, and the second length is the number of elements in the target array after appending the new elements; a parameter module, used to determine the first parameter and the second parameter of the target array according to the first length and the second length, wherein the first parameter is the smallest integer not less than the square root of the first length, and the second parameter is the smallest integer not less than the square root of the second length; an index module, used to re-index the target array with the second interval as the index interval when the first parameter is less than the second parameter, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is smaller than the second interval.
[0008] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above method is executed when the program is run.
[0009] According to another aspect of an embodiment of the present application, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above method through the computer program.
[0010] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any one of the embodiments of the above method.
[0011] In an embodiment of the present application, when it is necessary to append new elements to a target array, the second length is determined according to the first length, wherein the first length is the number of elements in the target array before appending the new elements, and the second length is the number of elements in the target array after appending the new elements; according to the first length and the second length, a first parameter and a second parameter of the target array are determined, wherein the first parameter is the smallest integer not less than the square root of the first length, and the second parameter is the smallest integer not less than the square root of the second length; when the first parameter is less than the second parameter, the target array is re-indexed with the second interval as the index interval, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is less than the second interval. By judging whether a boundary condition is met when it is necessary to append elements to the array, re-indexing with a larger index interval when the boundary condition is met, and dynamically adjusting the index in the array as the elements in the array increase, the purpose of reducing the decay rate of the reading speed is achieved, thereby solving the technical problem of the rapid decay of the reading speed of the elements in the array caused by the increasing amount of data in the array. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0013] Figure 1 is a schematic diagram of a hardware environment of a data processing method according to an embodiment of the present application;
[0014] Figure 2 is a flow chart of an optional data processing method according to an embodiment of the present application;
[0015] Figure 3 is a schematic diagram of an optional data processing device according to an embodiment of the present application; and,
[0016] Figure 4 It is a structural block diagram of a terminal according to an embodiment of the present application. DETAILED DESCRIPTION
[0017] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0018] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0019] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretation:
[0020] Array: In this application, an array is an ordered collection of data of the same type. An array describes a number of data of the same type, arranged and combined in a certain order, where each data is called an element, and each element can be accessed through an index (subscript).
[0021] Array length: In this application, array length refers to the number of elements in the array, which increases as the number of elements in the array increases.
[0022] According to one aspect of the embodiments of the present application, a method embodiment of data processing is provided.
[0023] Optionally, in this embodiment, the above data processing method can be applied to Figure 1 In the hardware environment composed of the terminal 101 and the server 103 shown in FIG. Figure 1 As shown, the server 103 is connected to the terminal 101 through a network, and can be used to provide data processing services for the terminal or a client installed on the terminal. A database 105 can be set on the server or independently of the server to provide data storage services for the server 103. The above network includes but is not limited to: a wide area network, a metropolitan area network or a local area network, and the terminal 101 is not limited to a PC, a mobile phone, a tablet computer, etc. The data processing method of the embodiment of the present application can be executed by the server 103, or by the terminal 101, or by the server 103 and the terminal 101. Among them, the terminal 101 executes the data processing method of the embodiment of the present application, and it can also be executed by the client installed thereon. The following is an example of a data processing method of an embodiment of the present application executed on a server.
[0024] Figure 2 is a flow chart of an optional data processing method according to an embodiment of the present application, such as Figure 2 As shown, the method may include the following steps:
[0025] Step S202, when the server needs to append a new element to the target array, the server determines a second length according to the first length, wherein the first length is the number of elements in the target array before appending the new element, and the second length is the number of elements in the target array after appending the new element;
[0026] Step S204: the server determines a first parameter and a second parameter of the target array according to the first length and the second length, wherein the first parameter is the smallest integer not less than the square root of the first length, and the second parameter is the smallest integer not less than the square root of the second length;
[0027] Step S206, when the first parameter is smaller than the second parameter, the server re-indexes the target array with the second interval as the index interval, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is smaller than the second interval.
[0028] Through the above steps S202 to S206, it is determined whether the boundary conditions are met when adding elements to the array. When the boundary conditions are met, the index is re-established with a larger index interval. As the elements in the array are increased, the index in the array is dynamically adjusted, thereby achieving the purpose of reducing the decay rate of the reading speed, and further solving the technical problem of the rapid decay of the reading speed of the elements in the array caused by the continuous increase in the amount of data in the array.
[0029] In the technical solution provided in step S202, when the server needs to append new elements to the target array, the server determines the second length based on the first length, wherein the first length is the number of elements in the target array before appending the new elements, and the second length is the number of elements in the target array after appending the new elements.
[0030] Appending a new element refers to adding a new element to the target array. One or more new elements may be added to the target array. The server may execute step S202 once for each new element added, or once for each several elements added.
[0031] If the server executes step S202 once each time a new element is added, determining the second length based on the first length means adding 1 to the original number of elements in the target array. For example, step S202 is executed once each time an element is added. There are 9 elements in the target array. When a new element needs to be appended to the target array, the second length is determined to be 10 based on the first length of 9.
[0032] If the server executes step S202 once every time a certain number of elements are added, determining the second length based on the first length means adding a certain number of elements to the original number of elements in the target array. For example, step S202 is executed once every time 3 elements are added. There are 9 elements in the target array. When 3 elements need to be added to the target array, the second length is determined to be 12 based on the first length of 9.
[0033] As an optional embodiment, the server may start executing step S202 when the number of elements in the target array exceeds a certain threshold (ie, when there are too many elements in the array resulting in a slow reading speed).
[0034] In the technical solution provided in step S204, the server determines the first parameter and the second parameter of the target array based on the first length and the second length, wherein the first parameter is the smallest integer not less than the square root of the first length, and the second parameter is the smallest integer not less than the square root of the second length.
[0035] The server may calculate the first parameter and the second parameter using a square root operation and a rounding function.
[0036] As an optional embodiment, the server determines the first parameter according to the following formula: D = ceil (sqrt (L 1 )), where D represents the first parameter, L 1 Indicates the first length, ceil(sqrt(L 1 )) indicates that the square root of the first length is rounded upwards; the second parameter is determined according to the following formula: D'=ceil(sqrt(L 2 )), where D' represents the second parameter, L 2 Indicates the second length, ceil(sqrt(L 2 )) means rounding up the square root of the second length.
[0037] In the technical solution provided in step S206, when the first parameter is smaller than the second parameter, the server re-indexes the target array with the second interval as the index interval, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is smaller than the second interval.
[0038] The server may use a variety of boundary conditions to determine the situation where the first parameter is less than the second parameter. For example, D represents the first parameter, and D' represents the second parameter. When D<D', the target array is re-indexed using the second interval as the index interval.
[0039] The first interval is the index interval of the target array before appending new elements, and the second interval is the index interval of the target array after appending new elements. The second interval is larger than the first interval, so that the indexes are evenly distributed in the array after appending new elements, reducing the decay rate of the reading speed.
[0040] For example, before appending new elements, there are 16 elements in the array, the first parameter is 4, the indexes point to the 3rd, 6th, and 9th elements respectively, and the index interval is 3; after appending new elements, there are 17 elements in the array, the second parameter is 5, the first parameter is less than the second parameter, the re-established index ① can point to the 4th, 8th, 12th, and 16th elements respectively, with an index interval of 4, and ② can also point to the 5th, 10th, and 15th elements respectively, with an index interval of 5. When there are 17 elements in the array, the indexes pointing to the 5th, 10th, and 15th elements have an average faster reading speed than the indexes pointing to the 3rd, 6th, and 9th elements.
[0041] As a preferred embodiment, when D'-D≥1, a first-level index is re-established for the target array with the second interval as the index interval, wherein D represents the first parameter, D' represents the second parameter, the second interval is g, the number of indexes of the first-level index is g, and the element corresponding to the block pointed to by the first-level index is the (N*g)th element in the target array, g=(D'-1), and N is a positive integer not greater than g.
[0042] The array is indexed by square division. As the number of elements in the array increases, the number of indexes and the index interval increase synchronously, realizing dynamic adjustment of the index and further reducing the decay rate of the reading speed.
[0043] For example, there are 9 elements in the array originally, the first parameter D=3, and after adding an element, there are 10 elements in the array, the second parameter D′=4, the second interval is g=(4-1)=3, the value of N is 1, 2, 3, and the value of (N*g) is 3, 6, and 9 respectively. The re-established indexes point to the 3rd, 6th, and 9th elements in the array respectively.
[0044] As a preferred embodiment, in the case of D'-D≥1, if the second parameter is greater than the specified threshold, a multi-level index is established in the following manner: the first level index in the multi-level index is re-established for the target array with the second interval as the index interval, wherein the second interval is f, n is a natural number greater than 1; a second-level index is established with the third interval as the first-level index, wherein D represents the first parameter, D' represents the second parameter, the third interval is p, p=f^2, the second-level index is used to skip part of the index in the first-level index, and the third interval is the number of first-level indexes between adjacent second-level indexes.
[0045] As the amount of data continues to increase, the second parameter continues to increase. If the index is still established with g=(D'-1) as the interval, there are still many elements between adjacent indexes. At this time, the reading speed of elements is slow. Therefore, the method of establishing multi-level indexes is adopted to improve the reading speed.
[0046] For example, there are 10,000 elements in the array, the first parameter D=100, and 1 element needs to be added. The second parameter D'=101, and the specified threshold is 100. When n=2, the second interval f=floor((10001-1)^(1 / 4))=10, and the first-level index points to the 10th, 20th...9990th, and 10,000th elements respectively. With the third interval p=10^2=100, the second-level index of the first-level index is established, and the second-level index points to the 100th, 200th...900th, and 1000th first-level indexes respectively (that is, the first-level indexes corresponding to the 1000th, 2000th...9000th, and 10,000th elements). The upper-level index is used to index the interval of the lower-level index, reducing the use of storage space.
[0047] As an optional embodiment, after re-establishing the first-level index for the target array with the second interval as the index interval, the server accesses the i-th element in the target array in the following manner: searching the first-level index for the target index that is closest to the pointed element and the i-th element, where the target index points to the j-th element and j is a natural number not less than i; if the target index exists, access forward starting from the element pointed to by the target index until the i-th element is found; if the target index does not exist, access forward starting from the last element in the target array until the i-th element is found.
[0048] For example, there are 10 elements in the target array, and the indexes in the array point to the 3rd, 6th, and 9th elements respectively. When you need to access the first element, first find the index pointing to the third element that is closest to 1, and then access forward from the third element until you find the first element.
[0049] As an optional embodiment, the server stores the target array in the blockchain, wherein each element in the target array is sequentially stored in consecutive blocks in the blockchain; and a mapping relationship between the array identifier and the array hash of the target array is saved in the contract, wherein the array hash is the transaction hash of the last element of the target array in the blockchain.
[0050] Optionally, when it is necessary to access the target element in the target array through the contract, the array hash is obtained through the array identifier; the array hash is used to access forward to obtain the transaction hash of the target element; and the target element is obtained through the transaction hash of the target element.
[0051] When reading data through a contract, if all data is placed in a smart contract, only one element in the array can be accessed at a time, as the execution of the blockchain contract is single-threaded. In this embodiment, each element in the array is stored in a continuous block in the blockchain in turn, and the reading of the transaction block can be multi-threaded. The mapping relationship between the array identifier and the array hash of the target array is saved by the contract. By accessing the last element in the array, the transaction hash of the last element is used to access other elements, thereby realizing multi-threaded reading and improving the reading speed of the elements in the array.
[0052] As an optional embodiment, the technical solution of the present application is schematically described below in combination with specific implementation methods:
[0053] This solution limits the operations supported by variable-length arrays to the following three: ① Add a new element to the end of an array; ② Read a subscript element of an array; ③ Create a new array.
[0054] For the above operations, the operations on the blockchain are as follows:
[0055] 1. Create a new array: Create a unique variable U inside the contract i , and create a new transaction on the chain at the same time, the transaction hash is T 0 , containing this array U i And other necessary initial information, such as length L, etc. Then create U in the form of map within the contract i and T 0 At the same time, T 0 The necessary initial threshold H must be included, and H is determined based on the estimated maximum possible array size.
[0056] 2. Append a new element A to an array.
[0057] First, for a certain array, you need to use U i To identify, from the contract through U i Get U i T 0 Values, get H and L.
[0058] (1) If L+1≤H, a new transaction is created directly on the chain, including A and the old T 0 (When the forward pointer of the linked list is used) all the information, its transaction hash is T', and the length of the array L inside T' is updated to L+1, and the contract internal U i T 0 Map to T′.
[0059] (2) If L+1>H, let D′=ceil(sqrt(L+1)), D=ceil(sqrt(L))
[0060] ①If D′-D<1, then add as in L≤H.
[0061] ② If D′-D ≥ 1, then in T′, update the index table with intervals of D. For example, the existing data is 1, 2, 3, 4, 5, 6, 7, 8, 9, and their previous corresponding transaction hash is t i Now add 10, and now H = 9, then D′ = ceil(sqrt10) = 4, D = ceil(sqrt(9)) = 3, and D′-D≥1 is satisfied. We need to create an index with D = 3 intervals, and the index is 9 = t 9 ,6=t 6 ,3=t 3 , where the coordinates of the equal sign are array subscripts. Then combine A, L′=L+1 and other information as a new transaction and store it in the new transaction T′. i Map to this new T′.
[0062] ③If the value of D′ is large, such as exceeding H, we can create a secondary index in the same way, and the updated storage space is sqrt(sqrt(L)), and so on. For example, when inserting to L=10001, D′=sqrt(L-1)=100, which exceeds the value of H. We will create indexes like 10000, 9900, 9800,..., but we can directly recursively create indexes of D′=sqrt(100)=10, so that we can use secondary indexes like 10000, 9000, 8000... to reduce the use of storage space. If we create indexes according to the method in ②, as more data is added, there will be more index information in the transaction body, because sqrt(L) becomes larger, and multi-level indexes can be used to point to indexes of similar limited interval sizes (such as H^2), and the upper index is used to index the interval of the lower index, reducing space usage. Multi-level indexes can be created separately and do not have to be embedded in every transaction body. The establishment method is similar to the above, but it is established every time the limited interval size is broken.
[0063] 3. Read the element value of an array with the subscript id.
[0064] According to the contract i Read to T 0If there is no index information, follow the forward pointer and check whether L is equal to id along the previous transaction. If they are equal, directly return the storage value of this transaction. Otherwise, read the index information. For example, in the above example, we need to read id = 1, and the index information is 9 = t 9 ,6=t 6 ,3=t 3 , we can find the 3 closest to 1, and then use t 3 The forward information of id=1 is used to find the storage value. For multi-level indexes, just read along the index until you can find the forward index. And the reading can be multi-threaded concurrently, which greatly improves the attenuation of contract performance.
[0065] This solution determines whether the boundary conditions are met when adding elements to the array. When the boundary conditions are met, the index is re-established with a larger index interval, so that the index is evenly distributed in the array after the new element is added. As the elements in the array increase, the index in the array is dynamically adjusted, thereby achieving the purpose of reducing the decay rate of the reading speed, thereby solving the technical problem of the rapid decay of the reading speed of the elements in the array caused by the continuous increase in the amount of data in the array; in addition, the square division method is used to establish the index for the array. As the number of elements in the array increases, the number of indexes and the index interval increase synchronously, realizing the dynamic adjustment of the index, and further reducing the decay rate of the reading speed; when the amount of data increases to a certain value, the index is adjusted dynamically, and the decay rate of the reading speed is further reduced. When the degree of storage is determined, a multi-level index is established to improve the reading speed; each element in the array is stored in a continuous block in the blockchain in turn, and the mapping relationship between the array identifier and the array hash of the target array is saved in the contract by taking advantage of the multi-threaded reading of the transaction block. By accessing the block of the last element in the array, multi-threaded access to other elements is achieved by the transaction hash of the last element, thereby realizing multi-threaded reading and improving the reading speed of elements in the array; in batch appending, the read parallel feature can be used for acceleration, the index decay level is sqrt(n), and there is no increase in algorithm constants, which realizes efficient element appending and very slow appending performance decay.
[0066] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0067] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0068] According to another aspect of an embodiment of the present application, a data processing device for implementing the above data processing method is also provided. Figure 3 is a schematic diagram of an optional data processing device according to an embodiment of the present application, such as Figure 3 As shown, the device may include:
[0069] A determination module 32, configured to determine a second length according to the first length when a new element needs to be added to the target array, wherein the first length is the number of elements in the target array before the new element is added, and the second length is the number of elements in the target array after the new element is added;
[0070] A parameter module 34, configured to determine a first parameter and a second parameter of a target array according to the first length and the second length, wherein the first parameter is a minimum integer not less than a square root of the first length, and the second parameter is a minimum integer not less than a square root of the second length;
[0071] The index module 36 is used to re-index the target array with the second interval as the index interval when the first parameter is smaller than the second parameter, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is smaller than the second interval.
[0072] It should be noted that the determination module 32 in this embodiment can be used to execute step S202 in the embodiment of the present application, the parameter module 34 in this embodiment can be used to execute step S204 in the embodiment of the present application, and the index module 36 in this embodiment can be used to execute step S206 in the embodiment of the present application.
[0073] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware.
[0074] Through the above modules, the technical problem of the rapid decrease in the reading speed of elements in the array caused by the continuous increase in the amount of data in the array can be solved.
[0075] As an optional embodiment, the determination module 32 further includes: a first determination unit, configured to determine the first parameter according to the following formula: D = ceil (sqrt (L 1 )), where D represents the first parameter, L 1 Indicates the first length, ceil(sqrt(L 1 )) indicates that the square root of the first length is rounded upwards; the second determining unit determines the second parameter according to the following formula: D'=ceil(sqrt(L 2 )), where D' represents the second parameter, L 2 Indicates the second length, ceil(sqrt(L 2 )) means rounding up the square root of the second length.
[0076] Optionally, the index module 36 also includes: a first index unit, used to re-establish a first-level index for the target array with the second interval as the index interval when D'-D≥1, wherein the second interval is g, the number of indexes of the first-level index is g, and the element corresponding to the block pointed to by the first-level index is the (N*g)th element in the target array, g=(D'-1), and N is a positive integer not greater than g.
[0077] Optionally, the index module 36 further includes: a second index unit, in the case of D'-D≥1, if the second parameter is greater than a specified threshold, establishes a multi-level index in the following manner: re-establishes a first-level index in the multi-level index for the target array with the second interval as the index interval, wherein the second interval is f, n is a natural number greater than 1; a second-level index is established with the third interval as the first-level index, wherein the third interval is p, p=f^2, the second-level index is used to skip part of the index in the first-level index, and the third interval is the number of first-level indexes between adjacent second-level indexes.
[0078] As an optional embodiment, the first index unit is also used to: after re-establishing a first-level index for the target array with the second interval as the index interval, access the i-th element in the target array in the following manner: search from the first-level index for the target index that is closest to the pointed element and the i-th element, where the target index points to the j-th element, and j is a natural number not less than i; if the target index exists, access forward from the element pointed to by the target index until the i-th element is found; if the target index does not exist, access forward from the last element in the target array until the i-th element is found.
[0079] As an optional embodiment, the determination module 32 is also used to: store the target array in the blockchain, wherein each element in the target array is stored in sequence in consecutive blocks in the blockchain; a mapping module is used to save the mapping relationship between the array identifier and the array hash of the target array in the contract, wherein the array hash is the transaction hash of the last element of the target array in the blockchain.
[0080] Optionally, the determination module 32 is further used to: obtain the array hash through the array identifier when it is necessary to access the target element in the target array through the contract; use the array hash to access forward to obtain the transaction hash of the target element; obtain the target element through the transaction hash of the target element.
[0081] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.
[0082] According to another aspect of the embodiments of the present application, a server or terminal for implementing the above data processing method is also provided.
[0083] Figure 4 is a structural block diagram of a terminal according to an embodiment of the present application, such as Figure 4 As shown, the terminal may include: one or more ( Figure 4 (only one is shown) processor 401, memory 403, and transmission device 405, as shown in Figure 4 As shown, the terminal may also include an input and output device 407.
[0084] Among them, the memory 403 can be used to store software programs and modules, such as program instructions / modules corresponding to the data processing method and device in the embodiment of the present application. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 403, that is, realizing the above-mentioned data processing method. The memory 403 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 403 may further include a memory remotely arranged relative to the processor 401, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0085] The above-mentioned transmission device 405 is used to receive or send data via a network, and can also be used for data transmission between a processor and a memory. Specific examples of the above-mentioned network may include a wired network and a wireless network. In one example, the transmission device 405 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 405 is a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.
[0086] Specifically, the memory 403 is used to store application programs.
[0087] The processor 401 can call the application stored in the memory 403 through the transmission device 405 to perform the following steps: when it is necessary to append new elements to the target array, determine the second length based on the first length, wherein the first length is the number of elements in the target array before appending the new elements, and the second length is the number of elements in the target array after appending the new elements; determine the first parameter and the second parameter of the target array based on the first length and the second length, wherein the first parameter is the smallest integer not less than the square root of the first length, and the second parameter is the smallest integer not less than the square root of the second length; when the first parameter is less than the second parameter, re-index the target array with the second interval as the index interval, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is smaller than the second interval.
[0088] By using the embodiment of the present application, a data processing solution is provided. By determining whether a boundary condition is met when adding elements to an array, re-establishing the index with a larger index interval when the boundary condition is met, and dynamically adjusting the index in the array as the elements in the array increase, the purpose of reducing the decay rate of the reading speed is achieved, thereby solving the technical problem of the rapid decay of the reading speed of the elements in the array caused by the continuous increase in the amount of data in the array.
[0089] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0090] It can be understood by those skilled in the art that Figure 4 The structure shown is for illustration only, and the terminal may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, or other terminal devices. Figure 4It does not limit the structure of the above electronic device. For example, the terminal may also include Figure 4 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 4 Different configurations are shown.
[0091] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0092] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to execute the program code of the data processing method.
[0093] Optionally, in this embodiment, the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.
[0094] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:
[0095] S1, when it is necessary to append a new element to the target array, determine the second length according to the first length, wherein the first length is the number of elements in the target array before appending the new element, and the second length is the number of elements in the target array after appending the new element;
[0096] S2, determining a first parameter and a second parameter of the target array according to the first length and the second length, wherein the first parameter is a minimum integer not less than the square root of the first length, and the second parameter is a minimum integer not less than the square root of the second length;
[0097] S3, when the first parameter is smaller than the second parameter, re-indexing the target array with the second interval as the index interval, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is smaller than the second interval.
[0098] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0099] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0100] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0101] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0102] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0103] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0104] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0105] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0106] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A data processing method, characterized in that: include: In the case where a new element needs to be appended to the target array, the second length is determined according to the first length, wherein the first length is the number of elements in the target array before the new element is appended, and the second length is the number of elements in the target array after the new element is appended; Determine a first parameter and a second parameter of the target array according to the first length and the second length, wherein the first parameter is a minimum integer not less than the square root of the first length, and the second parameter is a minimum integer not less than the square root of the second length; In the case where the first parameter is less than the second parameter, the target array is re-indexed with the second interval as the index interval, wherein the index interval of the target array before re-indexing is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is less than the second interval; the target array is indexed by square division, and the indexes are evenly distributed in the target array after the new elements are appended, and as the number of elements in the target array increases, the number of indexes and the index interval increase synchronously.
2. The method according to claim 1, characterized in that Determining a first parameter and a second parameter of the target array according to the first length and the second length includes: The first parameter is determined according to the following formula: D=ceil(sqrt(L1)), wherein D represents the first parameter, L1 represents the first length, and ceil(sqrt(L1)) represents rounding up the square root of the first length; The second parameter is determined according to the following formula: D'=ceil(sqrt(L2)), wherein D' represents the second parameter, L2 represents the second length, and ceil(sqrt(L2)) represents rounding up the square root of the second length.
3. The method according to claim 2, characterized in that When the first parameter is less than the second parameter, re-indexing the target array with the second interval as the index interval includes: When D'-D≥1, a first-level index is re-established for the target array with the second interval as the index interval, wherein the second interval is g, the number of indexes of the first-level index is g, the element corresponding to the block pointed to by the first-level index is the (N*g)th element in the target array, g=(D'-1), and N is a positive integer not greater than g.
4. The method according to claim 2, characterized in that: When the first parameter is less than the second parameter, re-indexing the target array with the second interval as the index interval includes: In the case of D'-D≥1, if the second parameter is greater than a specified threshold, a multi-level index is established in the following manner: a first-level index in the multi-level index is re-established for the target array with the second interval as the index interval, wherein the second interval is f, n is a natural number greater than 1; a second-level index is established for the first-level index with a third interval, wherein the third interval is p, p=f^2, the second-level index is used to skip part of the indexes in the first-level index, and the third interval is the number of first-level indexes between adjacent second-level indexes.
5. The method according to claim 3, characterized in that: After re-establishing a primary index for the target array with the second interval as the index interval, the method further includes accessing the i-th element in the target array in the following manner: Search the target index that points to the element closest to the i-th element from the primary index, where the target index points to the j-th element, and j is a natural number not less than i; If the target index exists, access forward from the element pointed to by the target index until the i-th element is found; If the target index does not exist, access forward from the last element in the target array until the i-th element is found.
6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: Storing the target array in a blockchain, wherein each element in the target array is sequentially stored in consecutive blocks in the blockchain; The mapping relationship between the array identifier of the target array and the array hash is saved in the contract, wherein the array hash is the transaction hash of the last element of the target array in the blockchain.
7. The method according to claim 6, characterized in that The method further comprises: When it is necessary to access the target element in the target array through the contract, the array hash is obtained through the array identifier; Using the array hash to access forward, obtain the transaction hash of the target element; The target element is obtained by using the transaction hash of the target element.
8. A data processing device, characterized in that: include: A determination module, configured to determine a second length according to the first length when a new element needs to be appended to the target array, wherein the first length is the number of elements in the target array before the new element is appended, and the second length is the number of elements in the target array after the new element is appended; a parameter module, configured to determine a first parameter and a second parameter of the target array according to the first length and the second length, wherein the first parameter is a minimum integer not less than a square root of the first length, and the second parameter is a minimum integer not less than a square root of the second length; An indexing module is used to re-establish the index for the target array with the second interval as the index interval when the first parameter is less than the second parameter, wherein the index interval of the target array before re-establishing the index is the first interval, the index interval is the interval between elements pointed to by adjacent indexes, and the first interval is less than the second interval; the target array is indexed by square division, and the indexes are evenly distributed in the target array after the new elements are appended, and as the number of elements in the target array increases, the number of indexes and the index interval increase synchronously.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: The processor executes the method according to any one of claims 1 to 7 through the computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the data processing method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Updating method and device for index table
CN106796588A
Index establishment method and device, electronic equipment, computer storage medium and program
CN108229358A