A dynamic hashing method, device, equipment and storage medium

By obtaining the historical data of the user environment, dynamically generate hash functions and tables, optimize the hash algorithm, solve the problem of different efficiency of static hash algorithms in different environments, and improve program operation efficiency.

CN112463795BActive Publication Date: 2025-01-24HANGZHOU DBAPPSECURITY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011347256.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-26
Publication Date
2025-01-24
Estimated Expiration
2040-11-26

AI Technical Summary

Technical Problem

Conventional static hashing algorithms cannot be optimized according to changes in the user environment, resulting in different efficiency of hashing algorithms in different environments, which affects the operation efficiency of the program.

Method used

By obtaining historical access data, determine the frequency of access to the records, and generate the corresponding hash functions and hash tables to optimize the records of frequent visits, reduce the possibility of hash conflict, and dynamically update the hash algorithm.

Benefits of technology

It improves the efficiency of the hash algorithm and reduces the possibility of hash conflicts, thus improving the operating efficiency of the program to which the hash algorithm belongs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112463795B_ABST
    Figure CN112463795B_ABST
Patent Text Reader

Abstract

The present invention discloses a dynamic hash method, device, equipment and storage medium, the method comprising: obtaining historical data of historical accesses to an original hash table to be updated, and determining the frequency of historical accesses to corresponding records in the original hash table based on the historical data; generating a corresponding hash function based on the frequency corresponding record higher than the frequency threshold, so that the possibility of hash collision when accessing the record with a frequency higher than the frequency threshold based on the generated hash function is the lowest; creating a hash table corresponding to the generated hash function, and inserting each record contained in the original hash table into the generated hash table according to the generated hash function; replacing the original hash table with the generated hash table, and replacing the hash function corresponding to the original hash table with the generated hash function. The present application can improve the efficiency of the hash algorithm, thereby improving the program operation efficiency of the program to which the hash algorithm belongs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of hash technology, and more specifically, to a dynamic hash method, device, equipment and storage medium. Background Art

[0002] Hash can compress a message of any length into a message digest of a fixed length. When using a hash algorithm to implement record query, the records that need to be accessed are usually stored in a hash table, and the corresponding hash function is used to calculate the key value used to implement the record query to obtain the corresponding hash value, and then the record at the position corresponding to the hash value is queried in the hash table, which is the record that needs to be accessed; however, conventional static hash algorithms will not be optimized as the user environment changes, so there is a problem that the same hash algorithm in different environments has different efficiencies, thereby affecting the program running efficiency of the program to which it belongs. Summary of the invention

[0003] The purpose of the present invention is to provide a dynamic hash method, device, equipment and storage medium, which can improve the efficiency of the hash algorithm and further improve the program running efficiency of the program to which the hash algorithm belongs.

[0004] In order to achieve the above object, the present invention provides the following technical solutions:

[0005] A dynamic hashing method, comprising:

[0006] Obtain historical data of historical accesses to the original hash table to be updated, and determine the frequency of historical accesses to corresponding records in the original hash table based on the historical data;

[0007] Generate a corresponding hash function based on the frequency corresponding records above the frequency threshold, so as to minimize the probability of hash collision when accessing the records with the frequency above the frequency threshold based on the generated hash function;

[0008] Creating a hash table corresponding to the generated hash function, and inserting each record contained in the original hash table into the generated hash table according to the generated hash function;

[0009] The generated hash table is used to replace the original hash table, and the generated hash function is used to replace the hash function corresponding to the original hash table.

[0010] Preferably, according to the generated hash function, each record contained in the original hash table is inserted into the generated hash table, including:

[0011] If there are multiple records with the same hash value obtained based on the generated hash function, it is determined that the multiple records corresponding to the same hash value belong to the same bucket in the generated hash table, and according to the principle that the higher the frequency, the earlier the position in the corresponding bucket, the multiple records corresponding to the same hash value are inserted into the corresponding bucket of the hash table.

[0012] Preferably, it also includes:

[0013] In the process of inserting all the records contained in the original hash table into the generated hash table, if an information request sent by a user is received, the record corresponding to the information request is queried in the generated hash table. If the search is successful, the found record is returned to the user. Otherwise, the record corresponding to the information request is queried in the original hash table.

[0014] Preferably, after replacing the original hash table with the generated hash table, the method further includes:

[0015] The original hash table is recycled, and the cache corresponding to the original hash table is cleared.

[0016] Preferably, before obtaining the historical data of the original hash table to be updated, the method further includes:

[0017] Monitor the host CPU, memory, the status of the original hash table and the performance of the original hash table. If it is monitored that the idle resources contained in the host CPU are less than the preset resources, and / or the storage space contained in the memory is less than the preset space, and / or the number of records contained in the original hash table is greater than the record threshold, and / or the query efficiency of the original hash table is lower than the efficiency threshold, execute the step of obtaining historical data of historical accesses to the original hash table to be updated.

[0018] Preferably, it also includes:

[0019] The historical data of the original hash table to be updated that was accessed within a preset time period before the current moment is collected periodically, and the collected historical data is stored in the memory or file for retrieval.

[0020] Preferably, before reclaiming the original hash table, the method further includes:

[0021] Output an option of whether to recycle the original hash table. If a recycle instruction based on the option is received from the outside, execute the step of reclaiming the original hash table. Otherwise, transfer the original hash table to a specified location for storage.

[0022] A dynamic hashing device, comprising:

[0023] An acquisition module, used to: acquire historical data of historical accesses to the original hash table to be updated, and determine the frequency of historical accesses to corresponding records in the original hash table based on the historical data;

[0024] A generation module, configured to: generate a corresponding hash function based on the frequency corresponding records above the frequency threshold, so as to minimize the possibility of hash collision when accessing the records with the frequency above the frequency threshold based on the generated hash function;

[0025] A creation module, used to: create a hash table corresponding to the generated hash function, and insert each record contained in the original hash table into the generated hash table according to the generated hash function;

[0026] The replacement module is used to: replace the original hash table with the generated hash table, and replace the hash function corresponding to the original hash table with the generated hash function.

[0027] A dynamic hash device, characterized by comprising:

[0028] Memory for storing computer programs;

[0029] A processor is used to implement the steps of the dynamic hash method as described in any one of the above items when executing the computer program.

[0030] A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the dynamic hash method as described in any one of the above items.

[0031] The present invention provides a dynamic hash method, device, equipment and storage medium, the method comprising: obtaining historical data of historical accesses to an original hash table to be updated, and determining the frequency of historical accesses to corresponding records in the original hash table based on the historical data; generating a corresponding hash function based on the corresponding records with a frequency higher than a frequency threshold, so that the possibility of hash collision occurring when the records with a frequency higher than the frequency threshold are accessed based on the generated hash function is minimized; creating a hash table corresponding to the generated hash function, and inserting all records contained in the original hash table into the generated hash table according to the generated hash function; replacing the original hash table with the generated hash table, and replacing the hash function corresponding to the original hash table with the generated hash function. In the technical solution disclosed in the present application, the frequency of the user's historical access to the corresponding records is determined based on the data of the user's historical access to the records in the original hash table. After determining the records most frequently visited by the user, a hash function with the lowest possibility of hash conflicts when accessing these records is generated, and a new hash table is generated. The records in the original hash table are inserted into the new hash table according to the hash function, and finally the new hash function and the new hash table are used to replace the original hash function and the original hash table; thereby, the hash algorithm is dynamically updated based on the user's access to records in different environments, so that the records most frequently visited by users in the corresponding environment have the lowest possibility of hash conflicts when accessed after the hash algorithm is dynamically updated, thereby improving the efficiency of the hash algorithm, and further improving the program running efficiency of the program to which the hash algorithm belongs. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0033] Figure 1 A flow chart of a dynamic hashing method provided by an embodiment of the present invention;

[0034] Figure 2 A schematic diagram of implementing a dynamic hashing method provided by an embodiment of the present invention;

[0035] Figure 3 A schematic diagram of the function implementation of a historical record module in a dynamic hash method provided by an embodiment of the present invention;

[0036] Figure 4 A schematic diagram of the function implementation of a hash algorithm generation module in a dynamic hash method provided by an embodiment of the present invention;

[0037] Figure 5A schematic diagram of the function implementation of a hash replacement module in a dynamic hash method provided by an embodiment of the present invention;

[0038] Figure 6 A schematic diagram of the structure of a dynamic hashing device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0039] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0040] See also Figure 1 , which shows a flow chart of a dynamic hashing method provided by an embodiment of the present invention, which may include:

[0041] S11: Obtain historical data of historical accesses to the original hash table to be updated, and determine the frequency of historical accesses to corresponding records in the original hash table based on the historical data.

[0042] The execution subject of a dynamic hash method provided in an embodiment of the present invention may be a corresponding dynamic hash device. Wherein, updating the hash algorithm includes updating the hash function and the hash table. The hash function is a function that needs to calculate the key value used to implement the record query to obtain its hash value (the hash value corresponds to the position of the record to be queried in the hash table). The hash table is a table storing the records to be queried, and the record is the data to be queried; in the embodiment of the present application, the original hash table is the hash table to be updated, and the hash function corresponding to the original hash table is the hash function to be updated. Specifically, when it is necessary to implement the update of the hash algorithm, the historical data of the original hash table can be obtained. The historical data can be the data obtained on the user side (user environment), which includes the records and the number of times in the original hash table that were accessed before the current moment (that is, in history). The number is the frequency of accessing the corresponding record. If the frequency is higher, it means that the corresponding record is accessed more frequently, that is, the corresponding record is more likely to be a record that the user needs to access frequently.

[0043] S12: Generate a corresponding hash function based on the records corresponding to the frequencies higher than the frequency threshold, so as to minimize the possibility of hash collision when accessing the records with the frequencies higher than the frequency threshold based on the generated hash function.

[0044] The frequency threshold can be a value set according to actual needs. If the frequency of accessing any record is higher than the frequency threshold, it means that the access to the arbitrary record is relatively frequent, and the arbitrary record is data that the user needs to access frequently. Based on the frequency records higher than the frequency threshold and the principle of the hash function, a corresponding low-collision hash function (i.e., a new hash function) can be generated, and the low-collision hash function is the one that has the lowest hash conflict when the hash value calculated by the hash function is used to access the frequency records higher than the frequency threshold. Among them, hash conflict has the same meaning as the corresponding concept in the prior art, that is, the hash values ​​corresponding to different records are the same, and at this time, these records should belong to the same position in the hash table.

[0045] S13: Create a hash table corresponding to the generated hash function, and insert all records contained in the original hash table into the generated hash table according to the generated hash function.

[0046] After generating a new hash function, it is also necessary to create a hash table corresponding to the new hash function, that is, a new hash table; specifically, the created new hash table is a hash table that does not contain any records, and then the records in the original hash table are traversed and all inserted into the new hash table. Among them, when inserting the records in the original hash table into the new hash table, it is implemented according to the new hash function, that is, after determining the new hash function, the hash value corresponding to the new hash function for each record in the original hash table can be determined, and the hash value corresponds to the position of the record in the new hash table. Therefore, when inserting the records in the original hash table into the new hash table, the hash value corresponding to the new hash function for any record in the original hash table is first determined, and then the arbitrary record is inserted into the position in the new hash table corresponding to the determined hash value, thereby realizing the insertion of all records in the original hash table into the new hash table.

[0047] S14: Use the generated hash table to replace the original hash table, and use the generated hash function to replace the hash function corresponding to the original hash table.

[0048] The original hash table is replaced with a new hash table, and the hash function corresponding to the original hash table (which may be referred to as the original hash function in the embodiment of the present application) is replaced with a new hash function, thereby realizing dynamic hashing based on the historical data of user access records.

[0049] In the technical solution disclosed in the present application, the frequency of the user's historical access to the corresponding records is determined based on the data of the user's historical access to the records in the original hash table. After determining the records most frequently visited by the user, a hash function with the lowest possibility of hash conflicts when accessing these records is generated, and a new hash table is generated. The records in the original hash table are inserted into the new hash table according to the hash function, and finally the new hash function and the new hash table are used to replace the original hash function and the original hash table; thereby, the hash algorithm is dynamically updated based on the user's access to records in different environments, so that the records most frequently visited by users in the corresponding environment have the lowest possibility of hash conflicts when accessed after the hash algorithm is dynamically updated, thereby improving the efficiency of the hash algorithm, and further improving the program running efficiency of the program to which the hash algorithm belongs.

[0050] A dynamic hash method provided by an embodiment of the present invention inserts each record contained in an original hash table into a generated hash table according to a generated hash function, which may include:

[0051] If there are multiple records with the same hash value based on the generated hash function, it is determined that the multiple records corresponding to the same hash value belong to the same bucket in the generated hash table, and the multiple records corresponding to the same hash value are inserted into the corresponding bucket of the hash table according to the principle that the higher the frequency, the earlier the position in the corresponding bucket.

[0052] An embodiment of the present application can set a bucket for each position in the new hash table. Thus, when multiple records have the same hash value corresponding to the new hash function, that is, the positions of these multiple records in the new hash table should be the same, these records that should be in the same position can be stored in the bucket at that position. For records in the same bucket, the query is implemented by traversing the records in the bucket. Therefore, the closer the position of the record in the bucket is, the sooner it will be traversed and queried. Based on this, for records that should be in the same bucket, when inserting these records into the new hash table, the present application can store the records in a manner such that the higher the frequency, the closer the position is, thereby further improving the efficiency of the hash algorithm.

[0053] It should be noted that the data on the user side has higher characteristic performance within a certain time and space. For example, the IP used by the IP-based hash algorithm on the user side is not the full IP segment, but the IP data of the specific IP segment. The hash input IP will not change within a certain time and space; based on the hash algorithm for scheduling internal game items, when users run the game, each user has different tendencies to use the items in the game due to their own relevance and preferences. Based on this, an example is given to illustrate the dynamic update of the hash algorithm implemented in the present application. For example, based on the IP hash algorithm, the user's historical data is collected on the user side to analyze the user's network segment information, the unchanged network bit information in the network segment information is removed, and the host bit in the network segment information is hashed, that is, the most frequently communicated IP is stored in the hash table with the hash value corresponding to the lowest conflict hash function, and the frequently communicated IP is stored in the front position of the corresponding bucket in the hash table, so that when the user hashes again, the data is hit once with a high probability, thereby improving the program running efficiency; another example is based on the hash algorithm inside the game, by recording the user's item identification ID (such as number, etc.) and analyzing the item identification ID of the item frequently used by the user, the item identification ID of the top 50% of the most commonly used items is taken for low-conflict hash algorithm generation, and the hash of the item identification ID used by the user is prioritized to reduce the program response time during the user's routine operations.

[0054] A dynamic hashing method provided by an embodiment of the present invention may further include:

[0055] In the process of inserting all the records contained in the original hash table into the generated hash table, if an information request sent by the user is received, the record corresponding to the information request is queried in the generated hash table. If the search is successful, the found record is returned to the user. Otherwise, the record corresponding to the information request is queried in the original hash table.

[0056] It should be noted that in the process of inserting the records contained in the original hash table into the new hash table, if an information request sent by the user is received, that is, a request for querying the corresponding records, the records corresponding to the information request are preferentially queried in the new hash table. If the query is successful, there is no need to query the original hash table again. If the query fails, the records corresponding to the information request are queried in the original hash table and returned to the user after the query is successful, and information about the query failure is returned to the user after the query fails. It can be seen that in the process of implementing dynamic hash updates, the present application combines the original hash table and the new hash table to implement the query of corresponding records, thereby reducing the impact on the corresponding program and user query behavior in the process of implementing dynamic hash updates.

[0057] A dynamic hash method provided by an embodiment of the present invention may further include: after replacing the original hash table with the generated hash table,

[0058] Recycle the original hash table and clean up the cache corresponding to the original hash table.

[0059] Among them, after the new hash table replaces the original hash table, that is, after all records in the original hash table are inserted into the new hash table, the original hash table can be recycled and the cache corresponding to the original hash table can be cleared, thereby avoiding the storage space occupied by the original hash table that is no longer needed.

[0060] A dynamic hash method provided by an embodiment of the present invention may further include, before obtaining historical data of historical accesses to an original hash table to be updated:

[0061] Monitor the host CPU, memory, the status of the original hash table and the performance of the original hash table. If it is monitored that the idle resources contained in the host CPU are less than the preset resources, and / or the storage space contained in the memory is less than the preset space, and / or the number of records contained in the original hash table is greater than the record threshold, and / or the query efficiency of the original hash table is lower than the efficiency threshold, then execute the step of obtaining historical data of historical accesses to the original hash table to be updated.

[0062] Among them, the host CPU is the CPU contained in the host where the program to which the hash algorithm belongs is located, the memory is the memory contained in the host, the state of the original hash table includes the number of records contained in the original hash table, the performance of the original hash table is the query efficiency within a specified period of time, and the query efficiency is the total number of times the records in the hash table are accessed within a specified period of time, divided by the average time used for each access to the records in the hash table, and the preset resources, preset space, record threshold and efficiency threshold can all be set according to actual conditions. Since the host CPU and memory are required to implement the hash algorithm, in order to reduce the occupancy of both or either of them when they are insufficient, the hash algorithm can be updated; in addition, if the original hash table contains too many records and / or the query efficiency of the original hash table is too low, in order to avoid the inability to have more records and to improve the query efficiency of the original hash table, the hash algorithm can be updated.

[0063] In addition, the hash algorithm can be dynamically updated when the user's environment changes. It should be noted that since the process of collecting the user's historical data will consume some storage space, and the historical data analysis will also occupy a certain amount of host CPU and memory, the process of dynamically updating the hash also requires that the host CPU's idle resources and memory storage space are not too low (not lower than the corresponding minimum threshold).

[0064] A dynamic hashing method provided by an embodiment of the present invention may further include:

[0065] The historical data of the original hash table to be updated that was accessed within a preset time period before the current moment is collected periodically, and the collected historical data is stored in the memory or file for retrieval.

[0066] It should be noted that the embodiment of the present application can collect the historical data of the user within the time interval before the current moment at a certain time interval, which can specifically include source data and destination data, wherein the source data is the key value used when the record query needs to be realized, or it is called input data, and the destination data is the data output after the hash is completed, that is, the record; the historical data is stored in the memory or file, and then the host CPU, memory, hash table status and hash table performance are monitored, so as to obtain the historical data collected for the last time at an appropriate time, and then realize the dynamic update of the hash algorithm based on the historical data obtained. Therefore, through the regular collection of historical data, it is ensured that the required historical data can be quickly obtained when needed, and the efficiency of the dynamic update of the hash algorithm is improved.

[0067] A dynamic hash method provided by an embodiment of the present invention may further include the following steps before reclaiming the original hash table:

[0068] Output the option of whether to recycle the original hash table. If a recycling instruction based on the option input is received from the outside, the step of recycling the original hash table is executed. Otherwise, the original hash table is transferred to the specified location for storage.

[0069] Among them, the designated location can be determined according to actual needs; it should be noted that, considering that the user may need to obtain each version of the hash table in history, the embodiment of the present application can also output options. After the user enters a recycling instruction based on the option, it is determined based on the recycling instruction whether the original hash table needs to be recycled, thereby further improving the user experience.

[0070] In a specific application scenario, a dynamic hash method provided by an embodiment of the present invention can be implemented based on a historical data recording module, a hash algorithm generation module, and a hash replacement module. These three modules respectively complete the three functions of data collection, data analysis, and hash replacement. These three modules are linked to generate a dynamic update of the hash algorithm based on user-side data; the implementation process is as follows: Figure 2 As shown, the user data is the user's historical data.

[0071] like Figure 3 As shown, the history record module collects historical data including source data and destination data, organizes the data format of the historical data, records the historical data into memory or a file, and monitors the current host CPU, memory, hash table status and hash table performance (may also include hard disk light) to wake up the hash algorithm generation module at the appropriate time.

[0072] like Figure 4As shown, the hash algorithm generation module can also be called the analysis module, which is the core module for dynamically updating the hash algorithm. It generates a new hash algorithm (including hash functions and hash tables) by analyzing the user's historical data and hash table performance.

[0073] like Figure 5 As shown, after the hash replacement module generates a new hash function and hash table, it is necessary to implement the original hash table (i.e. Figure 5 The old hash table in the program is replaced with a new hash table; and the new hash algorithm is used to replace the original hash algorithm. During the replacement process, two hash table items need to be maintained, and the nodes are inserted into the new hash table by traversing the old hash table; during the program replacement process, the user first queries the new hash table, and when the queried node (i.e., record) does not exist, the old hash table is queried, thereby reducing the impact on the program during the replacement process; after the replacement is completed, the old hash table is recycled and the cache is cleared.

[0074] The present invention provides a method for solving the problem that the efficiency of the same hash algorithm is different in different environments, thereby affecting the program running efficiency. The dynamic hash is a hash algorithm based on the idea of ​​self-optimization programming. Specifically, when the user-side environment changes, the user's historical data is automatically collected and, under appropriate conditions, the historical data is analyzed to generate a new hash algorithm to replace the original hash algorithm, thereby dynamically updating the hash algorithm based on the historical data without manual intervention, and can more accurately match the user-side data to improve the program running efficiency.

[0075] The embodiment of the present invention also provides a dynamic hash device, such as Figure 6 As shown, this may include:

[0076] The acquisition module 11 is used to: acquire historical data of historical accesses to the original hash table to be updated, and determine the frequency of historical accesses to corresponding records in the original hash table based on the historical data;

[0077] A generating module 12 is used to: generate a corresponding hash function based on the frequency corresponding records higher than the frequency threshold, so as to minimize the possibility of hash collision when accessing the records with frequency higher than the frequency threshold based on the generated hash function;

[0078] The creation module 13 is used to: create a hash table corresponding to the generated hash function, and insert each record contained in the original hash table into the generated hash table according to the generated hash function;

[0079] The replacement module 14 is used to replace the original hash table with the generated hash table, and replace the hash function corresponding to the original hash table with the generated hash function.

[0080] An embodiment of the present invention provides a dynamic hash device, wherein the creation module may include:

[0081] An insertion unit is used to: if there are multiple records with the same hash value obtained based on the generated hash function, determine that the multiple records corresponding to the same hash value belong to the same bucket in the generated hash table, and insert the multiple records corresponding to the same hash value into the corresponding bucket of the hash table according to the principle that the higher the frequency, the earlier the position in the corresponding bucket.

[0082] A dynamic hashing device provided by an embodiment of the present invention may further include:

[0083] A query module is used to: in the process of inserting all records contained in the original hash table into the generated hash table, if an information request sent by a user is received, query the generated hash table for the record corresponding to the information request; if the search is successful, return the found record to the user; otherwise, query the original hash table for the record corresponding to the information request.

[0084] A dynamic hashing device provided by an embodiment of the present invention may further include:

[0085] The recycling module is used to: after replacing the original hash table with the generated hash table, recycle the original hash table and clean up the cache corresponding to the original hash table.

[0086] A dynamic hashing device provided by an embodiment of the present invention may further include:

[0087] A monitoring module is used to: monitor the host CPU, memory, the status of the original hash table and the performance of the original hash table before obtaining the historical data of historical accesses to the original hash table to be updated; if it is monitored that the idle resources contained in the host CPU are less than the preset resources, and / or the storage space contained in the memory is less than the preset space, and / or the number of records contained in the original hash table is greater than the record threshold, and / or the query efficiency of the original hash table is lower than the efficiency threshold, then execute the step of obtaining the historical data of historical accesses to the original hash table to be updated.

[0088] A dynamic hashing device provided by an embodiment of the present invention may further include:

[0089] The storage module is used to: regularly collect historical data of the original hash table to be updated within a preset time period before the current moment, and store the collected historical data in a memory or a file for retrieval.

[0090] The collected historical data is recorded in memory or files, and can also include:

[0091] The output module is used to: before recycling the original hash table, output an option of whether to recycle the original hash table, if receiving a recycling instruction based on the option input from the outside, execute the step of recycling the original hash table, otherwise, transfer the original hash table to a specified location for storage.

[0092] The embodiment of the present invention further provides a dynamic hash device, which may include:

[0093] Memory for storing computer programs;

[0094] A processor is used to implement the steps of any of the above dynamic hash methods when executing a computer program.

[0095] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above dynamic hash methods can be implemented.

[0096] It should be noted that the description of the relevant parts of a dynamic hash device, equipment and storage medium provided by the embodiment of the present invention can be found in the detailed description of the corresponding parts of a dynamic hash method provided by the embodiment of the present invention, which will not be repeated here. In addition, the parts of the above technical solutions provided by the embodiment of the present invention that are consistent with the implementation principles of the corresponding technical solutions in the prior art are not described in detail to avoid excessive elaboration.

[0097] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A dynamic hashing method, characterized in that: include: Obtain historical data of historical accesses to the original hash table to be updated, and determine the frequency of historical accesses to corresponding records in the original hash table based on the historical data; Generate a corresponding hash function based on the frequency corresponding records above the frequency threshold, so as to minimize the probability of hash collision when accessing the records with the frequency above the frequency threshold based on the generated hash function; Creating a hash table corresponding to the generated hash function, and inserting each record contained in the original hash table into the generated hash table according to the generated hash function; Replacing the original hash table with the generated hash table, and replacing the hash function corresponding to the original hash table with the generated hash function; According to the generated hash function, each record contained in the original hash table is inserted into the generated hash table, including: If there are multiple records with the same hash value obtained based on the generated hash function, it is determined that the multiple records corresponding to the same hash value belong to the same bucket in the generated hash table, and the multiple records corresponding to the same hash value are inserted into the corresponding bucket of the hash table according to the principle that the higher the frequency, the earlier the position in the corresponding bucket; Before obtaining the historical data of the original hash table to be updated, it also includes: Monitor the status of the host CPU, memory, original hash table and the performance of the original hash table. If it is monitored that the idle resources contained in the host CPU are less than the preset resources, and / or the storage space contained in the memory is less than the preset space, and / or the number of records contained in the original hash table is greater than the record threshold, and / or the query efficiency of the original hash table is lower than the efficiency threshold, then execute the step of obtaining historical data of historical accesses to the original hash table to be updated; wherein, the performance of the original hash table is the query efficiency within a specified period of time, and the query efficiency is the quotient of the total number of accesses to the records in the hash table within the specified period of time and the average time used for each access to the records in the hash table.

2. The method according to claim 1, characterized in that: Also includes: In the process of inserting all the records contained in the original hash table into the generated hash table, if an information request sent by a user is received, the record corresponding to the information request is queried in the generated hash table. If the search is successful, the found record is returned to the user. Otherwise, the record corresponding to the information request is queried in the original hash table.

3. The method according to claim 2, characterized in that After replacing the original hash table with the generated hash table, the method further includes: The original hash table is recycled, and the cache corresponding to the original hash table is cleared.

4. The method according to claim 1 or 3, characterized in that: Also includes: The historical data of the original hash table to be updated that was accessed within a preset time period before the current moment is collected periodically, and the collected historical data is stored in the memory or file for retrieval.

5. The method according to claim 4, characterized in that Before recycling the original hash table, the method further includes: Output an option of whether to recycle the original hash table. If a recycle instruction based on the option is received from the outside, execute the step of reclaiming the original hash table. Otherwise, transfer the original hash table to a specified location for storage.

6. A dynamic hashing device, characterized in that: include: An acquisition module, used to: acquire historical data of historical accesses to the original hash table to be updated, and determine the frequency of historical accesses to corresponding records in the original hash table based on the historical data; A generation module, configured to: generate a corresponding hash function based on the frequency corresponding records above the frequency threshold, so as to minimize the possibility of hash collision when accessing the records with the frequency above the frequency threshold based on the generated hash function; A creation module, used to: create a hash table corresponding to the generated hash function, and insert each record contained in the original hash table into the generated hash table according to the generated hash function; A replacement module, used to: replace the original hash table with the generated hash table, and replace the hash function corresponding to the original hash table with the generated hash function; The creation module specifically includes: If there are multiple records with the same hash value obtained based on the generated hash function, it is determined that the multiple records corresponding to the same hash value belong to the same bucket in the generated hash table, and the multiple records corresponding to the same hash value are inserted into the corresponding bucket of the hash table according to the principle that the higher the frequency, the earlier the position in the corresponding bucket; The dynamic hash device specifically includes: Monitor the status of the host CPU, memory, original hash table and the performance of the original hash table. If it is monitored that the idle resources contained in the host CPU are less than the preset resources, and / or the storage space contained in the memory is less than the preset space, and / or the number of records contained in the original hash table is greater than the record threshold, and / or the query efficiency of the original hash table is lower than the efficiency threshold, then execute the step of obtaining historical data of historical accesses to the original hash table to be updated; wherein, the performance of the original hash table is the query efficiency within a specified period of time, and the query efficiency is the quotient of the total number of accesses to the records in the hash table within the specified period of time and the average time used for each access to the records in the hash table.

7. A dynamic hash device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the dynamic hash method as claimed in any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the dynamic hash method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Progressive re-hashing method and device, computer equipment and storage medium

    CN109828966A