Hash table processing method and device, medium and equipment

By using the key-value separation method of index arrays and data arrays in the hash table, and combining the balanced binary tree to handle hash conflicts, the problem of storage and search efficiency of existing hash tables is solved, and the expansion process is optimized through step-by-step expansion, achieving more efficient data storage and access.

CN119690969AActive Publication Date: 2025-03-25BANK OF CHINA INSURANCE INFORMATION TECH MANAGEMENT
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202411754170.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-03-25
Estimated Expiration
2044-12-02

AI Technical Summary

Technical Problem

When processing large amounts of data, existing hash tables have problems such as high storage occupancy, serious hash conflicts, low search efficiency, and large computing volume and long-term blockage caused by one-time expansion.

Method used

Data is stored in the form of index arrays and data arrays, index positions are calculated by hash values ​​for searching, inserting or deleting operations, and data is organized using a balanced binary tree structure in the data array to resolve hash conflicts. At the same time, step-by-step expansion is used to avoid performance degradation caused by one-time expansion.

Benefits of technology

It effectively saves storage space, reduces the complexity of search during hash conflicts, improves data storage and access efficiency, and makes the hash table expansion process smoother, avoiding performance bottlenecks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690969A_ABST
    Figure CN119690969A_ABST
Patent Text Reader

Abstract

The invention provides a Hash table processing method and device, a medium and equipment, a Hash table comprises an index array and a data array, the address of data in the data array is stored in the index array, the data is stored in the data array, and the processing method comprises the steps that the Hash value of target data is calculated, calculating an index position according to the hash value; accessing the index array according to the index position to obtain an address of target data corresponding to the index position in the data array; and accessing the data array according to the address of the target data in the data array, and searching, inserting or deleting the target data. The data storage efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data storage, and in particular to a hash table processing method, device, medium and equipment. Background Art

[0002] With the advent of the information age, the data that needs to be stored has grown exponentially. Hash table, also known as hash table, is a data storage structure that establishes a one-to-one mapping relationship between the storage location of an element and the key code (value) of the element through a hash function. With the development of Internet technology, hash table, as a data structure for storing keys and values, has a large number of applications in data storage. Its characteristics are that it uses space in exchange for time, calculates the hash value of the key through a hash function, and quickly locates the location by looking up the table to obtain the value. For those skilled in the art, how to improve the data structure of the hash table to achieve efficient data storage and access is a topic that needs to be continuously studied. Summary of the invention

[0003] In view of this, the present application provides a hash table processing method, device, medium and equipment, the main purpose of which is to use the hash table for efficient data storage.

[0004] According to one aspect of the present application, a hash table processing method is provided, wherein the hash table includes an index array and a data array, wherein the address of data in the data array is stored in the index array, and the data is stored in the data array, and the processing method includes:

[0005] Calculate a hash value of the target data, and calculate an index position according to the hash value;

[0006] Access the index array according to the index position to obtain the address of the target data corresponding to the index position in the data array;

[0007] According to the address of the target data in the data array, the data array is accessed to perform a search, insertion or deletion operation on the target data.

[0008] In one implementation, the method further includes:

[0009] Determine whether the same hash value is calculated for different data, and if so, determine that there is a hash conflict;

[0010] The data array is organized based on a balanced binary tree data structure to handle the hash conflict.

[0011] In one implementation, organizing the data array based on a balanced binary tree data structure includes:

[0012] If the root node is empty, it is determined that the position in the data array is empty, then the data is directly placed in the corresponding position. If the root node is not empty, traverse from the root node to find the insertion position of the element to be inserted

[0013] In one implementation, the step of processing the hash conflict includes:

[0014] When inserting into a binary search tree, record the nodes searched during the insertion process. After the insertion, search upward from the insertion node, performing rotation adjustments in sequence until the root node.

[0015] In one implementation,

[0016] The hash table includes an old hash table and an expanded new hash table, wherein the capacity of the new hash table is greater than the capacity of the old hash table;

[0017] The method further includes: setting a capacity expansion flag to indicate whether the capacity expansion operation is in progress.

[0018] In one implementation, the method further includes:

[0019] Read the expansion flag to determine whether the hash table is in an expansion operation;

[0020] If yes, determine the index array capacity and data array capacity of the new hash table according to the specified expansion size; and, in response to the data operation request, perform the following steps:

[0021] In response to a data insertion operation request, insert the data into the new hash table;

[0022] For a data search operation request, first search the old hash table, and if not found, then search in the new hash table;

[0023] For a data deletion operation request, the old hash table is first searched, and if found, it is deleted. If not found, it is searched and deleted in the new hash table.

[0024] In one implementation, the method further includes:

[0025] After each hash expansion is completed, it is determined whether all elements in the old hash table have been migrated to the new hash table. If the expansion is completed, the expansion flag is reset.

[0026] According to one aspect of the present application, a hash table processing device is provided, wherein the hash table includes an index array and a data array, wherein the address of data in the data array is stored in the index array, and the data is stored in the data array, and the processing device includes:

[0027] An index position determination unit, configured to calculate a hash value of the target data and calculate an index position according to the hash value;

[0028] An index array access unit, used to access the index array according to the index position, and obtain the address of the target data corresponding to the index position in the data array;

[0029] The data array access unit is used to access the data array according to the address of the target data in the data array, and perform the operation of searching, inserting or deleting the target data.

[0030] According to one aspect of the present application, a provision is provided.

[0031] According to one aspect of the present application, a storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned hash table processing method when running.

[0032] According to one aspect of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the above-mentioned hash table processing method.

[0033] By means of the above technical scheme, the present application provides a hash table processing method, device, medium and equipment, which stores the address of data in a data array in an index array, stores data in a data array, and when performing data operations, first accesses the index array according to the index position to obtain the address of the target data in the data array corresponding to the index position; then accesses the data array according to the address of the target data in the data array to perform search, insertion or deletion operations on the target data.

[0034] It can be seen that the present application uses the index array and data array methods respectively. The index array stores the address of the data corresponding to the index in the data array. For example, a 4-byte index array is used to store the position of the data in the data array instead of the actual position in the memory, which can save storage space.

[0035] In addition, in one implementation, compared with the existing hash table using linked list storage, the embodiment of the present application uses a balanced binary tree to store data with the same hash value, solving the problem of low search efficiency when hash conflicts are serious, and reducing the time complexity from O(n) to close to O(logn).

[0036] In addition, compared with one-time expansion, the embodiment of the present application adopts step-by-step expansion to avoid rehashing a large number of elements into a new table in a short period of time, which can avoid the huge amount of calculation and long-term blocking caused by one-time expansion, making the entire expansion process smoother.

[0037] In summary, the hash table processing solution provided in this application can improve the efficiency of data storage.

[0038] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] 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:

[0040] Figure 1 A schematic diagram of a hash table structure in the prior art is shown;

[0041] Figure 2 A flow chart of a hash table processing method provided by an embodiment of the present application is shown;

[0042] Figure 3 A schematic diagram of a hash table structure in an example of a hash table processing method provided in an embodiment of the present application is shown;

[0043] Figure 4 A schematic diagram of the structure of a hash table processing device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0044] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.

[0045] See also Figure 1 , the existing hash table uses a linked list to store elements with the same hash value, and all elements with the same hash value are inserted into the end of the linked list in sequence. When searching, you need to traverse from the head of the linked list until you find the element you want to find. When the number of elements in the hash table reaches the upper limit, you need to create a new hash table and reinsert all elements in the old table into the new hash table in sequence. Each node in the linked list stores the current value and a pointer to the next node.

[0046] The inventor of this application has found that Figure 1 ,The existing hash table has the following problems.

[0047] 1. The existing hash table uses a pointer to store the address of the next element in memory, which requires 8 bytes in a 64-bit operating system. A balanced binary tree needs to store pointers to the left and right nodes, which requires a total of 16 bytes. When the number of nodes in the tree is large, the memory usage is relatively high.

[0048] 2. Existing hash tables generally use the zipper method to resolve hash conflicts, placing elements with the same hash value in a linked list. In extreme cases, if a large number of elements have the same hash value, the linked list will be too long, and hash table query, insertion and deletion need to traverse the entire linked list, and the time complexity will degenerate from O(1) to O(n), and the performance will be significantly reduced.

[0049] 3. The existing hash table expansion adopts one-time expansion. When the elements in the hash table are full, the elements are re-hashed and inserted into the new hash table at one time. When the number of elements in the hash table is large, the one-time expansion will cause a lot of calculations, and the expansion process will be very time-consuming. At this time, the query, insertion and deletion operations of the hash table may be blocked, resulting in performance degradation.

[0050] Based on the above analysis, an embodiment of the present application proposes a hash table processing method to solve one or more of the above problems.

[0051] refer to Figure 2 , is a flow chart of a hash table processing method provided in an embodiment of the present application, wherein the hash table includes an index array and a data array, wherein the address of the data in the data array is stored in the index array, and the data is stored in the data array, and the method includes the following steps S201-S203.

[0052] S201: Calculate the hash value of the target data, and calculate the index position according to the hash value;

[0053] S202: Access the index array according to the index position to obtain the address of the target data corresponding to the index position in the data array;

[0054] S203: Access the data array according to the address of the target data in the data array, and perform a search, insert or delete operation on the target data.

[0055] Among them, the address of the data in the data array is stored in the index array (index array) (rather than the address of the data in the memory), and the data is stored in the data array (data array). Therefore, the key-value separation is achieved through the index array and the data array, which can solve the problem of high memory usage of the existing hash table storage. The traditional hash table uses a linked list to store elements with the same hash value. The linked list needs to store a pointer to the next element. Taking a 64-bit operating system as an example, it requires an 8-byte size. The embodiment of the present application adopts a key-value separation method, that is, an index array and a number array are used to store key and value respectively. There is no need to use an 8-byte size to store pointers, but 4 bytes are used to store the position of the data in the data array. If the pointer is stored, the left and right node pointers in the balanced binary tree require a total of 16 bytes, while the present application only requires 8 bytes, which saves more memory usage.

[0056] In order to solve the problem of hash conflicts in existing hash tables, the embodiment of the present application proposes to use a balanced binary tree data structure combined with a linked list to organize the data array.

[0057] In one implementation, the method further includes: determining whether the same hash value is calculated for different data, and if so, determining that a hash conflict exists; and organizing a data array based on a balanced binary tree data structure to handle hash conflicts.

[0058] Among them, the balanced binary tree can use data structures such as AVL tree, red-black tree, skip list, scapegoat tree, Treap and stretch tree to organize the data array. The balanced binary tree is used to solve the problem of uncertain height of the binary sorted tree. If the height difference between the subtrees of the binary sorted tree is too large, the time complexity of the binary sorted tree operation will be upgraded to O(n). In order to avoid this situation and prepare for the worst case, the balanced binary tree appears to make the height of the tree as small as possible. Its essence is still a binary search tree. In a balanced binary tree, the absolute value of the difference between the height of the left subtree and the right subtree is less than or equal to 1, and the left subtree and the right subtree are also balanced binary trees. For ease of understanding, a number is attached to each node on the tree to give the height difference between the left subtree and the right subtree of the node. This number is called the balance factor (BF) of the node. The balance factor = the height of the left subtree of the node - the height of the right subtree of the node. Therefore, the balance factor of all nodes in the balanced binary tree can only be -1, 0, and 1. The advantages of a balanced binary tree are reflected in its efficient search, insertion, and deletion operations, which benefit from its strict balance conditions and self-adjustment mechanism after various operations.

[0059] Therefore, in the data array, each data may contain four parts, namely, the hash value, the address pointing to the left subtree, the address pointing to the right subtree, and the value of the data itself. Each part uses 4 bytes to store, a total of 16 bytes, which are stored sequentially in the data array. Therefore, in one implementation, the organizational content of the data array includes the hash value, the address of the left subtree, the address of the right subtree, and the value.

[0060] In one implementation, the data array is organized based on a balanced binary tree data structure, including: if the root node is empty, that is, the position in the data array is empty, the data is directly placed in the corresponding position; if the root node is not empty, traversing from the root node to find the insertion position of the element to be inserted.

[0061] In one implementation, using a balanced binary tree to handle hash conflicts may include the following steps: when inserting into the binary search tree, record the nodes searched during the insertion process, and after the insertion, search upward from the insertion node, performing rotation adjustments in sequence until the root node.

[0062] It can be seen that the embodiment of the present application can solve the problem of low insertion and deletion efficiency of the traditional zipper-based hash table by organizing the data array in a balanced binary tree. In the existing hash table, a linked list is used to store elements in the same hash bucket. If multiple keys have the same hash value, the linked list will become longer, and insertion and deletion need to traverse the entire linked list, causing the complexity of insertion and deletion of the hash table to degenerate from O(1) to O(n), resulting in a significant decrease in performance. In the embodiment of the present application, by replacing the linked list with a balanced binary tree, the time complexity of insertion and deletion is significantly reduced, and the average time complexity is optimized from O(n) to close to O(logn), and even in the case of severe hash conflicts, it can still maintain a high performance.

[0063] In view of the defects of the existing one-time expansion of hash tables, the embodiments of the present application propose a step-by-step expansion method to solve the problems of time-consuming and lag in one-time expansion.

[0064] In an embodiment of the present application, two sets of hash table structures can be set, wherein the original hash table is called the old hash table, and the hash table after expansion is called the new hash table. Regardless of the old hash table or the new hash table, the aforementioned "index array + data array" structure can be adopted to efficiently store data in this key-value separation manner. For the expanded new hash table, its capacity is generally larger than the old hash table. For example, the capacity of the new hash table is twice that of the old hash table. In addition, in order to solve the problem of one-time expansion of the existing hash table, in an embodiment of the present application, an expansion flag is set, so as to determine whether it is currently in an expansion operation by reading the expansion flag, so as to realize step-by-step expansion, that is, the expansion operation is dispersed into insertion, search and deletion. Each time an insertion, search or deletion is performed, only a part of the elements are re-hashed and inserted into the new table, avoiding a large number of calculations at a certain moment, and the entire expansion process is smoother.

[0065] Therefore, in one implementation, the method further includes: reading an expansion flag to determine whether the hash table is in an expansion operation; if so, determining the index array capacity and data array capacity of the new hash table according to the specified expansion size; and, in response to the data operation request, executing the following steps:

[0066] 1) In response to a data insertion operation request, insert the data into a new hash table;

[0067] 2) For a data search operation request, first search the old hash table, and if not found, search in the new hash table;

[0068] 3) For a data deletion operation request, first search the old hash table, if found, delete it, if not found, search and delete it in the new hash table.

[0069] After each hash expansion is completed, it is determined whether all elements in the old hash table have been migrated to the new hash table. If the expansion is completed, the expansion flag is reset. For example, the expansion flag value Value-resizing stamp is set. When Value-resizing stamp = 1, it indicates that the expansion operation is in progress. When the expansion is not performed or the expansion is completed, Value-resizing stamp = 0.

[0070] It can be seen that the embodiments of the present application can solve the problem of performance degradation during traditional one-time expansion. Traditional one-time expansion requires rehashing all elements and inserting them into the new hash table in a short time. When the hash table capacity is large, the expansion process will be more time-consuming. One-time expansion will cause obvious delays, and the application may respond slowly or freeze during the expansion process. Step-by-step expansion distributes the expansion operation into insertion, search, and deletion. Each time an insertion, search, or deletion is performed, only a part of the elements are rehashed and inserted into the new table, avoiding a large number of calculations at a certain moment, and the entire expansion process is smoother.

[0071] See also Figure 3 , shows a schematic diagram of a hash table structure in an example of a hash table processing method provided in an embodiment of the present application.

[0072] In this example, a key-value separation method is used for storage. The key stores the address of the data, and the value stores the actual data to be accessed. Two data structures, index array and data, are used to store the index and the corresponding data respectively. When expanding capacity, the new and old index arrays are maintained at the same time to achieve smooth step-by-step expansion. The process of data search, insertion and deletion is as follows.

[0073] 1. Hash value calculation and index search

[0074] When you need to find, insert or delete a piece of data, first calculate the hash value of the data, and then use the hash value to calculate the index position in the hash table, that is, a certain position in the index array.

[0075] 2. Get the data address from the index array

[0076] According to the index position calculated in step 1, access the index array to retrieve the value stored at that position. The index array stores the position of the data to be accessed in the data array.

[0077] 3. Data storage and reading

[0078] According to step 2, the storage address of the data in the data array is found, and the corresponding position of the data array can be directly accessed to read or update the data. If there are multiple elements at this position, the tree is searched according to the value size according to the characteristics of the balanced binary tree sort. If the value of the data to be queried is greater than the value of the current node, the right subtree is searched, otherwise the left subtree is searched. If the value and hash value are equal, the element is found.

[0079] 4. Data insertion and hash conflict handling

[0080] If the hash values ​​calculated for different keys are the same, the data with the same hash values ​​are logically organized into a balanced binary tree. If the root node is empty, that is, the position in the data array is empty, the data is directly placed in the corresponding position. If the root node is not empty, traverse from the root node to find the insertion position of the element to be inserted. After the insertion is completed, the binary tree is kept balanced through rotation operations. These are all logical operations. Physically, you only need to modify the left and right subtree fields corresponding to the data.

[0081] The following is an explanation of the rotation operation of a binary tree.

[0082] The definition of a balanced binary tree is recursive and must satisfy the following two points: it is a binary sorted tree, and the left and right subtrees of any node are also balanced binary trees (the difference between the left and right heights is less than 1). This definition ensures that the depth of a balanced binary tree will not be too large, which is conducive to searching. Balance factor (BF): For node P, its balance factor = left subtree height - right subtree height, balance factor = left subtree height - right subtree height. If |balance factor|>1, then the tree with node P as the root is an unbalanced binary sorted tree.

[0083] There are two cases for rotating a binary tree:

[0084] The first is left rotation, which includes two steps: rotating the root node (denoted as P) of the tree to be rotated to the left (counterclockwise) relative to its right child node (denoted as S), so that the root node P becomes the left child node of the child node S; and, the left subtree of the node S is used as the right subtree of the node P. The second is right rotation, which includes two steps: rotating the root node (denoted as P) of the tree to be rotated to the right (clockwise) relative to the left child node (denoted as S), so that the root node P becomes the right child node of the child node S; and, the right subtree of the node S is used as the left subtree of the node P.

[0085] Therefore, when inserting into a binary search tree, if an imbalance occurs, you only need to search upward from the node just inserted (denoted as P) to find the first node with |BF|>1 (denoted as F here), and use this node as the root node for rotation adjustment.

[0086] 5. Delete operation

[0087] When the element to be deleted is found, it is only deleted logically. Physically, the position of the element is set to empty, and all free positions in the data array are organized using a linked list. When an element needs to be inserted, it is inserted into the free position in the array first. If there is no free position, it is inserted into the end of the linked list in sequence.

[0088] 6. Hash table expansion

[0089] The present invention adopts step-by-step expansion, maintains two old and new index arrays at the same time, and sets an expansion flag to indicate whether the hash table is in step-by-step expansion. When the capacity of the old index array reaches the upper limit, a new index array is created, and the capacity is twice that of the old index array. A fixed expansion size is set, and before inserting data each time, the expansion flag is read to determine whether it is in the hash expansion process. If it is in the hash expansion process, the specified size is expanded first, and then the data is inserted into the data array, and the position is stored in the new index array; if it is not in the hash expansion process, the element position is stored in the old index array. When inserting the data array, first determine whether there is an idle position in the array. If so, the data is placed in the idle position in the array first. If not, the data is inserted into the end of the array in sequence.

[0090] When searching for data, first determine whether it is in the hash expansion process. If it is in the hash expansion process, first check the old index array. If it is not found, then check the new index array. If it is not in the hash expansion process, directly search the old index array. Find the position of the element in the data array in the index array and check whether the data array exists.

[0091] Before deleting data, it is also determined whether it is in the process of hash expansion. If it is in the process of hash expansion, it is expanded to the specified size first, and then the data is searched in the old index array. After the data is found, the deletion flag is set. If the data is not found in the old index array, the data is searched in the new index array. After the data is found, the deletion flag is set. Since the data is stored continuously in the array, the deleted data is deleted logically, and the position is set to empty physically. All free positions in the array are managed using a linked list.

[0092] After each hash expansion is completed, it is determined whether all elements in the old table have been migrated to the new table. If the expansion is completed, the hash expansion flag is reset.

[0093] In summary, the hash table processing method provided in the embodiment of the present application adopts a key-value separation storage method, and uses an index array and a data array for storage respectively. The index array stores the address of the data corresponding to the index in the data array. For example, 4 bytes are used to store the position of the data in the data array instead of the actual position in the memory, which can save storage space; moreover, compared with the linked list method, the embodiment of the present application adopts a balanced binary tree method to store data with the same hash value, which solves the problem of low search efficiency when hash conflicts are serious, and the time complexity is reduced from O(n) to close to O(logn); in addition, compared with one-time expansion, the embodiment of the present application adopts step-by-step expansion to avoid re-hashing a large number of elements into a new table in a short period of time, which can avoid the huge amount of calculation and long-term blocking caused by one-time expansion, making the entire expansion process smoother.

[0094] Corresponding to the above-mentioned hash table processing method, an embodiment of the present application also provides a hash table processing device.

[0095] See also Figure 4 , shows a schematic diagram of the structure of a hash table processing device provided in an embodiment of the present application, wherein the hash table includes an index array and a data array, wherein the address of data in the data array is stored in the index array, and the data is stored in the data array, and the processing device includes:

[0096] An index position determination unit 401 is used to calculate a hash value of target data and calculate an index position according to the hash value;

[0097] An index array access unit 402, configured to access the index array according to the index position, and obtain the address of the target data corresponding to the index position in the data array;

[0098] The data array access unit 403 is used to access the data array according to the address of the target data in the data array, and perform the search, insertion or deletion operation of the target data.

[0099] In one implementation, the method further includes:

[0100] The hash conflict processing unit 404 is used to determine whether the same hash value is calculated for different data, and if so, determine that a hash conflict exists; organize the data array based on a balanced binary tree data structure, and process the hash conflict.

[0101] The hash conflict processing unit 404 is specifically used for:

[0102] If the root node is empty, that is, the position in the data array is empty, the data is directly placed in the corresponding position. If the root node is not empty, traverse from the root node to find the insertion position of the element to be inserted.

[0103] The hash conflict processing unit 404 is specifically used for:

[0104] When inserting into a binary search tree, record the nodes searched during the insertion process. After the insertion, search upward from the insertion node, performing rotation adjustments in sequence until the root node.

[0105] In one implementation,

[0106] The hash table includes an old hash table and an expanded new hash table, wherein the capacity of the new hash table is greater than the capacity of the old hash table;

[0107] The device further comprises a capacity expansion operation control unit 405, which is used to set a capacity expansion flag to indicate whether it is in a capacity expansion operation.

[0108] In one implementation, the capacity expansion operation control unit 405 is further configured to:

[0109] Read the expansion flag to determine whether the hash table is in an expansion operation;

[0110] If yes, determine the index array capacity and data array capacity of the new hash table according to the specified expansion size; and, in response to the data operation request, perform the following steps:

[0111] In response to a data insertion operation request, insert the data into the new hash table;

[0112] For a data search operation request, first search the old hash table, and if not found, then search in the new hash table;

[0113] For a data deletion operation request, the old hash table is first searched, and if found, it is deleted. If not found, it is searched and deleted in the new hash table.

[0114] In one implementation, the capacity expansion operation control unit 405 is further configured to:

[0115] After each hash expansion is completed, it is determined whether all elements in the old hash table have been migrated to the new hash table. If the expansion is completed, the expansion flag is reset.

[0116] An embodiment of the present application further provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0117] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:

[0118] Calculate a hash value of the target data, and calculate an index position according to the hash value;

[0119] Access the index array according to the index position to obtain the address of the target data corresponding to the index position in the data array;

[0120] According to the address of the target data in the data array, the data array is accessed to perform a search, insertion or deletion operation on the target data.

[0121] 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 computer programs.

[0122] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0123] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0124] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:

[0125] Calculate a hash value of the target data, and calculate an index position according to the hash value;

[0126] Access the index array according to the index position to obtain the address of the target data corresponding to the index position in the data array;

[0127] According to the address of the target data in the data array, the data array is accessed to perform a search, insertion or deletion operation on the target data.

[0128] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0129] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0130] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0131] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0132] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0133] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0134] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.

[0135] The above is only a preferred implementation 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 hash table processing method, characterized in that: The hash table includes an index array and a data array, wherein the address of data in the data array is stored in the index array, and the data is stored in the data array. The processing method includes: Calculate a hash value of the target data, and calculate an index position according to the hash value; Access the index array according to the index position to obtain the address of the target data corresponding to the index position in the data array; According to the address of the target data in the data array, the data array is accessed to perform a search, insertion or deletion operation on the target data.

2. The method according to claim 1, characterized in that Also includes: Determine whether the same hash value is calculated for different data, and if so, determine that there is a hash conflict; The data array is organized based on a balanced binary tree data structure, and the hash conflict is processed.

3. The method according to claim 2, characterized in that The data array is organized based on a balanced binary tree data structure, including: If the root node is empty and the position in the data array is determined to be empty, the data is directly placed in the corresponding position. If the root node is not empty, traverse from the root node to find the insertion position of the element to be inserted.

4. The method according to claim 2, characterized in that: The step of processing the hash conflict comprises: When inserting into a binary search tree, record the nodes searched during the insertion process. After the insertion, search upward from the insertion node, performing rotation adjustments in sequence until the root node.

5. The method according to any one of claims 1 to 4, characterized in that: The hash table includes an old hash table and an expanded new hash table, wherein the capacity of the new hash table is greater than the capacity of the old hash table; The method further includes: setting a capacity expansion flag to indicate whether the capacity expansion operation is in progress.

6. The method according to claim 5, characterized in that Also includes: Read the expansion flag to determine whether the hash table is in an expansion operation; If so, determine the index array capacity and data array capacity of the new hash table according to the specified size of the expansion; And, in response to the data operation request, perform the following steps: In response to a data insertion operation request, insert the data into the new hash table; For a data search operation request, first search the old hash table, and if not found, then search in the new hash table; For a data deletion operation request, the old hash table is first searched, and if found, it is deleted. If not found, it is searched and deleted in the new hash table.

7. The method according to claim 6, characterized in that Also includes: After each hash expansion is completed, it is determined whether all elements in the old hash table have been migrated to the new hash table. If the expansion is completed, the expansion flag is reset.

8. A hash table processing device, characterized in that: The hash table includes an index array and a data array, wherein the address of data in the data array is stored in the index array, and the data is stored in the data array, and the processing device includes: An index position determination unit, configured to calculate a hash value of the target data and calculate an index position according to the hash value; An index array access unit, used to access the index array according to the index position, and obtain the address of the target data corresponding to the index position in the data array; The data array access unit is used to access the data array according to the address of the target data in the data array, and perform the operation of searching, inserting or deleting the target data.

9. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.

10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and apparatus for removing call ticket repeat

    CN101442731A

  • Read and write operation method and apparatus

    CN105117471A

  • Hash table construction method and system for nonvolatile memory

    CN107153707A

  • Chain log storage structure, hash index structure and data operation method thereof, server and medium

    CN107515901A

  • Method and device for processing conflict of data of hash tables

    CN107992577A