A data search method, device, equipment and storage medium
By dividing the index data at a high and low bit and using hash table, the problems of high data search time complexity and high memory consumption in embedded systems are solved, and low complexity and efficient data search and storage are achieved, which reduces the The impact of the conflict.
Patent Information
- Application Number
- CN202311843029.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2043-12-28
AI Technical Summary
Existing data search algorithms have problems with high time complexity and high memory consumption in embedded systems, especially the hashing algorithms have shortcomings in memory usage and hash conflict.
By dividing the index data from high and low bits, using hash tables to determine candidate storage nodes, and traverse the linked list when necessary to find data, reducing memory usage and improving search efficiency, and using hash buckets and conflict domain structures to reduce storage and deletion Complexity.
It realizes data search and storage with low time complexity in embedded systems, reduces memory usage, improves the efficiency of data search and deletion, and avoids the complexity caused by hash conflicts.
Smart Images

Figure CN117971899B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data search method, device, equipment and storage medium. Background Art
[0002] In computer systems, data search is a very common requirement in many scenarios. Common search algorithms include linked lists, red-black trees, radix trees, etc. However, the above search algorithms need to traverse the entire data structure when searching for data, resulting in high time complexity.
[0003] In order to solve the problem of high time complexity in the search process, a hash algorithm is proposed. Although the hash algorithm solves the problem of high time complexity to a certain extent, it still has the disadvantage of high memory consumption. Especially in embedded systems, memory is extremely limited. Therefore, there is an urgent need for a data search method that can ensure low time complexity during search and low memory consumption to solve the problems existing in the current search algorithm. Summary of the invention
[0004] In view of this, the present invention provides a data search method, device, equipment and storage medium to solve the current problems of large memory consumption and high time complexity.
[0005] In a first aspect, the present invention provides a data search method, the method comprising:
[0006] The index data is obtained from the data search instruction; the index data is divided into high and low bits to obtain the first sub-data and the second sub-data; the candidate storage node is determined from the preset hash table with the first sub-data as the index; if the storage data in the data domain of the candidate storage node includes the second sub-data, the storage data and the first sub-data are merged to obtain the data to be searched; if the storage data in the data domain of the candidate storage node does not include the second sub-data, the linked list with the candidate storage node as the head node is traversed to obtain the data to be searched according to the storage data containing the second sub-data and the first sub-data in the linked list node.
[0007] The data search method provided in this embodiment first divides the index data into high and low bits to obtain the first sub-data for determining the candidate storage location, and then uses the second sub-data obtained after the high and low bit division to determine the storage location of the data; in this way, the situation of traversing the entire data structure when searching for data is avoided, and the storage location of the data or its approximate storage range can be accurately provided, thereby reducing the time complexity of the search; and because only part of the data to be searched is stored in the storage location, it is also necessary to merge the storage data of the storage location and the first sub-data to obtain the data to be searched; by storing part of the data, the current problem of large memory consumption is solved and memory occupancy is reduced.
[0008] In an optional implementation manner, the index data is divided into high and low bits to obtain the first sub-data and the second sub-data, including:
[0009] Obtain a preset offset; perform shift processing on the index data according to the offset to obtain a shift result; and determine the data corresponding to the low-order part as the first sub-data and the data corresponding to the high-order part as the second sub-data according to the shift result.
[0010] Compared with the traditional hash value obtained by the method of dividing and leaving a remainder, the present preferred embodiment determines the first sub-data by a shift processing method, thereby reducing the consumption of the CPU and making the processing more efficient; moreover, according to the usual data encoding habits, high-order data are more likely to be the same, therefore, the present embodiment determines the low-order part of the data as the first sub-data, which can minimize the occurrence of hash conflicts and thus improve the efficiency of data search.
[0011] In an optional embodiment, the method further includes:
[0012] The data to be stored is obtained from the data storage instruction, and the data to be stored includes the third sub-data and the fourth sub-data; the state of the node corresponding to the third sub-data is obtained when the index is used to obtain the third sub-data; and the target storage node is determined according to the state of the node to store the fourth sub-data in the target storage node.
[0013] In an optional implementation, determining a target storage node according to a state of a node to store the fourth sub-data in the target storage node includes:
[0014] When the state of the node is empty, the node is determined as a target storage node, and the fourth sub-data is stored in the data domain of the target storage node.
[0015] In this embodiment, when storing data, the data to be stored is split, and only the fourth sub-data after the split is stored, so that the space occupied is reduced.
[0016] In an optional implementation, determining a target storage node according to a state of the node to store the fourth sub-data in the target storage node, the method further includes:
[0017] When the state of the node is non-empty, the state of the free list is obtained, the preset hash table includes a collision domain, and the address of the head node of the free list is stored in the pointer field of the head node of the collision domain; when the state of the free list is non-empty, the head node of the free list is determined as the target storage node, and the fourth sub-data is stored in the target storage node, and the head node is deleted from the free list; when the state of the free list is empty, it is determined whether there is a free node in the collision domain; and the target storage node is determined according to the determination result.
[0018] In an optional implementation, determining the target storage node according to the judgment result includes:
[0019] When the judgment result is that there is no idle node in the collision domain, the storage fails; when the judgment result is that there is an idle node in the collision domain, the position corresponding to the first idle node in the collision domain is determined according to the data in the collision domain head node, and the position is determined as the target storage node.
[0020] In an optional implementation, after determining the target storage node, the method further includes:
[0021] Insert the target storage node into the linked list with the candidate storage node as the head node, and use the target storage node as the successor node of the node.
[0022] When storing data, this embodiment directly uses the target storage node as the successor node of the candidate storage node, and does not need to insert the target storage node to the end of the linked list by traversal, so that the time complexity of the storage process is reduced.
[0023] In an optional embodiment, the method further includes:
[0024] The data to be deleted are obtained, and the data to be deleted include the fifth sub-data and the sixth sub-data; the storage node of the data to be deleted is determined according to the fifth sub-data; when the storage node belongs to a conflict domain, the data in the storage node is exchanged with the data of the head node in the linked list to which the storage node belongs; and the head node of the linked list to which the exchanged storage node belongs is deleted.
[0025] The data search method provided in this embodiment directly exchanges the storage node with part of the data domain of the head node of the linked list to which the storage node belongs after finding the storage node where the data to be deleted is located. There is no need to store the predecessor node and the successor node of the storage node, which simplifies the deletion process and improves the deletion efficiency.
[0026] In a second aspect, the present invention provides a data search device, the device comprising:
[0027] The first acquisition module is used to obtain index data from the data search instruction; the division module is used to divide the index data into high and low bits to obtain the first sub-data and the second sub-data; the first determination module is used to determine the candidate storage node from the preset hash table with the first sub-data as the index; the first search module is used to merge the storage data and the first sub-data to obtain the data to be searched if the storage data in the data domain of the candidate storage node includes the second sub-data; the second search module is used to traverse the linked list with the candidate storage node as the head node if the storage data in the data domain of the candidate storage node does not include the second sub-data, so as to obtain the data to be searched according to the storage data containing the second sub-data and the first sub-data in the linked list node.
[0028] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the data search method of the first aspect or any corresponding embodiment thereof by executing the computer instructions. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0030] Figure 1 is a flow chart of a data search method according to Embodiment 1 of the present invention;
[0031] Figure 2 is a schematic diagram of the distribution of the hash bucket structure according to Embodiment 1 of the present invention;
[0032] Figure 3 is a flow chart of a data search method according to Embodiment 2 of the present invention;
[0033] Figure 4 is a flowchart of data storage in embodiment 2 of the present invention;
[0034] Figure 5 is a schematic flow chart of a data search method according to Embodiment 3 of the present invention;
[0035] Figure 6 is a flowchart of data deletion in Embodiment 3 of the present invention;
[0036] Figure 7 is a structural block diagram of a data search device according to Embodiment 4 of the present invention;
[0037] Figure 8 It is a schematic diagram of the hardware structure of the computer device of Example 5 of the present invention. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0039] Traditional data search methods usually require traversing the entire data structure to find the data to be searched, which makes the search time complexity high. However, the hash algorithm can directly determine the storage location of the data to be searched by calculating the hash value, thereby reducing the search time complexity.
[0040] Specifically, the data structure corresponding to the hash algorithm - the hash table is mainly used to store key-value pair data, which includes the key value key and the attribute value value. When searching for data using the hash algorithm, the hash value hash corresponding to the key is first calculated by the hash function, and then the storage location of the key-value pair data corresponding to the key in the hash table is determined using the hash as the index, and finally the key-value pair data to be searched is obtained from the storage location. It is precisely because of the existence of the hash value that when searching for a key-value pair, it is no longer necessary to traverse the entire data result to search, thereby reducing the time complexity of the search process.
[0041] However, as can be seen from the above description, the key value and the attribute value are stored in the hash table at the same time, and when searching, the value is actually searched based on the key. Therefore, the key stored in the hash table occupies a large amount of memory. Especially when the algorithm is applied to embedded systems, memory usage becomes a very serious problem.
[0042] In addition to the above defects, hash algorithms are also prone to hash collisions. Hash collision refers to the situation where two or more different keys are mapped to the same location by the hash function when using a hash table to store data. In this case, it will make it difficult to store and delete data.
[0043] Specifically, when a hash conflict occurs during data storage, the traditional hash algorithm first needs to determine the location of the hash bucket through the hash value, find the last node of the linked list with the hash bucket as the head node, and dynamically allocate memory to add a node to the tail of the linked list corresponding to the hash bucket, and store the data to be stored in the newly added node. When a hash conflict occurs during data deletion, similarly, the storage location of the data to be deleted is found through traversal, and the predecessor and successor nodes of the storage node where the data to be deleted is located are saved, so that the pointer field can be modified after the data to be deleted is deleted.
[0044] However, in the above data storage process, all conflicting data still need to be traversed to complete the storage operation, which increases the time complexity of storage; and in the data deletion process, the predecessor and successor nodes of the deleted data also need to be saved, making the deletion operation complicated.
[0045] To this end, this scheme improves the classic hash algorithm and proposes a data search method with low search time complexity and low memory usage for application in embedded systems.
[0046] According to an embodiment of the present invention, a data search method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0047] Example 1
[0048] In this embodiment, a data search method is provided, which can be used in mobile terminals, PCs, etc. Figure 1 is a flow chart of a data search method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0049] Step S101, obtaining index data from a data search instruction.
[0050] Specifically, the data search instruction carries a search operation instruction and index data, and the index data is index information of the data to be searched.
[0051] Specifically, the data search instruction can be triggered by the user end. When the data search instruction is received, the search operation instruction and the index data are obtained from the data search instruction, so that the controller searches the hash table for the data to be searched corresponding to the index data based on the search operation instruction.
[0052] The hash table used in this scheme consists of two parts: hash bucket and collision domain, and the hash bucket and collision domain are as follows Figure 2 The centralized distribution shown is not a traditional hash distribution. The hash bucket is used to store metadata, and the collision domain is used to store collision data. If there is a hash collision between data A and data B, and data A appears before data B, then data A is defined as metadata and data B is defined as collision data. For another example, if data C does not have a hash collision, then data C is also metadata.
[0053] It should also be noted that the hash bucket and collision domain are uniformly addressed, such as the element range of the hash bucket is A[0]-A
[1000] , and the element range of the collision domain is A
[1001] -A
[1600] . In this solution, the hash table data structure is defined by the following code:
[0054] #define p(2^m)
[0055] #define BUCKET_SIZE p / / Define the capacity of the hash bucket
[0056] #define COLLISION_SIZE 1024*2 / / Define the capacity of the collision domain. Note: The maximum capacity of the collision domain is 2^m.
[0057] Exemplarily, the structure of each element in the hash table is shown in Table 1, including a data field data and a pointer field next.
[0058] Table 1
[0059] data next
[0060] Exemplarily, the index data may be a key value in a key-value pair, and the index data varies with the application scenario and is not specifically limited here. In this embodiment, the definition code for the hash table data structure is as follows:
[0061] Step S102, dividing the index data into high and low bits to obtain first sub-data and second sub-data.
[0062] Specifically, the index data is divided into high and low bits to obtain high-bit data and low-bit data. The first sub-data can be high-bit data or low-bit data, and the corresponding relationship between the first sub-data and high and low bit data is not specifically limited here, and those skilled in the art can select according to actual conditions.
[0063] For example, if the index data is 64-bit data 0xFFCA00003F3C0012 (hexadecimal), after high and low bit division, the lower 20-bit part, namely 0xC0012, is used as the first sub-data, and the upper 44-bit part, namely 0xFFCA00003F3, is used as the second sub-data.
[0064] Step S103: determine a candidate storage node from a preset hash table using the first sub-data as an index.
[0065] Specifically, in the preset hash table, the hash bucket indexed as the first sub-data is determined as a node that may store the data to be found, ie, a candidate storage node. The preset hash table is the hash table to which the data to be found belongs.
[0066] Exemplarily, still taking the embodiment in step S102 as an example, if the first sub-data is 0xC0012, the hash bucket with the subscript 0xC0012 is determined as the candidate storage node.
[0067] Step S104: if the storage data in the candidate storage node data domain includes the second sub-data, the storage data and the first sub-data are merged to obtain the data to be searched.
[0068] Specifically, after determining the candidate storage node, first read the data stored in the data domain of the candidate storage node (i.e., the stored data); then determine whether the stored data includes the second sub-data; when the stored data includes the second sub-data, it indicates that the candidate storage node is the target location of this search. At this time, the stored data and the first sub-data can be merged to obtain the data to be searched.
[0069] Exemplarily, the second sub-data is usually located in the header field of the stored data. Therefore, the method for determining whether the second sub-data is included in the stored data may be to obtain the first m bits of the stored data, compare the first m bits of the data with the second sub-data for consistency, and determine whether the second sub-data is included in the stored data based on the comparison result. If the two are consistent, it is determined that the second sub-data is included in the stored data; if the two are inconsistent, it is determined that the second sub-data is not included in the stored data. In this embodiment, m is the number of bits of the second sub-data.
[0070] Step S105, if the storage data in the candidate storage node data field does not include the second sub-data, traverse the linked list with the candidate storage node as the head node to obtain the data to be searched based on the storage data including the second sub-data and the first sub-data in the linked list node.
[0071] Specifically, the second sub-data is not included in the stored data, indicating that the candidate storage node is not the target location of this search, and also indicates that there is a hash conflict in the data to be searched. When there is a hash conflict in the data to be searched, the node storing the data to be searched must be in the linked list with the candidate storage node as the head node. Therefore, it is necessary to traverse the nodes in the linked list in sequence to find the stored data carrying the second sub-data, so as to restore the data to be searched based on the found stored data and the first sub-data. It should be emphasized here that in the linked list to which the node storing the data to be searched belongs, the head node is the hash bucket corresponding to the first sub-data, and the remaining nodes are all elements in the conflict domain. It should also be noted that if the stored data in the data domain of the candidate storage node does not include the second sub-data and the pointer domain of the candidate storage node is empty, or, in the linked list to which the candidate storage node belongs, the data domain of the remaining nodes does not contain the second sub-data, it means that the data to be searched does not exist in the hash table, so the search fails this time, and the result of the failed search is displayed on the user interface.
[0072] The data search method provided in this embodiment first divides the index data into high and low bits to obtain the first sub-data for determining the candidate storage location, and then uses the second sub-data obtained after the high and low bit division to determine the storage location of the data; in this way, the situation of traversing the entire data structure when searching for data is avoided, and the storage location of the data or its approximate storage range can be accurately provided, thereby reducing the time complexity of the search; and because only part of the data to be searched is stored in the storage location, it is also necessary to merge the storage data of the storage location and the first sub-data to obtain the data to be searched; by storing part of the data, the current problem of large memory consumption is solved and memory occupancy is reduced.
[0073] Preferably, the above step S102 includes:
[0074] Gets the preset offset.
[0075] Specifically, the preset offset is set by the user according to the actual scenario when storing data. Its value is related to the amount of stored data and the overlap rate of high and low bits in the stored data. If the amount of data is very small and the overlap rate of the high bits of the stored data is low, then the value of the preset offset can be small; if the amount of data is large and the overlap rate of the high and low bits is high, then the value of the preset offset should be as large as possible to reduce data conflicts.
[0076] The index data is shifted according to the offset to obtain a shift result.
[0077] Specifically, the index data is left-shifted with the offset being the number of shift bits to obtain a shift result.
[0078] According to the shift result, the data corresponding to the low-order part is determined as the first sub-data, and the data corresponding to the high-order part is determined as the second sub-data.
[0079] Specifically, the low-order portion of data obtained after the shift is determined as the first sub-data, and the remaining high-order portion is determined as the second sub-data.
[0080] Compared with the traditional hash value obtained by the method of dividing and leaving a remainder, the present preferred embodiment determines the first sub-data by a shift processing method, thereby reducing the consumption of the CPU and making the processing more efficient; moreover, according to the usual data encoding habits, high-order data are more likely to be the same, therefore, the present embodiment determines the low-order part of the data as the first sub-data, which can minimize the occurrence of hash conflicts and thus improve the efficiency of data search.
[0081] Example 2
[0082] In this embodiment, a data search method is provided, which can be used in mobile terminals, PCs, etc. Figure 3 is a flow chart of a data search method according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:
[0083] Step S301, obtain index data from the data search instruction. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0084] Step S302: divide the index data into high and low bits to obtain the first sub-data and the second sub-data. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.
[0085] Step S303: Using the first sub-data as an index, determine a candidate storage node from a preset hash table. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0086] Step S304: If the stored data in the candidate storage node data domain includes the second sub-data, the stored data and the first sub-data are merged to obtain the data to be searched. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.
[0087] Step S305: If the storage data in the candidate storage node data field does not include the second sub-data, then traverse the linked list with the candidate storage node as the head node to obtain the data to be searched based on the storage data containing the second sub-data and the first sub-data in the linked list node. Figure 1 Step S105 of the illustrated embodiment will not be described in detail here.
[0088] Step S306, obtaining the data to be stored from the data storage instruction, where the data to be stored includes the third sub-data and the fourth sub-data.
[0089] Specifically, the data storage instruction carries a storage operation instruction and data to be stored. After the data to be stored is acquired, the data to be stored is divided into third sub-data and fourth sub-data using the preferred method of step S102.
[0090] Step S307, obtaining the state of the corresponding node when the index takes the third sub-data.
[0091] Specifically, in the hash table, the third sub-data is used as an index to obtain the state of the hash bucket corresponding to the index. The state of the hash bucket includes empty and non-empty.
[0092] Exemplarily, if the third sub-data is 0011, the hash bucket with the index 0011 is found from the hash table, and the state of the hash bucket is obtained.
[0093] Step S308: determine a target storage node according to the state of the node, so as to store the fourth sub-data in the target storage node.
[0094] Specifically, the above step S308 includes:
[0095] Step S3081: when the state of the node is empty, the node is determined as a target storage node, and the fourth sub-data is stored in the data domain of the target storage node.
[0096] Specifically, when the state of the hash bucket (i.e., the node) is empty, it means that the current hash bucket can be used for data storage. At this time, the hash bucket is directly determined as the target storage node, and then the fourth sub-data is stored in the data domain of the target storage node. Since the original state of the hash bucket is empty, the pointer domain of the hash bucket is still empty and does not need to be modified.
[0097] Step S3082, when the state of the node is not empty, obtain the state of the free list.
[0098] Specifically, when the state of a hash bucket (i.e., a node) is non-empty, it means that the current hash bucket already has data stored, and there is a hash conflict in the current data to be stored. Therefore, the data to be stored needs to be stored in a node in the conflict domain. When storing the data to be stored, it is first necessary to determine the target storage node for storing the data to be stored from the conflict domain. The first step in determining the target storage node is to obtain the state of the free list in the conflict domain.
[0099] Specifically, referring to the description of the hash table and the element structure in the hash table in step S101, the head node of the collision domain includes a data domain and a pointer domain, wherein the data domain part is used to store the data volume of all collision data from the time when the hash table is constructed to the current time, which is the sum of the collision data that still exists and the collision data that existed originally but has been deleted; the pointer domain part points to the head node of the free list. The free list is formed by nodes that were originally non-empty but are in an idle state due to the subsequent deletion of stored data.
[0100] For example, if the capacity of the collision domain is 100, excluding the head node, the real available space is 99, the data in the head node data domain is 80, and there are 20 nodes in the free list. Then, there are 39 nodes currently available, including 19 nodes in the collision domain that have never stored data, and 20 nodes in the free list that have been released.
[0101] Step S3083, when the state of the free linked list is not empty, the head node of the free linked list is determined as the target storage node, and the fourth sub-data is stored in the target storage node, and the head node is deleted from the free linked list.
[0102] Step S3084, when the state of the free list is empty, determine whether there is an idle node in the conflict domain.
[0103] Specifically, when the state of the free list is empty, it means that there is no node available for storage in the free list. At this time, it is necessary to determine whether there are other free nodes in the conflict domain.
[0104] Specifically, the method for determining whether there are other idle nodes in the collision domain is as follows: read the amount of data in the data domain of the collision domain head node; compare the amount of data with the capacity of the collision domain - 1; if the two are consistent, it means that the collision domain is full and there are no other idle nodes; if they are inconsistent, it means that there are other idle nodes.
[0105] Step S3085, determine the target storage node according to the judgment result.
[0106] In some optional implementations, the above step S3085 includes:
[0107] Step a1: When the judgment result is that there is no idle node in the conflict domain, the storage fails.
[0108] Specifically, when there is no idle node in the collision domain, it means that there is no extra space in the hash table for storage, so the storage operation fails.
[0109] Step a2: when the judgment result is that there is an idle node in the collision domain, the position corresponding to the first idle node in the collision domain is determined according to the data in the collision domain head node, and the position is determined as the target storage node.
[0110] Specifically, when there is an idle node in the collision domain, it means that there is still space available in the collision domain. At this time, the target storage node can be determined starting from the next node of the collision domain head node and the amount of data stored in the head node as the offset.
[0111] Step a3: insert the target storage node into the linked list with the candidate storage node as the head node, and use the target storage node as the successor node of the node.
[0112] In this embodiment, when storing data, the data to be stored is split, and only the fourth sub-data after the split is stored, so that the space occupied is reduced; when storing data, the target storage node is directly used as the successor node of the candidate storage node, so that the time complexity is reduced. The data storage process involved in step S306 to step S308 is as follows: Figure 4 shown.
[0113] Example 3
[0114] In this embodiment, a data search method is provided, which can be used in mobile terminals, such as mobile phones, tablet computers, etc. Figure 5 is a flow chart of a data search method according to an embodiment of the present invention. Figure 5 As shown, the process includes the following steps:
[0115] Step S501, obtain index data from the data search instruction. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0116] Step S502: divide the index data into high and low bits to obtain the first sub-data and the second sub-data. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.
[0117] Step S503: Using the first sub-data as an index, determine a candidate storage node from a preset hash table. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0118] Step S504: If the stored data in the candidate storage node data domain includes the second sub-data, the stored data and the first sub-data are merged to obtain the data to be searched. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.
[0119] Step S505: If the storage data in the candidate storage node data field does not include the second sub-data, then traverse the linked list with the candidate storage node as the head node to obtain the data to be searched based on the storage data containing the second sub-data and the first sub-data in the linked list node. Figure 1 Step S105 of the illustrated embodiment will not be described in detail here.
[0120] Step S506, obtaining data to be deleted, where the data to be deleted includes the fifth sub-data and the sixth sub-data.
[0121] Specifically, the data to be deleted can be obtained from the received data deletion instruction. After the data to be deleted is obtained, the preferred method of step S102 can be used to divide the data to be stored into fifth sub-data and sixth sub-data.
[0122] Step S507: determining a storage node of the data to be deleted according to the fifth sub-data.
[0123] Specifically, the fifth sub-data is used as an index to search the hash table for a node storing the sixth sub-data, and the node storing the sixth sub-data is determined as the storage node of the data to be deleted. If the storage node of the data to be deleted is not found, it means that the data to be deleted does not exist in the hash table, and a deletion failure is displayed on the interactive interface.
[0124] Step S508: when the storage node belongs to the conflict domain, the data in the storage node is exchanged with the data of the head node in the linked list to which the storage node belongs.
[0125] Specifically, when the storage node belongs to a hash bucket, the corresponding hash bucket is directly deleted.
[0126] Step S509, deleting the head node of the linked list to which the exchanged storage node belongs.
[0127] The data deletion process involved in step S506 to step S509 is as follows: Figure 6 shown.
[0128] The data search method provided in this embodiment directly exchanges the storage node with part of the data domain of the head node of the linked list to which the storage node belongs after finding the storage node where the data to be deleted is located. There is no need to store the predecessor node and the successor node of the storage node, which simplifies the deletion process and improves the deletion efficiency.
[0129] Example 4
[0130] In the present embodiment, a data search device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0131] This embodiment provides a data search device, such as Figure 7 As shown, the device comprises:
[0132] The first acquisition module 701 is used to acquire index data from a data search instruction.
[0133] The division module 702 is used to divide the index data into high and low bits to obtain the first sub-data and the second sub-data.
[0134] The first determination module 703 is used to determine the candidate storage node from the preset hash table using the first sub-data as an index; the second acquisition module is used to determine the candidate storage node from the preset hash table using the first sub-data as an index.
[0135] The first search module 704 is configured to merge the storage data and the first sub-data to obtain the data to be searched if the storage data in the candidate storage node data domain includes the second sub-data.
[0136] The second search module 705 is used to traverse the linked list with the candidate storage node as the head node if the storage data in the candidate storage node data domain does not include the second sub-data, so as to obtain the data to be searched according to the storage data containing the second sub-data and the first sub-data in the linked list nodes.
[0137] In some optional implementations, the partitioning module 702 includes:
[0138] The first acquisition submodule is used to obtain a preset offset; the shift submodule is used to shift the index data according to the offset to obtain a shift result; the first determination submodule is used to determine the data corresponding to the low-order part as the first sub-data and the data corresponding to the high-order part as the second sub-data according to the shift result.
[0139] In some optional embodiments, the device further comprises:
[0140] The second acquisition module is used to obtain the data to be stored from the data storage instruction, and the data to be stored includes the third sub-data and the fourth sub-data; the third acquisition module is used to obtain the state of the corresponding node when the index takes the third sub-data; the storage module is used to determine the target storage node according to the state of the node, so as to store the fourth sub-data to the target storage node.
[0141] In some optional embodiments, the storage module includes:
[0142] The first storage submodule is configured to, when the state of the node is empty, determine the node as a target storage node, and store the fourth sub-data in a data domain of the target storage node.
[0143] In some optional implementations, the storage module further includes:
[0144] The second acquisition submodule is used to acquire the state of the free list when the state of the node is non-empty, and the address of the head node of the free list is stored in the pointer field of the head node of the collision domain; the second determination submodule is used to determine the head node of the free list as the target storage node when the state of the free list is non-empty, and store the fourth sub-data in the target storage node, and delete the head node from the free list; the judgment submodule is used to judge whether there is a free node in the collision domain when the state of the free list is empty; the third determination submodule is used to determine the target storage node according to the judgment result.
[0145] In some optional implementations, the third determining submodule includes:
[0146] The display unit is used to determine storage failure when the judgment result is that there are no idle nodes in the conflict domain; the determination unit is used to determine the position corresponding to the first idle node in the conflict domain according to the data in the conflict domain head node when the judgment result is that there are idle nodes in the conflict domain, and determine the position as the target storage node.
[0147] In some optional implementations, after the determination unit, the method further includes:
[0148] The insertion unit is used to insert the target storage node into the linked list with the candidate storage node as the head node, and use the target storage node as the successor node of the node.
[0149] In some optional embodiments, the device further comprises:
[0150] The fourth acquisition module is used to acquire the data to be deleted, and the data to be deleted includes the fifth sub-data and the sixth sub-data; the second determination module is used to determine the storage node of the data to be deleted according to the fifth sub-data; the exchange module is used to exchange the data in the storage node with the data of the head node in the linked list to which the storage node belongs when the storage node belongs to the conflict domain; the deletion module is used to delete the head node of the linked list to which the storage node belongs after the exchange.
[0151] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0152] The data search device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0153] Example 5
[0154] The embodiment of the present invention also provides a computer device having the above Figure 7 The data search device shown.
[0155] See also Figure 8 , Figure 8 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 8 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 8 A processor 10 is taken as an example.
[0156] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0157] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0158] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device 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.
[0159] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0160] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0161] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0162] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A data search method, characterized in that: The method comprises: Get index data from data search instructions; Dividing the index data into high and low bits to obtain first sub-data and second sub-data; Using the first sub-data as an index, determining a candidate storage node from a preset hash table; If the storage data in the candidate storage node data domain includes the second sub-data, merging the storage data and the first sub-data to obtain the data to be searched; If the storage data in the data domain of the candidate storage node does not include the second sub-data, traversing the linked list with the candidate storage node as the head node to obtain the data to be searched according to the storage data including the second sub-data and the first sub-data in the linked list nodes; Acquire the data to be stored from the data storage instruction, where the data to be stored includes the third sub-data and the fourth sub-data; Obtain the state of the node corresponding to the third sub-data when the index is taken; Determine a target storage node according to the state of the node, so as to store the fourth sub-data in the target storage node; When the state of the node is non-empty, the state of the free list is obtained, the preset hash table includes a collision domain, and the address of the head node of the free list is stored in the pointer domain of the head node of the collision domain; When the state of the free linked list is not empty, determining the head node of the free linked list as the target storage node, storing the fourth sub-data in the target storage node, and deleting the head node from the free linked list; When the state of the free linked list is empty, determining whether there is an idle node in the conflict domain; Determine the target storage node according to the judgment result; When the judgment result is that there is an idle node in the collision domain, determining the position corresponding to the first idle node in the collision domain according to the data in the collision domain head node, and determining the position as the target storage node; Using the target storage node as a successor node of the node; Acquire data to be deleted, where the data to be deleted includes fifth sub-data and sixth sub-data; Determining a storage node of the to-be-deleted data according to the fifth sub-data; When the storage node belongs to the conflict domain, exchanging the data in the storage node with the data of the head node in the linked list to which the storage node belongs; Delete the head node of the linked list to which the storage node belongs after the exchange.
2. The method according to claim 1, characterized in that The step of dividing the index data into high and low bits to obtain the first sub-data and the second sub-data includes: Get the preset offset; Performing shift processing on the index data according to the offset to obtain a shift result; According to the shift result, the data corresponding to the low-order part is determined as the first sub-data, and the data corresponding to the high-order part is determined as the second sub-data.
3. The method according to claim 1, characterized in that: The step of determining a target storage node according to the state of the node, so as to store the fourth sub-data in the target storage node, comprises: When the state of the node is empty, the node is determined as the target storage node, and the fourth sub-data is stored in the data domain of the target storage node.
4. The method according to claim 1, characterized in that: The determining the target storage node according to the judgment result includes: When the judgment result is that there is no idle node in the conflict domain, storage fails.
5. The method according to claim 1, characterized in that After determining the target storage node, the method further includes: Insert the target storage node into a linked list with the node as the head node.
6. A data search device, characterized in that: The device comprises: A first acquisition module, used for acquiring index data from a data search instruction; A division module, used for dividing the index data into high and low bits to obtain first sub-data and second sub-data; A first determining module, configured to determine a candidate storage node from a preset hash table using the first sub-data as an index; a first search module, configured to merge the stored data and the first sub-data to obtain data to be searched if the stored data in the candidate storage node data domain includes the second sub-data; A second search module is used for traversing a linked list with the candidate storage node as a head node to obtain the data to be searched according to the stored data containing the second sub-data and the first sub-data in the linked list nodes if the stored data in the data domain of the candidate storage node does not include the second sub-data; A second acquisition module is used to acquire the data to be stored from the data storage instruction, where the data to be stored includes the third sub-data and the fourth sub-data; A third acquisition module is used to obtain the state of the corresponding node when the index takes the third sub-data; A storage module, used to determine a target storage node according to a state of the node, so as to store the fourth sub-data in the target storage node; The storage module also includes: The second acquisition submodule is used to acquire the state of the free list when the state of the node is not empty, and the address of the head node of the free list is stored in the pointer field of the head node of the collision domain; the second determination submodule is used to determine the head node of the free list as the target storage node when the state of the free list is not empty, and store the fourth subdata in the target storage node, and delete the head node from the free list; the judgment submodule is used to judge whether there is a free node in the collision domain when the state of the free list is empty; the third determination submodule is used to determine the target storage node according to the judgment result; The third determination submodule includes: A determination unit, configured to determine a position corresponding to the first idle node in the collision domain according to data in the collision domain head node when the result of the determination is that there is an idle node in the collision domain, and determine the position as the target storage node; A determination module, used for taking the target storage node as a successor node of the node; A fourth acquisition module, used to acquire the data to be deleted, where the data to be deleted includes the fifth sub-data and the sixth sub-data; A second determining module, used to determine a storage node of the data to be deleted according to the fifth sub-data; The exchange module is used to exchange the data in the storage node with the data of the head node in the linked list to which the storage node belongs when the storage node belongs to the conflict domain; The deletion module is used to delete the head node of the linked list to which the exchanged storage node belongs.
7. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the data search method according to any one of claims 1 to 5 by executing the computer instructions.
