Data processing method and device, electronic device, and storage medium
By setting a specified number of random pointers for each element in the element queue and setting it to uniformly distribute when the access speed decreases, the problem of inefficient random subscript access on the blockchain is solved, and the access speed is improved.
Patent Information
- Application Number
- CN202111597952.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-12-24
AI Technical Summary
Due to the large amount of data, the access efficiency of random subscript access on the blockchain is low, and the existing technology has not been effectively solved.
Set a specified number of random pointers for each element in the element queue. When the access speed decreases, set the random pointer of the next element to a uniformly distributed pointer. By setting a specified number of random pointers for each element in the element queue, random subscript access is performed, and when the access speed decreases, set the random pointer of the next element to a uniformly distributed pointer.
This improves performance degradation caused by randomization, improves access speed, and solves the problem of low access efficiency of random subscripts due to large data volume.
Smart Images

Figure CN114443044B_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 being used for data storage. Currently, storing data like variable-length arrays on blockchains generally relies on smart contracts. Random index access can be accomplished using arrays within the contract. However, due to inherent flaws in smart contracts, access efficiency decreases as data grows.
[0003] Currently, no effective solution has been proposed to the problem of low access efficiency of random index access due to the large amount of data. Summary of the Invention
[0004] 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 related technologies of low access efficiency of random index access due to large data volume.
[0005] According to one aspect of an embodiment of the present application, a data processing method is provided, including: obtaining a second element to be inserted after a first element, wherein the first element is located at the tail of an element queue stored in a container, the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1; when the access speed to elements in the element queue does not decrease, the second element is inserted after the first element, and each pointer of the H random pointers of the second element is randomly set to point to an element in the element queue that is located before the first element; when the access speed to elements in the element queue decreases, the second element is inserted after the first element, and the H random pointers of the second element are set to evenly point to the H elements in the element queue that are located before the first element.
[0006] According to another aspect of an embodiment of the present application, a data processing device is also provided, including: an element acquisition module, used to acquire a second element to be inserted after a first element, wherein the first element is located at the tail of an element queue stored in a container, and the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1; a first insertion module, used to insert the second element after the first element without decreasing the access speed to the elements in the element queue, and randomly set each pointer of the H random pointers of the second element to point to an element in the element queue that is located before the first element; a second insertion module, used to insert the second element after the first element when the access speed to the elements in the element queue decreases, and set the H random pointers of the second element to evenly point to the H elements in the element queue that are located before the first element.
[0007] 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.
[0008] According to another aspect of an embodiment of the present application, an electronic device is 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.
[0009] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps of any of the above-described method embodiments.
[0010] In an embodiment of the present application, a method is adopted to obtain a second element to be inserted after a first element, wherein the first element is located at the tail of an element queue stored in a container, the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1; when the access speed to the elements in the element queue does not decrease, the second element is inserted after the first element, and each pointer of the H random pointers of the second element is randomly set to point to an element in the element queue that is located before the first element; when the access speed to the elements in the element queue decreases, the second element is inserted after the first element, and the H random pointers of the second element are set to uniformly point to the H elements in the element queue that are located before the first element; by setting a specified number of random pointers for each element in the element queue, random subscript access is performed, and when the access speed decreases, the random pointer of the next element is set to a uniformly distributed pointer, thereby improving the performance degradation caused by randomization, achieving the purpose of speeding up the access speed, and thus solving the technical problem of low access efficiency of random subscript access due to a large amount of data. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] 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:
[0012] Figure 1 is a schematic diagram of a hardware environment of a data processing method according to an embodiment of the present application;
[0013] Figure 2 is a flowchart of an optional data processing method according to an embodiment of the present application;
[0014] Figure 3 is a schematic diagram of an optional data processing device according to an embodiment of the present application; and
[0015] Figure 4 This is a structural block diagram of a terminal according to an embodiment of the present application. DETAILED DESCRIPTION
[0016] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0017] 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 sequential order. 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 a sequence 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.
[0018] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretations:
[0019] Container: In this application, a container refers to an object that holds or contains a group of elements.
[0020] Element queue: In this application, an element queue is an ordered collection 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] Random pointers: In this application, the node where each element is located contains a specified number of random pointers, which can point to the nodes where the elements before the element are located in the element queue.
[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 via 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-mentioned network includes but is not limited to: a wide area network, a metropolitan area network or a local area network. 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 or it can be executed by the client installed thereon. The following description will be made by taking a data processing method of the embodiment of the present application executed on a server as an example.
[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: The server obtains a second element to be inserted after the first element, wherein the first element is located at the end of an element queue stored in the container, and the first element has H random pointers, each of which points to an element in the element queue that is located before the first element, where H is a natural number greater than 1.
[0026] Step S204: If the access speed to the elements in the element queue does not decrease, the server inserts the second element after the first element and randomly sets each of the H random pointers of the second element to point to an element in the element queue that is located before the first element.
[0027] Step S206: When the access speed to the elements in the element queue decreases, the server inserts the second element after the first element and sets the H random pointers of the second element to evenly point to the H elements before the first element in the element queue.
[0028] Through the above steps S202 to S206, a specified number of random pointers are set for each element to perform random index access. When the access speed decreases, the random pointer of the next element is set to a uniformly distributed pointer, thereby improving the performance degradation caused by randomization and achieving the purpose of speeding up the access speed, thereby solving the technical problem of low access efficiency of random index access due to large data volume.
[0029] In the technical solution provided in step S202, the server obtains the second element to be inserted after the first element, wherein the first element is located at the tail of the element queue stored in the container, and the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1.
[0030] The server may execute step S202 each time an element is inserted. If the number of elements in the element queue before inserting the second element is L, the first element is the Lth element in the element queue. When L≤H, the number of random pointers possessed by the first element is less than H. The random pointers point to the elements preceding the Lth element, which may include or exclude the previous element of the first element, because access to the previous element of an element in the element queue may be achieved without using random pointers.
[0031] For example, if there are 4 elements in the element queue, H=4, the first element is the 4th element in the element queue, and the H random pointers of the first element can be 2 random pointers pointing to the 1st and 2nd elements respectively, or 3 random pointers pointing to the 1st, 2nd, and 3rd elements respectively.
[0032] The server may resume execution of step S202 when the number of elements in the element queue exceeds a specified threshold. Each element has random pointers that point to H different elements. For example, the server resumes execution of step S202 when the number of elements in the element queue exceeds H. When H = 9, the first element is the tenth element in the element queue. The first element has nine random pointers that point to nine different elements before the first element in the element queue.
[0033] In the technical solution provided in step S204, when the access speed to the elements in the element queue does not decrease, the server inserts the second element after the first element, and randomly sets each of the H random pointers of the second element to point to an element in the element queue that is located before the first element.
[0034] The access speed to elements in the element queue can be determined in a variety of ways, including but not limited to the following: 1) based on the access speed of a certain access, for example, based on the access speed of the most recent access record; 2) based on the average access speed of multiple accesses, for example, based on the average access speed of the most recent 5 access records.
[0035] There are many ways to determine whether the access speed has decreased, including but not limited to the following: ① comparing the access speed of the access with the later access time with the access with the earlier access time; ② setting a preset standard access speed, and determining that the access speed has decreased when the access speed is lower than the standard access speed.
[0036] As an optional embodiment, the server randomly sets each of the H random pointers of the second element to point to an element in the element queue that is located before the first element, and each of the H random pointers of the second element points to the Nth element in the element queue, where N is a positive integer not greater than L, and L is the number of elements in the element queue before the second element is inserted.
[0037] In order to avoid storing the same random pointer, the random pointer can be set as follows: use a positive integer strictly smaller than L as the first value range (since an element can directly access its previous element in the element queue without using a random pointer, the value range does not need to include L), randomly take out a value from the first value range, and record the remaining values as the second value range, then randomly take out a value from the second value range, and record the remaining values as the second value range... After H times of taking values, H non-repeating positive integers N1, N2...N that are strictly smaller than L are obtained. H ; Set H random pointers to point to the N1, N2...N in the element queue respectively H A random pointer to an element.
[0038] In the technical solution provided in step S206, when the access speed to the elements in the element queue decreases, the server inserts the second element after the first element, and sets the H random pointers of the second element to evenly point to the H elements before the first element in the element queue.
[0039] As an optional embodiment, the server sets the H random pointers of the second element to point evenly to the H elements before the first element in the element queue, and each of the H random pointers of the second element points to the Nth element in the element queue, where N = k*floor(L / H), k is a positive integer and k≤H, L is the number of elements in the element queue before the second element is inserted, and floor(L / H) means rounding down the quotient of L divided by H.
[0040] In this embodiment, H random pointers are respectively set to point to the N1, N2...N H elements, floor(L / H) represents the interval between the elements pointed to by adjacent random pointers. For example, L=100 and H=9, then floor(L / H)=11, and the H random pointers are set to point to the 11th, 22nd, 33rd, 44th, 55th, 66th, 77th, 88th, and 99th elements in the element queue respectively.
[0041] The server may determine the value of N by using a calculation method including but not limited to N=k*floor(L / H), as long as the H random pointers evenly point to the elements in the element queue.
[0042] As an optional embodiment, the server can access the elements in the element queue in the following manner: when it is necessary to access the i-th element in the element queue, starting from the last element in the element queue, search for the target random pointer in the H random pointers of the element, where each pointer in the H random pointers of an element points to the N-th element in the element queue, and the target random pointer is a random pointer among the H random pointers that points to an element closest to the i-th element and not before the i-th element; skip some elements in the element queue to access the j-th element pointed to by the target random pointer, where j∈N and j is a positive integer not less than i; starting from the j-th element pointed to by the target random pointer, continue to search for the target random pointer in the H random pointers of the element until the i-th element is found.
[0043] For example, there are 13 elements in the element queue, H=3, and now the 5th element needs to be accessed. If the 3 random pointers of the 13th element point to the 4th, 8th, and 12th elements respectively, then find the first value not less than 5 in the order of 4, 8, and 12 from small to large, and the target random pointer is the random pointer pointing to the 8th element, and the 8th element is accessed. If the 3 random pointers of the 8th element point to the 1st, 3rd, and 6th elements respectively, then find the first value not less than 5 in the order of 1, 3, and 6 from small to large, and the target random pointer is the random pointer pointing to 6, and the 6th element is accessed. If the 3 random pointers of the 6th element point to the 2nd, 3rd, and 4th elements respectively, and there is no target random pointer that meets the conditions, then access from the 6th element forward to the 5th element, completing this element access.
[0044] Optionally, access information of this access to the i-th element is recorded, wherein the access information includes access speed information; an access speed index for this access to the i-th element is determined based on the access speed information, and the access speed index is used to indicate whether the access speed to the i-th element in the element queue has decreased.
[0045] The access speed information includes the number of access steps. If the number of access steps is greater than a specified threshold, the access speed indicator is determined to be a decrease in the access speed to the elements in the element queue. If the number of access steps is not greater than the specified threshold, the access speed indicator is determined to be a constant in the access speed to the elements in the element queue. The number of access steps refers to the total number of elements accessed from the last element to the i-th element. For example, if i = 5, starting from the 13th element, the random pointer accesses the 8th element, then the random pointer accesses the 6th element, and finally the forward access completes the access to the 5th element. The 8th, 6th, and 5th elements are accessed in sequence, and the number of access steps is 3.
[0046] The access speed information may also include access duration. If the access duration exceeds a specified threshold, the access speed indicator is determined to indicate a decrease in the access speed to elements in the element queue. If the access duration is within the specified threshold, the access speed indicator is determined to indicate no decrease in the access speed to elements in the element queue. The access duration refers to the total time elapsed from the last element to the i-th element.
[0047] Before inserting a new element each time, the server queries whether the existing random pointers can meet the speed requirements of random index access and access the elements at an access speed greater than a certain threshold. If the current access speed is slow, it means that the current random pointers may be too concentrated. When inserting new elements, it is necessary to set the random pointers to point evenly to other elements to improve access speed.
[0048] Optionally, before inserting the first element into the second element, the server may obtain information about whether the access speed to the elements in the element queue has decreased in the following manner: search for target access information, where the access information also includes an access starting point, and the target access information is the access information of the last access with the first element as the access starting point, and the access starting point is the last element in the element queue when the element is accessed; determine whether the access speed to the elements in the element queue has decreased based on the access speed indicator in the target access information.
[0049] For example, the first element is the 50th element in the element queue, and the server saves multiple access information, including access information before the first element is inserted and access information after the first element is inserted. Among them, the access information after the first element is inserted takes the 50th element (the last element in the element queue at the time of access) as the access starting point. In the last access with the 50th element as the access starting point, the access speed indicator is "the access speed to the i-th element in the element queue has decreased", and the search result is obtained, which is "the access speed to the elements in the element queue has decreased".
[0050] As an optional embodiment, the technical solution of the present application is schematically described below in conjunction with specific implementation methods:
[0051] Subscript access is defined as being able to access the value of A[i] for a container A, where i is an integer.
[0052] This solution provides the following two methods for container operations: let the number of elements in the container be L, 1. provide a method for inserting values with subscript L+1, 2. provide a method for accessing values with subscripts 1 to L.
[0053] The contract records a hash value inside to point to the transaction hash of the last element, denoted as T, and then uses f to record whether the last search was slow. The initial value is false.
[0054] Let the storage threshold be H, where each transaction storage unit stores a stored value (i.e., an element) and H random pointers that point to H different transaction hashes with subscripts less than this storage unit.
[0055] 1. Insert a new element X:
[0056] Obtain the latest T from the contract, and let the subscript of the currently inserted element be L.
[0057] If f is false, randomly select H positive numbers that are strictly less than L (if L - 1 < H, just take all of them). Then find the hashes of these H subscript values along T and store them in a new transaction, and obtain the new transaction hash T' and update it to the contract.
[0058] If f is true, let D = floor(L / H), then the subscripts of the H hashes inserted this time are 1, D, 2D,..., D * H. This step is mainly used to determine the subscripts and prevent performance degradation caused by randomization.
[0059] 2. Search for the value of the subscript id:
[0060] Obtain T, that is, the transaction information of the last subscript. In the order of the subscripts of the H hashes from smallest to largest, find the first subscript hash t that is greater than id, and then repeat the above steps along t until the value stored in the transaction body with subscript t is found. During this query process, if it is found that the query time or the number of index accesses is greater than the threshold, set the value of f to true for this access, and leave it for adjustment during the next insertion, otherwise set f to false.
[0061] Using the above two methods, ① it can be efficiently appended, the append performance decay is very slow, and the time and number of index accesses have the opportunity to be dynamically adjusted; ② the read efficiency decay is very slow and can be adaptively adjusted; ③ the contract storage cannot be read in multiple threads, but here with the transaction hash of the last element, parallel queries can be performed, and the reading can be in multiple threads, which improves the multi-threaded reading efficiency.
[0062] This solution sets a specified number of random pointers for each element in the element queue, and the storage space consumed is controllable. Random pointers that are not set to be evenly distributed can speed up access in some accesses, but may not accelerate elements in other ranges due to their concentrated distribution in certain ranges. When the access speed drops, the random pointer of the next element is set to a uniformly distributed pointer to improve the performance degradation caused by randomization; each time a new element is appended and a random pointer is set for it, the current access speed is judged, and different random pointer setting methods are used according to the judgment results to achieve adaptive adjustment, so that the time and number of index accesses have the opportunity to be dynamically adjusted; the data is stored in each transaction storage unit of the blockchain instead of the contract, the transaction hash of the last element is obtained through the contract, and then the transaction hash of the last element is used to achieve multi-threaded access to other elements, thereby realizing multi-threaded reading and improving the data reading speed.
[0063] 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 this application is not limited by the order of the actions described, because according to this 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 this application.
[0064] 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 the necessary general hardware platform, and of course it can also be implemented 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 enabling 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.
[0065] According to another aspect of the embodiments of the present application, a data processing device for implementing the above-mentioned 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:
[0066] an element acquisition module 32, configured to acquire a second element to be inserted after a first element, wherein the first element is at the end of an element queue stored in the container, the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1;
[0067] A first insertion module 34 is configured to insert a second element after the first element without decreasing the access speed to the elements in the element queue, and randomly set each of the H random pointers of the second element to point to an element in the element queue that is located before the first element;
[0068] The second insertion module 36 is used to insert the second element after the first element when the access speed to the elements in the element queue decreases, and set the H random pointers of the second element to evenly point to the H elements before the first element in the element queue.
[0069] It should be noted that the element acquisition module 32 in this embodiment can be used to execute step S202 in the embodiment of the present application, the first insertion module 34 in this embodiment can be used to execute step S204 in the embodiment of the present application, and the second insertion module 36 in this embodiment can be used to execute step S206 in the embodiment of the present application.
[0070] 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. Figure 1 In the hardware environment shown, it can be implemented by software or by hardware.
[0071] Through the above module, a specified number of random pointers are set for each element in the element queue for random index access. When the access speed decreases, the random pointer of the next element is set to a uniformly distributed pointer, thereby improving the performance degradation caused by randomization and achieving the purpose of speeding up access. This solves the technical problem of low access efficiency of random index access due to large data volume.
[0072] As an optional embodiment, the first insertion module 34 is further used to: randomly set each of the H random pointers of the second element to point to an element in the element queue that is located before the first element, and each of the H random pointers of the second element points to the Nth element in the element queue, where N is a positive integer not greater than L, and L is the number of elements in the element queue before the second element is inserted.
[0073] As an optional embodiment, the second insertion module 36 is further used to: set the H random pointers of the second element to evenly point to the H elements before the first element in the element queue, and each of the H random pointers of the second element points to the Nth element in the element queue, where N = k*floor(L / H), k is a positive integer and k≤H, L is the number of elements in the element queue before the second element is inserted, and floor(L / H) means rounding down the quotient of L divided by H.
[0074] As an optional embodiment, the data processing device is also used to: when it is necessary to access the i-th element in the element queue, starting from the last element in the element queue, search for the target random pointer in the H random pointers of the element, wherein each of the H random pointers of an element points to the N-th element in the element queue, and the target random pointer is a random pointer among the H random pointers that points to an element closest to the i-th element and not before the i-th element; skip some elements in the element queue to access the j-th element pointed to by the target random pointer, wherein j∈N and j is a positive integer not less than i; starting from the j-th element pointed to by the target random pointer, continue to search for the target random pointer in the H random pointers of the element until the i-th element is found.
[0075] Optionally, the data processing device is also used to: after finding the i-th element, record the access information of this access to the i-th element, wherein the access information includes access speed information; determine the access speed index of this access to the i-th element based on the access speed information, and the access speed index is used to indicate whether the access speed to the i-th element in the element queue has decreased.
[0076] Optionally, the data processing device is also used to: determine an access speed indicator based on access speed information, the access speed information includes the number of access steps, and when the number of access steps is greater than a specified threshold, determine the access speed indicator as that the access speed to the elements in the element queue has decreased; when the number of access steps is not greater than the specified threshold, determine the access speed indicator as that the access speed to the elements in the element queue has not decreased.
[0077] Optionally, the data processing device is also used to: before inserting the first element into the second element, search for target access information, wherein the access information also includes an access starting point, and the target access information is the access information of the last access with the first element as the access starting point, and the access starting point is the last element in the element queue when the element is accessed; and determine whether the access speed to the elements in the element queue has decreased based on the access speed indicator in the target access information.
[0078] 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. Figure 1 The hardware environment shown can be implemented through software or hardware, wherein the hardware environment includes a network environment.
[0079] According to another aspect of the embodiments of the present application, a server or terminal for implementing the above-mentioned data processing method is also provided.
[0080] 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 Figure 4 As shown, the terminal may further include input and output devices 407 .
[0081] Among them, the memory 403 can be used to store software programs and modules, such as the 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 a combination thereof.
[0082] The 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 embodiment, the transmission device 405 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and a router via a network cable so as to communicate with the Internet or a local area network. In one embodiment, the transmission device 405 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0083] Specifically, the memory 403 is used to store application programs.
[0084] The processor 401 can call the application stored in the memory 403 through the transmission device 405 to perform the following steps: obtain the second element to be inserted after the first element, wherein the first element is located at the end of the element queue stored in the container, and the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1; when the access speed to the elements in the element queue does not decrease, the second element is inserted after the first element, and each pointer of the H random pointers of the second element is randomly set to point to an element in the element queue that is located before the first element; when the access speed to the elements in the element queue decreases, the second element is inserted after the first element, and the H random pointers of the second element are set to evenly point to the H elements in the element queue that are located before the first element.
[0085] The present invention provides a data processing solution by setting a specified number of random pointers for each element in an element queue for random index access. If access speed decreases, the random pointer for the next element is set to a uniformly distributed pointer, thereby improving the performance degradation caused by randomization and achieving faster access speed. This solves the technical problem of low access efficiency of random index access due to large data volumes.
[0086] 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.
[0087] 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 4 It 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 with Figure 4 Different configurations shown.
[0088] A person skilled in the art will 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, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0089] 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.
[0090] Optionally, in this embodiment, the above-mentioned storage medium may be located on at least one network device among the multiple network devices in the network shown in the above-mentioned embodiment.
[0091] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:
[0092] S1, obtain the second element to be inserted after the first element, wherein the first element is at the end of the element queue stored in the container, the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1;
[0093] S2, when the access speed to the elements in the element queue does not decrease, insert the second element after the first element, and randomly set each of the H random pointers of the second element to point to an element in the element queue that is located before the first element;
[0094] S3, when the access speed to the elements in the element queue decreases, insert the second element after the first element, and set the H random pointers of the second element to evenly point to the H elements before the first element in the element queue.
[0095] 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.
[0096] 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.
[0097] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0098] 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-mentioned 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 can be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in each embodiment of the present application.
[0099] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0100] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, 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, and can be electrical or other forms.
[0101] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0102] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0103] 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: Get a second element to be inserted after a first element, where the first element is at the end of an element queue stored in a container, the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1; In a case where access speed to elements in the element queue does not decrease, inserting the second element after the first element, and randomly setting each of the H random pointers of the second element to point to an element in the element queue that is located before the first element; When the access speed to the elements in the element queue decreases, the second element is inserted after the first element, and the H random pointers of the second element are set to evenly point to the H elements in the element queue that are located before the first element.
2. The method according to claim 1, characterized in that Randomly setting each of the H random pointers of the second element to point to an element in the element queue that precedes the first element includes: Each of the H random pointers of the second element points to the Nth element in the element queue, where N is a positive integer not greater than L, and L is the number of elements in the element queue before the second element is inserted.
3. The method according to claim 1, characterized in that Setting the H random pointers of the second element to evenly point to the H elements preceding the first element in the element queue includes: Each of the H random pointers of the second element points to the Nth element in the element queue, where N = k*floor(L / H), k is a positive integer and k≤H, L is the number of elements in the element queue before inserting the second element, and floor(L / H) means rounding down the quotient of L divided by H.
4. The method according to any one of claims 1 to 3, characterized in that The method further includes accessing elements in the element queue as follows: When it is necessary to access the i-th element in the element queue, starting from the last element in the element queue, searching for a target random pointer in the H random pointers of the element, wherein each of the H random pointers of an element points to the N-th element in the element queue, and the target random pointer is a random pointer of the H random pointers that is closest to the i-th element and not before the i-th element; Skip some elements in the element queue to access the j-th element pointed to by the target random pointer, where j∈N and j is a positive integer not less than i; Starting from the j-th element pointed to by the target random pointer, continue searching for the target random pointer among the H random pointers of the elements until the i-th element is found.
5. The method according to claim 4, characterized in that After finding the i-th element, the method further includes: Recording access information of the current access to the i-th element, wherein the access information includes access speed information; An access speed index for accessing the i-th element this time is determined according to the access speed information, where the access speed index is used to indicate whether an access speed to the i-th element in the element queue decreases.
6. The method according to claim 5, characterized in that Determining an access speed index based on the access speed information, the method further includes: The access speed information includes the number of access steps. When the number of access steps is greater than a specified threshold, the access speed indicator is determined to be that the access speed to the elements in the element queue has decreased. When the number of access steps is not greater than the specified threshold, the access speed indicator is determined to be that the access speed to the elements in the element queue has not decreased.
7. The method according to claim 5, characterized in that Before inserting the second element after the first element, the method further includes: Searching for target access information, wherein the access information further includes an access starting point, the target access information is access information of the last access with the first element as the access starting point, and the access starting point is the last element in the element queue when accessing the element; According to the access speed indicator in the target access information, it is determined whether the access speed to the elements in the element queue decreases.
8. A data processing device, characterized in that: include: an element acquisition module, configured to acquire a second element to be inserted after a first element, wherein the first element is located at the end of an element queue stored in a container, the first element has H random pointers, each random pointer of the first element points to an element in the element queue that is located before the first element, and H is a natural number greater than 1; a first insertion module, configured to insert the second element after the first element without decreasing the access speed to the elements in the element queue, and randomly set each of the H random pointers of the second element to point to an element in the element queue that is located before the first element; The second insertion module is used to insert the second element after the first element when the access speed to the elements in the element queue decreases, and set the H random pointers of the second element to evenly point to the H elements in the element queue that are located before the first element.
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
Linked list create method and system and data search method and system
CN102117278A
Queue access method and device
CN103793267A