A hash table generation method, device, apparatus and storage medium
By dynamically adjusting the insertion position based on the hash slot status and collision count in the hash table, the problems of low hash table construction efficiency and high collision count are solved, thereby improving the construction efficiency of the hash table and reducing the performance impact.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI DAMENG DATABASE
- Filing Date
- 2023-03-09
- Publication Date
- 2026-04-28
AI Technical Summary
Existing hash tables are inefficient to build and have many collisions on hash slots, which affects performance.
By obtaining the state of the hash slot position, if it is not the target state, it is inserted into the hash slot linked list; if the number of collisions exceeds the threshold, it is inserted into the next hash table, thus resolving the problem of excessive collisions.
This improves the efficiency of hash table construction and reduces the performance impact of construction operations.
Smart Images

Figure CN116186338B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for generating hash tables. Background Technology
[0002] Hash tables are a commonly used data structure that helps quickly locate and find data of equal value. They are frequently used for join operations, deduplication, and grouping. There are many ways to implement hash tables, such as chaining, where data located in the same slot is linked together using a linked list. The process of using a hash table is as follows:
[0003] 1. Create a hash table. Create a hash table based on the given size.
[0004] 2. Construct the hash table data. Insert the given data into the hash table. Based on a certain characteristic value of the data, use a specific hash function to calculate the hash value corresponding to that characteristic value, and then use that hash value to determine the position of the data in the hash slot in the hash table. After determining the hash slot, insert the data into the linked list at that hash slot.
[0005] In the process of using hash tables, the first step is to determine the size of the hash table, and the second step is to construct the hash table based on the actual data. If the size of the hash table is too small or the amount of data used to construct the hash table is too large, the linked list on each slot of the hash table will become too long, which will affect the efficiency of constructing the hash table.
[0006] Traditional dynamically expanding hash table method:
[0007] Method 1: When expanding a hash table of length N, add an additional hash table of length N. Expand the data from the original hash table into the new hash table using the hash value % 2 method. Hash value % 2 is the remainder when the hash value is divided by 2. The result can be 0 or 1. If the result is 0, the corresponding data can be kept in the original hash table; if the result is 1, the corresponding data can be moved to the new hash table. The old and new hash tables are combined into a single hash table.
[0008] Method 2: When expanding a hash table of length N, apply for a new hash table of length M (M>N, M is usually twice N), and re-insert all the data from the old hash table into the new hash table.
[0009] Both methods require expanding the entire dataset, resulting in low efficiency. Method one, due to data uncertainty, may fail to resolve collisions after expansion. Furthermore, if the expanded hash table still has too many collisions, a further expansion is needed, impacting performance. Summary of the Invention
[0010] This invention provides a hash table generation method, apparatus, device, and storage medium, which solves the problems of low efficiency in hash table construction and numerous collisions on hash slots in the constructed hash table. It can improve the construction efficiency of hash tables while reducing the impact of construction operations on performance.
[0011] According to one aspect of the present invention, a hash table generation method is provided, comprising:
[0012] Get the hash slot status corresponding to the first hash slot position of the first data in the current hash table;
[0013] If the hash slot state corresponding to the first hash slot position is not the target state, then the first data is inserted into the first hash slot linked list according to the first hash slot position;
[0014] If the number of collisions corresponding to the first hash slot position is greater than the number threshold, then the target data corresponding to the first hash slot position is inserted into the next hash table of the current hash table.
[0015] According to another aspect of the present invention, a hash table generation apparatus is provided, the hash table generation apparatus comprising:
[0016] The hash slot status acquisition module is used to obtain the hash slot status corresponding to the first hash slot position of the first data in the current hash table;
[0017] The first data insertion module is used to insert the first data into the first hash slot linked list according to the first hash slot position if the hash slot state corresponding to the first hash slot position is not the target state.
[0018] The second data insertion module is used to insert the target data corresponding to the first hash slot position into the next hash table of the current hash table if the number of collisions corresponding to the first hash slot position is greater than the number threshold.
[0019] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0020] At least one processor; and
[0021] A memory communicatively connected to the at least one processor; wherein,
[0022] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the hash table generation method according to any embodiment of the present invention.
[0023] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the hash table generation method according to any embodiment of the present invention.
[0024] This invention addresses the problems of low hash table construction efficiency and numerous hash slot collisions in the constructed hash table by obtaining the hash slot state corresponding to the first hash slot position of the first data in the current hash table; if the hash slot state corresponding to the first hash slot position is not the target state, then the first data is inserted into the first hash slot linked list according to the first hash slot position; if the number of collisions corresponding to the first hash slot position is greater than a threshold, then the target data corresponding to the first hash slot position is inserted into the next hash table of the current hash table. This improves the construction efficiency of the hash table while reducing the impact of the construction operation on performance.
[0025] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0026] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 This is a flowchart of a hash table generation method according to an embodiment of the present invention;
[0028] Figure 2 This is a schematic diagram of the structure of a hash table generation device according to an embodiment of the present invention;
[0029] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0030] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0032] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0033] Example 1
[0034] Figure 1 This is a flowchart illustrating a hash table generation method provided in an embodiment of the present invention. This embodiment is applicable to situations where hash tables are extended. The method can be executed by the hash table generation device in this embodiment, which can be implemented in software and / or hardware, such as... Figure 1 As shown, the method specifically includes the following steps:
[0035] S110, obtain the hash slot status corresponding to the first hash slot position of the first data in the current hash table.
[0036] The first data is the preset data used to create the hash table, which is the data to be inserted into the hash table.
[0037] The current hash table can be the first hash table in the hash table linked list. For example, it can be a regular hash table T0, with the following information recorded: Hash table index: 0 (because the current hash table is the first hash table, the hash table index starts from 0 and increments sequentially); The next hash table of the current hash table: initially empty, and updated according to the actual situation; The total length of the current hash table, i.e., the total number of slots N: the actual total number; The number of slots already used USED: initially 0, and updated according to the actual situation; The maximum collision limit for each slot CONFLICT_MAX: a preset value; The number of data with different hash values in the linked list of each slot M: initially all 0, and updated according to the actual situation; Whether each slot is expanded: initially marked as "not expanded", and updated according to the actual situation; The maximum total number of hash tables MAX_HASH_NUM: a preset value.
[0038] The hash slot state can be either a target state or a non-target state. For example, if the hash slot is marked as "unexpanded", then the hash slot state is determined to be a non-target state; if the hash slot is marked as "expanded", then the hash slot state is determined to be a target state.
[0039] Specifically, the method for obtaining the hash slot status corresponding to the first hash slot position of the first data in the current hash table can be as follows: obtain the feature value of the first data, calculate the hash value corresponding to the feature value of the first data using a specific hash function based on the feature value of the first data; then determine the position of the hash slot of the first data in the current hash table based on the hash value corresponding to the feature value of the first data; after determining the position of the hash slot, determine the hash slot status based on the tag corresponding to the position of the hash slot.
[0040] S120, if the hash slot state corresponding to the first hash slot position is not the target state, then insert the first data into the first hash slot linked list according to the first hash slot position.
[0041] Specifically, the state of the hash slot corresponding to the first hash slot position is determined. If the state of the hash slot corresponding to the first hash slot position is not the target state, the first data is inserted into the first hash slot linked list according to the first hash slot position.
[0042] It should be noted that after inserting the first data into the first hash slot linked list, the number of collisions corresponding to the first hash slot position is updated. For example, if the hash value of the first data already exists in the first hash slot linked list, the number of collisions remains unchanged; otherwise, the number of collisions is incremented by one.
[0043] S130, if the number of collisions corresponding to the first hash slot position is greater than the number threshold, then insert the target data corresponding to the first hash slot position into the next hash table of the current hash table.
[0044] It should be noted that when determining the hash slot position based on the hash value, there are cases where different hash values exist but the corresponding hash slot positions are the same. In this case, data with different hash values will be inserted into the linked list on that hash slot; this situation is called a data collision. The number of collisions mentioned in this embodiment is the number of data collisions, which is the number of different hash values existing in the hash slot linked list. For example, if the hash slot linked list contains data A, B, and C, and the hash values corresponding to the three data are H1, H2, and H2 respectively, then the number of collisions on the hash slot linked list is determined to be 2.
[0045] The quantity threshold can be a preset value, and this embodiment of the invention does not impose any restrictions on it.
[0046] The target data corresponding to the first hash slot position is all the data at the first hash slot position.
[0047] Specifically, the method for inserting target data into the next hash table of the current hash table can be as follows: If the current hash table is the last hash table in the hash table chain, then a new hash table needs to be created for the current hash table, and the target data is then inserted into the next hash table. If the current hash table is not the last hash table in the hash table chain, that is, if the hash table chain includes the current hash table and the next hash table, then the target data is directly inserted into the next hash table.
[0048] In a specific example, hash tables are linked together to form a dynamic hash table linked list. When inserting data, it is first inserted into the first hash table. If the hash slot to be inserted has been expanded (i.e., the hash slot state is the target state), the data to be inserted is inserted into the next hash table; otherwise (i.e., the hash slot state is not the target state), the data to be inserted is inserted into that hash slot. Then, it is determined whether there are too many collisions on the hash slot. If there are too many, all the data in the slot is inserted into the next hash table, and the hash slot state is marked as "expanded".
[0049] This invention only requires inserting the data in the hash slots with too many collisions in the current hash table into the next hash table. This way, only a small amount of data needs to be processed, which can greatly reduce the performance impact of data movement operations. Furthermore, this invention inserts all the data in the hash slots with too many collisions into a new hash table, which can effectively solve the problem of too many collisions.
[0050] Optionally, if the number of collisions corresponding to the first hash slot position is greater than a threshold, the target data corresponding to the first hash slot position is inserted into the next hash table of the current hash table, including:
[0051] Obtain the number of collisions corresponding to the first hash slot position;
[0052] If the number of collisions corresponding to the first hash slot position is greater than the number threshold, then the target data corresponding to the first hash slot position is obtained;
[0053] The position of the second hash slot in the next hash table of the current hash table is determined based on the feature value of the target data.
[0054] The target data is inserted into the second hash slot linked list according to the position of the second hash slot.
[0055] Each hash slot records the number of collisions, and the number of collisions for each hash slot is updated in real time.
[0056] Specifically, the method for determining the position of the second hash slot in the next hash table of the current hash table based on the feature value of the target data can be as follows: obtain the feature value of the target data, calculate the hash value corresponding to the feature value of the target data using a specific hash function based on the feature value of the target data, and then determine the position of the second hash slot in the next hash table of the current hash table based on the hash value corresponding to the feature value of the target data.
[0057] Specifically, the method of inserting the target data into the second hash slot linked list according to the second hash slot position can be as follows: if the hash slot state corresponding to the second hash slot position is not the target state, then the target data is inserted into the second hash slot linked list according to the second hash slot position.
[0058] In a specific example, the data at the first hash slot position of the current hash table is directly inserted into the next hash table of the current hash table (that is, traversing all the data, calculating its hash value according to the characteristic value of each data and the preset hash function, determining the hash slot position on the new hash table according to the hash value, and inserting the data into the linked list of that hash slot). The linked list at the first hash slot position of the current hash table is set to empty, and the state of the first hash slot of the current hash table is marked as "expanded".
[0059] Optionally, before obtaining the number of collisions corresponding to the first hash slot position, the method further includes:
[0060] If, after the first data is inserted into the first hash slot linked list, all hash values in the hash slot linked list are different from the hash value of the first data, then the number of collisions corresponding to the position of the first hash slot is updated.
[0061] Specifically, if after the first data is inserted into the first hash slot linked list, there is a hash value in the hash slot linked list that is the same as the hash value of the first data, then the number of collisions corresponding to the first hash slot position remains unchanged. If after the first data is inserted into the first hash slot linked list, all the hash values in the hash slot linked list are different from the hash value of the first data, then the number of collisions corresponding to the first hash slot position is updated.
[0062] Specifically, updating the number of collisions corresponding to the first hash slot position can be done by increasing the number of collisions corresponding to the first hash slot position by a preset value. For example, the number of collisions corresponding to the first hash slot position can be incremented by one.
[0063] Optional, also includes:
[0064] If the hash slot state corresponding to the first hash slot position is the target state, then obtain the third hash slot position of the first data in the next hash table of the current hash table;
[0065] If the hash slot state corresponding to the third hash slot position is not the target state, then the first data is inserted into the third hash slot linked list according to the third hash slot position.
[0066] It should be noted that if the hash table linked list includes both the current hash table and its next hash table, then the first piece of data is inserted into the next hash table. If the current hash table is the last hash table in the linked list, then a new hash table is created, and the first piece of data is inserted into that next hash table.
[0067] Furthermore, if the next hash table after the current hash table is a newly created hash table, the first data can be directly inserted into the next hash table. For example, if the hash slot state corresponding to the first hash slot position is the target state, then the third hash slot position of the first data in the next hash table is obtained, and the first data is inserted into the third hash slot linked list according to the third hash slot position. That is, since the next hash table after the current hash table is newly created, there is no need to judge the hash slot state corresponding to the third hash slot position; the first data can be directly inserted into the next hash table.
[0068] Optional, also includes:
[0069] If the current hash table is the last hash table in the hash table chain, then get the number of hash slots used in the current hash table and the expansion factor;
[0070] A hash table is created based on the number of hash slots already used in the current hash table and the expansion factor, and the created hash table is determined as the next hash table after the current hash table.
[0071] The number of used hash slots is the number of hash slots into which data has been inserted. The length of the next hash table of the current hash table can be the product of the number of used hash slots in the current hash table and the expansion factor.
[0072] The expansion factor can be determined based on at least one of the following: the number of times the hash table linked list has been expanded, the number of collisions in the current hash table, and the length of the current hash table. For example, the expansion factor can be determined based on the number of times the hash table linked list has been expanded.
[0073] Specifically, the method for creating a hash table based on the number of hash slots already used in the current hash table and the expansion factor can be as follows: determine the length of the next hash table based on the number of hash slots already used in the current hash table and the expansion factor, and create the hash table based on the length of the next hash table.
[0074] Optionally, obtaining the expansion factor includes:
[0075] The expansion factor is determined based on the number of times the hash table's linked list has been expanded, the number of collisions in the current hash table, and the length of the current hash table.
[0076] In a specific example, the process of constructing a hash table based on given data using a dynamically expanding hash table method is as follows:
[0077] Step 1): Create a regular hash table T0 and record the following information in it:
[0078] Hash table index: 0 (because this is the first hash table, and hash table indices start from 0 and increment sequentially).
[0079] The next hash table after the current hash table: initially empty, and subsequently updated based on the actual situation;
[0080] The total length of the current hash table, i.e., the total number of slots N: the actual total number of slots;
[0081] The number of slots already used (USED): Initially 0, and will be updated based on the actual situation.
[0082] Maximum conflict limit per slot CONFLICT_MAX: default value;
[0083] The number of distinct hash values M in the linked list for each slot is initially 0 and will be updated based on actual conditions.
[0084] Whether each slot is expanded: Initially, it is "not expanded", and will be updated according to the actual situation.
[0085] Maximum total number of hash tables (MAX_HASH_NUM): Default value;
[0086] Step 2): Traverse the given data, calculate the corresponding hash value based on the feature value of each first data, and use the preset hash function to set the hash table T0 as the current hash table T to be inserted, and proceed to Step 3).
[0087] Step 3): Determine the position of the first data in the hash slot of hash table T based on the hash value. If the hash slot has been expanded, that is, the hash slot is in the target state, then take the next hash table of the current hash table T as the new hash table T and proceed to step 3). If the hash slot has not been expanded, that is, the hash slot is not in the target state, then insert the first data into the linked list on the hash slot and update the M value corresponding to the hash slot (if the hash value of the first data already exists in the linked list of the hash slot, then M remains unchanged; otherwise, M is incremented by 1). If M is greater than CONFLICT_MAX, proceed to step 4). If M is less than or equal to CONFLICT_MAX, proceed to step 7.
[0088] Step 4): If a next hash table exists for the current hash table T, proceed to step 6); otherwise, proceed to step 5.
[0089] Step 5): Expand the hash table: If the total number of hash tables is MAX_HASH_NUM, proceed to step 7); otherwise, set the extension factor EXTEND_FACTOR. Create a new hash table based on the number of used slots in the current hash table T (USED) and the extension factor EXTEND_FACTOR. The length N of the new hash table is USED multiplied by EXTEND_FACTOR. If creation is successful, record the next hash table of the current hash table T as the name of the new hash table and proceed to step 6); if creation fails, proceed to step 7).
[0090] Step 6): Move data: Directly insert all the data in the hash slot of hash table T into the newly created hash table (i.e., traverse all the data, calculate its hash value according to the characteristic value of each data and the preset hash function, determine the hash slot position on the new hash table according to the hash value, and insert the data into the hash slot linked list). Set the linked list on the hash slot of hash table T to empty, and mark the hash slot of hash table T as "expanded"; proceed to step 7).
[0091] Step 7): Continue iterating through the given data, performing Step 2), until the iteration is complete, at which point the hash table construction is finished.
[0092] Optional, also includes:
[0093] Get the hash slot status corresponding to the fourth hash slot position of the probe data in the current hash table;
[0094] If the hash slot state corresponding to the fourth hash slot position is not the target state, then query the fourth hash slot linked list to obtain data that matches the probe data.
[0095] The expansion factor is a value automatically set by the system based on factors such as the current number of times the dynamic hash table has been expanded, the current collision situation of the hash table, and the total length of the hash table. For example, it can be 2. This value is not necessarily the same each time the hash table is expanded.
[0096] It's important to note that after constructing the hash table, it needs to be probed. Probing the hash table means that for a given probe data, you need to find matching data within the hash table. This involves first calculating the hash value corresponding to the feature value of the probe data using a hash function, then determining the hash slot of the data in the hash table based on that hash value, and finally searching for matching data in the linked list on that hash slot.
[0097] The probe data is used to probe the hash table.
[0098] The fourth hash slot linked list is a linked list on the fourth hash slot.
[0099] The hash table generation method provided in this invention extends the hash table, thereby improving the hash table's detection efficiency.
[0100] Optional, also includes:
[0101] If the hash slot state corresponding to the fourth hash slot position is the target state, then the hash slot state corresponding to the fifth hash slot position in the next hash table of the current hash table is determined according to the hash value corresponding to the probe data.
[0102] If the hash slot state corresponding to the fifth hash slot position is not the target state, then query the fifth hash slot linked list to obtain data that matches the probe data.
[0103] Specifically, the method for determining the hash slot state corresponding to the fifth hash slot position in the next hash table of the current hash table based on the hash value corresponding to the probe data can be as follows: obtain the feature value of the probe data; calculate the hash value corresponding to the feature value of the probe data using a specific hash function based on the feature value of the probe data; then determine the fifth hash slot position of the probe data in the next hash table of the current hash table based on the hash value corresponding to the feature value of the probe data; obtain the tag information corresponding to the fifth hash slot position; and determine the hash slot state corresponding to the fifth hash slot position based on the tag information corresponding to the fifth hash slot position.
[0104] In a specific example, the process of probing the hash table based on probe data using the dynamically expanding hash table method is as follows:
[0105] Step 1): Traverse the probe data, calculate the corresponding hash value using the preset hash function based on the feature value of the probe data, and use hash table T0 as the current hash table T to be probed, then proceed to step 2).
[0106] Step 2): Determine the position of the data in the hash slot of hash table T based on the hash value. If the hash slot has been expanded, that is, the hash slot is in the target state, then the next hash table of the current hash table T is used as the new hash table T, and Step 2) is performed. If the hash slot has not been expanded, that is, the hash slot is not in the target state, then the matching data is searched in the linked list on the hash slot, and Step 3) is performed.
[0107] Step 3): Continue traversing the probe data and performing Step 2) until the traversal is complete, at which point the probe hash table is finished.
[0108] Optional, also includes:
[0109] Get the hash slot expansion ratio for each hash table in the hash table linked list;
[0110] Unexpanded data in the target hash table whose hash slot expansion ratio is greater than the ratio threshold is inserted into the next hash table of the target hash table, and the target hash table is deleted from the hash table chain.
[0111] Specifically, the method to obtain the hash slot expansion ratio corresponding to each hash table in the hash table linked list can be as follows: obtain the number of hash slots in the target state and the total number of hash slots corresponding to each hash table in the hash table linked list; determine the hash slot expansion ratio corresponding to each hash table based on the number of hash slots in the target state and the total number of hash slots corresponding to each hash table.
[0112] The ratio threshold can be preset, for example, it can be 85%.
[0113] It's important to note that, based on the dynamically expanding hash table method, after successfully constructing the hash table, if subsequent probing of the hash table is needed, the dynamic hash table linked list is further simplified: traversing the dynamic hash table linked list, when it's found that 85% of the hash slots in one hash table have been expanded, the data on the remaining 15% of hash slots is expanded to the next hash table, and that hash table is removed from the dynamic hash table linked list. This reduces the length of the dynamic hash table linked list and improves probing efficiency.
[0114] The technical solution of this embodiment obtains the hash slot state corresponding to the first hash slot position of the first data in the current hash table; if the hash slot state corresponding to the first hash slot position is not the target state, the first data is inserted into the first hash slot linked list according to the first hash slot position; if the number of collisions corresponding to the first hash slot position is greater than the number threshold, the target data corresponding to the first hash slot position is inserted into the next hash table of the current hash table. This solves the problems of low efficiency in building hash tables and a large number of collisions on the hash slots of the constructed hash table, and can improve the construction efficiency of hash tables while reducing the impact of construction operations on performance.
[0115] Example 2
[0116] Figure 2 This is a schematic diagram of a hash table generation device provided in an embodiment of the present invention. This embodiment is applicable to situations where hash tables need to be extended. The device can be implemented using software and / or hardware, and can be integrated into any device that provides hash table generation functionality, such as… Figure 2 As shown, the hash table generation device specifically includes: a hash slot status acquisition module 210, a first data insertion module 220, and a second data insertion module 230.
[0117] The hash slot status acquisition module is used to acquire the hash slot status corresponding to the first hash slot position of the first data in the current hash table.
[0118] The first data insertion module is used to insert the first data into the first hash slot linked list according to the first hash slot position if the hash slot state corresponding to the first hash slot position is not the target state.
[0119] The second data insertion module is used to insert the target data corresponding to the first hash slot position into the next hash table of the current hash table if the number of collisions corresponding to the first hash slot position is greater than the number threshold.
[0120] The above-described products can perform the methods provided in any embodiment of the present invention, and have the corresponding functional modules and beneficial effects for performing the methods.
[0121] Example 3
[0122] Figure 3 A schematic diagram of an electronic device 10 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0123] like Figure 3 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0124] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0125] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as hash table generation methods.
[0126] In some embodiments, the hash table generation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the hash table generation method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the hash table generation method by any other suitable means (e.g., by means of firmware).
[0127] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0128] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0129] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0130] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0131] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0132] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0133] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and no limitation is imposed herein.
[0134] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for generating a hash table, characterized in that, include: Obtain the hash slot status corresponding to the first hash slot position of the first data in the current hash table. The hash slot status includes target status and non-target status. If the hash slot is marked as "not expanded", then the hash slot status is determined to be non-target status. If the hash slot is marked as "expanded", then the hash slot status is determined to be target status. If the hash slot state corresponding to the first hash slot position is not the target state, then the first data is inserted into the first hash slot linked list according to the first hash slot position; If the number of collisions corresponding to the first hash slot position is greater than the number threshold, then the target data corresponding to the first hash slot position is inserted into the next hash table of the current hash table. The number of collisions is the number of different hash values existing in the hash slot linked list. If the number of collisions corresponding to the first hash slot position is greater than the threshold, then the target data corresponding to the first hash slot position is inserted into the next hash table of the current hash table, including: Obtain the number of collisions corresponding to the first hash slot position; If the number of collisions corresponding to the first hash slot position is greater than the number threshold, then the target data corresponding to the first hash slot position is obtained; The position of the second hash slot in the next hash table of the current hash table is determined based on the feature value of the target data. The target data is inserted into the second hash slot linked list according to the position of the second hash slot, and the hash slot status is marked as "expanded".
2. The method according to claim 1, characterized in that, Before obtaining the number of collisions corresponding to the first hash slot position, the process also includes: If, after the first data is inserted into the first hash slot linked list, all hash values in the hash slot linked list are different from the hash value of the first data, then the number of collisions corresponding to the position of the first hash slot is updated.
3. The method according to claim 1, characterized in that, Also includes: If the hash slot state corresponding to the first hash slot position is the target state, then obtain the third hash slot position of the first data in the next hash table of the current hash table; If the hash slot state corresponding to the third hash slot position is not the target state, then the first data is inserted into the third hash slot linked list according to the third hash slot position.
4. The method according to claim 1, characterized in that, Also includes: If the current hash table is the last hash table in the hash table chain, then get the number of hash slots used in the current hash table and the expansion factor; A hash table is created based on the number of hash slots already used in the current hash table and the expansion factor, and the created hash table is determined as the next hash table after the current hash table.
5. The method according to claim 4, characterized in that, Obtaining the expansion factor includes: The expansion factor is determined based on the number of times the hash table's linked list has been expanded, the number of collisions in the current hash table, and the length of the current hash table.
6. The method according to claim 1, characterized in that, Also includes: Get the hash slot status corresponding to the fourth hash slot position of the probe data in the current hash table; If the hash slot state corresponding to the fourth hash slot position is not the target state, then query the fourth hash slot linked list to obtain data that matches the probe data.
7. The method according to claim 6, characterized in that, Also includes: If the hash slot state corresponding to the fourth hash slot position is the target state, then the hash slot state corresponding to the fifth hash slot position in the next hash table of the current hash table is determined according to the hash value corresponding to the probe data. If the hash slot state corresponding to the fifth hash slot position is not the target state, then query the fifth hash slot linked list to obtain data that matches the probe data.
8. The method according to claim 1, characterized in that, Also includes: Get the hash slot expansion ratio for each hash table in the hash table linked list; Unexpanded data in the target hash table whose hash slot expansion ratio is greater than the ratio threshold is inserted into the next hash table of the target hash table, and the target hash table is deleted from the hash table chain.
9. A hash table generation device, characterized in that, include: The hash slot status acquisition module is used to acquire the hash slot status corresponding to the first hash slot position of the first data in the current hash table. The hash slot status includes target status and non-target status. If the hash slot is marked as "not expanded", the hash slot status is determined to be non-target status. If the hash slot is marked as "expanded", the hash slot status is determined to be target status. The first data insertion module is used to insert the first data into the first hash slot linked list according to the first hash slot position if the hash slot state corresponding to the first hash slot position is not the target state. The second data insertion module is used to insert the target data corresponding to the first hash slot position into the next hash table of the current hash table if the number of collisions corresponding to the first hash slot position is greater than the number threshold. The number of collisions is the number of different hash values existing in the hash slot linked list. The second data insertion module is specifically used to obtain the number of collisions corresponding to the first hash slot position; if the number of collisions corresponding to the first hash slot position is greater than the number threshold, then the target data corresponding to the first hash slot position is obtained. The position of the target data in the second hash slot of the next hash table in the current hash table is determined based on the feature value of the target data; the target data is inserted into the second hash slot linked list according to the position of the second hash slot, and the hash slot status is marked as "expanded".
10. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the hash table generation method according to any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the hash table generation method according to any one of claims 1-8.
Citation Information
Patent Citations
Method and equipment for storing updated web pages, web page storage system and web page search system
CN106844706A
Progressive re-hashing method and device, computer equipment and storage medium
CN109828966A
Detection method and device based on Hash connection, equipment and storage medium
CN112765174A