Hash Table Processing Method and Device
By calculating memory space information and applying for continuous memory when the hash table is created, the memory fragmentation and high computing resource consumption problems during hash table migration are solved, and more efficient hash table processing and maintenance are achieved.
Patent Information
- Application Number
- CN202210641049.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-08
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2042-06-08
AI Technical Summary
When migrating a hash table from one process to another, the prior art requires traversing each key and value for serialization encoding and deserialization, resulting in memory fragmentation problems and high computing resource consumption.
By obtaining the capacity information in the hash table creation request, computing the memory space information, and applying continuous memory as a hash table data block in memory to avoid memory fragmentation. At the same time, when an operation request is received, the hash table is directly updated to improve processing efficiency.
It effectively reduces maintenance costs and improves the processing efficiency of hash tables, especially during the serialization and deserialization process, reducing additional computing resource consumption.
Smart Images

Figure CN114860736B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and particularly to a method and device for processing hash tables. Background Art
[0002] With the development of Internet technology, as a data structure for storing keys and values, hash tables have a large number of applications in program programming. Its characteristic is to exchange space for time. By calculating the hash value of the key through a hash function, it quickly locates the position in the table to obtain the value. Hash tables are provided in various language standard libraries, but they mainly consider the query efficiency in the local environment. When a user wants to migrate a hash table from one process to another, they can only traverse each key and value of the hash table for serialization encoding, and then transmit it to another process through the network, and traverse again for deserialization. However, due to the influence of the operating environment, the application and release of memory will cause memory fragmentation problems, resulting in the need for additional computing resources for maintenance. At the same time, the time consumption of serialization and deserialization is also relatively large. Therefore, an effective solution is urgently needed to solve the above problems. Summary of the Invention
[0003] In view of this, embodiments of the present application provide a method for processing hash tables to solve the technical defects existing in the prior art. Embodiments of the present application also provide a device for processing hash tables, a computing device, and a computer-readable storage medium.
[0004] According to the first aspect of the embodiments of the present application, a method for processing hash tables is provided, including:
[0005] Obtain a hash table creation request, where the hash table creation request carries hash table capacity information;
[0006] Calculate memory space information according to the hash table capacity information and the storage data type associated with the hash table creation request;
[0007] In response to the hash table creation request, apply for continuous memory in the memory as a hash table data block according to the memory space information;
[0008] When an operation request submitted for the hash table associated with the hash table data block is received, update the hash table according to the operation request.
[0009] According to the second aspect of the embodiments of the present application, a device for processing hash tables is provided, including:
[0010] An obtaining module, configured to obtain a hash table creation request, where the hash table creation request carries hash table capacity information;
[0011] A calculation module, configured to calculate memory space information according to the hash table capacity information and the storage data type associated with the hash table creation request;
[0012] An application module, configured to, in response to the hash table creation request, apply for continuous memory in the memory as a hash table data block according to the memory space information;
[0013] An update module, configured to, when an operation request for the hash table associated with the hash table data block is received, update the hash table according to the operation request.
[0014] According to a third aspect of the embodiments of the present application, a computing device is provided, including:
[0015] A memory and a processor;
[0016] The memory is used to store computer-executable instructions, and when the processor executes the computer-executable instructions, the steps of the hash table processing method are implemented.
[0017] According to a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, which stores computer-executable instructions, and when the instructions are executed by a processor, the steps of the hash table processing method are implemented.
[0018] According to a fifth aspect of the embodiments of the present application, a chip is provided, which stores a computer program, and when the computer program is executed by the chip, the steps of the hash table processing method are implemented.
[0019] The present application provides a hash table processing method. When a hash table creation request carrying hash table capacity information is obtained, in order to avoid the maintenance difficulty problem caused by memory fragmentation, the consumed memory space information can be calculated according to the hash table capacity information and the storage data type associated with the hash table creation request. Then, in response to the hash table creation request, continuous memory is applied for in the memory as a hash table data block, so as to realize that continuous memory space can be applied for and used for the hash table creation request, which can effectively reduce the maintenance cost; at the same time, during the deserialization and serialization processes, since continuous memory does not require additional information to mark the memory location, the processing efficiency can be effectively improved; it is realized that after an operation request associated with the hash table is received, the hash table can be directly updated according to the hash table creation request, so as to improve the processing efficiency of addition / deletion / query. Description of the Drawings
[0020] Figure 1 is a flowchart of a first hash table processing method provided by an embodiment of the present application;
[0021] Figure 2It is a flowchart of a second hash table processing method provided by an embodiment of the present application;
[0022] Figure 3 It is a flowchart of a third hash table processing method provided by an embodiment of the present application;
[0023] Figure 4 It is a schematic structural diagram of a hash table processing device provided by an embodiment of the present application;
[0024] Figure 5 It is a structural block diagram of a computing device provided by an embodiment of the present application. Detailed implementation manners
[0025] In the following description, many specific details are set forth in order to provide a thorough understanding of the present application. However, the present application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar generalizations without departing from the connotation of the present application. Therefore, the present application is not limited by the specific implementations disclosed below.
[0026] The terms used in one or more embodiments of the present application are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of the present application. The singular forms "a", "said", and "the" used in one or more embodiments of the present application and the appended claims are also intended to include the plural forms unless the context clearly dictates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more of the associated listed items.
[0027] It should be understood that although the terms first, second, etc. may be used in one or more embodiments of the present application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first.
[0028] First, the noun terms involved in one or more embodiments of the present invention are explained.
[0029] Hash table: It is a data structure that directly accesses data according to the key value. That is to say, it accesses records by mapping the key value to a position in the table to speed up the search.
[0030] In the present application, a hash table processing method is provided. The present application also relates to a hash table processing device, a computing device, and a computer-readable storage medium, which will be described in detail one by one in the following embodiments.
[0031] Figure 1 The flowchart of the first hash table processing method provided according to an embodiment of the present application is shown, which specifically includes the following steps:
[0032] Step S102: Obtain a hash table creation request, where the hash table capacity information is carried in the hash table creation request.
[0033] The hash table processing method provided in this embodiment is implemented using the C++ language, and the key and value of the hash table belong to POD type data, that is, data with a fixed memory occupancy length. On this basis, by applying for continuous memory to create a hash table data block corresponding to the hash table creation request, the efficiency in the usage stage of the hash table can be effectively improved.
[0034] Based on this, the hash table creation request specifically refers to the request for the hash table to be created in the current application environment, and the key and value of the hash table belong to POD type data; correspondingly, the hash table capacity information specifically refers to the capacity size information required when creating the hash table. The specific setting of the hash table capacity information can be selected according to the actual application scenario, and this embodiment does not make any limitations here.
[0035] Further, in the case of receiving a hash table creation request, to support subsequent creation of a hash table data block through continuous memory and to maintain the usage of the hash table in the current application scenario, a hash table class can be implemented using a structure. The data composition structure of the structure can include a hash table data block, a data block capacity, the number of used slots in the hash table, and an index of free slots, so as to support improving the efficiency of addition / deletion / query during the application stage in combination with the above composition structure.
[0036] Among them, the hash table data block refers to a data block containing multiple slots in the hash table. Each key-value pair occupies one slot. Since the key and value belong to POD type data, the length of the key-value pair is fixed. Correspondingly, the size of the hash table data block is also fixed. At the same time, the problem of hash collision can be solved during the application stage. In addition to the key and value, the data in each slot can also include information indicating whether the current slot is free, information indicating whether the hash value conflicts, and an index of the next slot pointing to the conflict for the current slot, so as to complete the processing operation according to the above information when inserting data, deleting data, and querying data into the hash table.
[0037] Correspondingly, the data block capacity is used to record the upper limit of the slots in the hash table; the number of used slots in the hash table is used to represent the number of key-value pairs that have been inserted into the hash table; the index of free slots is used to represent the index of the current free slot, so as to quickly allocate a slot for newly inserted data when inserting data.
[0038] Step S104: Calculate the memory space information based on the hash table capacity information and the storage data type associated with the hash table creation request.
[0039] Specifically, based on the received hash table creation request above, further considering that the data types to be stored are different in different scenarios, the size of the hash table is also different. Since the hash table is a table structure existing in memory, before creating the hash table data block associated with the hash table, the storage data type associated with the hash table creation request can be determined first, that is, the data type to be processed in the current application scenario. Then, the size of the memory space to be consumed is calculated in combination with the hash table capacity information to obtain the memory space information, which can be used to apply for the local memory required in the current application scenario in memory according to this information for subsequent use.
[0040] Among them, the storage data type associated with the hash table creation request specifically refers to the data types of the hash table key and value, and the occupied memory length is fixed; for example, POD type data occupies a fixed-length memory; correspondingly, the memory space information specifically refers to the information about the size of the occupied memory space.
[0041] Based on this, the number of slots included in the hash table to be created can be determined according to the hash table capacity information. Since this hash table is used to store POD type data and occupies a fixed-length memory, the memory space information corresponding to the hash table creation request can be obtained by calculating the product of the hash table capacity information and the memory occupied by the storage data type, which is convenient for subsequent application of memory according to the memory space information to achieve the purpose of making full use of memory resources and avoiding resource waste.
[0042] Step S106: In response to the hash table creation request, apply for continuous memory in memory as the hash table data block according to the memory space information.
[0043] Specifically, based on the above calculation of the memory space information according to the hash table capacity information and the storage data type, further at this time, the memory for satisfying the hash table creation request can be applied for in memory according to the memory space information as the hash table data block. In order to improve the usage efficiency in the application stage, continuous memory and memory of the same size as the memory space information can be applied for in memory as the hash table data block, so as to achieve the creation and use of the hash table without additional maintenance of memory positions. And in the application stage, due to the continuity of memory, the serialization and deserialization processing of the hash table can be realized according to the offset, effectively improving the processing efficiency.
[0044] Furthermore, since continuous memory is applied for the hash table data block, there is no need for additional computing resources to maintain the memory address. Only by recording the offset can the storage location of the data in the hash table be determined, thus effectively reducing the consumption of computing resources. Further, after the hash table is serialized, if the hash table needs to be used continuously, the hash table also needs to be deserialized. This process takes into account that serialization is the process of converting the state information of the hash table into a storable or transmissible form, that is, converting the hash table into a byte sequence; while deserialization is the reverse process of serialization, that is, converting the byte sequence in the storable or transmissible form into a hash table. Therefore, by applying continuous memory, the serialization and deserialization processes do not require additional computing resources to maintain the data address in the memory. Only by calculating the offset can the data be read from the memory for serialization or deserialization processing, effectively improving the processing efficiency.
[0045] Among them, serialization and deserialization processing according to the offset means that during the process of reading data for serialization and deserialization processing, the offset of the next piece of data can be calculated based on the space occupied by the previous piece of data in the memory, that is, the offset position of the next piece of data relative to the storage position of the previous piece of data, so that the next piece of data can be directly read for processing according to the offset. In practical applications, to further save the consumption of computing resources, the offset of each piece of data can be recorded in the hash table. When performing serialization and deserialization processing, the corresponding offset can be directly determined by reading the hash table to improve the processing efficiency.
[0046] On this basis, after the hash table data block is created, it is actually the creation of the hash table required for the current application scenario. In order to facilitate the dynamic monitoring of the actual situation of the hash table because different information corresponding to the hash table will change with the usage status of the hash table, the hash table can be initialized first and then used, so that different information can be recorded through different parameters. In this embodiment, the specific implementation method is as follows:
[0047] Delete the redundant data in the continuous memory and initialize the hash table information corresponding to the hash table; where the hash table information includes hash table free slot index information and hash table used slot quantity information. In addition, the hash value range corresponding to the hash table can be determined according to the hash table capacity information; determine the data slots included in the hash table, and create index information corresponding to the data slots according to the hash value range.
[0048] Specifically, the redundant data specifically refers to all the data stored before creating the continuous memory of the hash table creation request using the applied memory, that is, all the data stored using this part of the memory. This part of the data needs to be deleted to release the continuous memory for subsequent use in creating hash table data blocks. Deleting the redundant data means clearing all the data stored in the continuous memory so that the processed continuous memory is in a zero-utilization state for subsequent applications. Correspondingly, the hash table information specifically refers to the information required during the application stage of the hash table, which is used to record the parameters that need to be recorded when the hash table is in use, including but not limited to the hash table free slot index information and the hash table used slot quantity information. Among them, the hash table empty slot index information specifically refers to the index information corresponding to the slots in the hash table that have not been used yet. Correspondingly, the hash table used slot quantity information specifically refers to the quantity information of the slots in the hash table that have been used. Based on this information, the quantity information of the slots in the hash table that have not been used can be determined.
[0049] Correspondingly, the hash value range specifically refers to the interval composed of the maximum and minimum values of the hash values obtained after hashing the key corresponding to the data. For example, if the storage capacity is 100, the calculated hash values will converge to the interval [0, 100), which is used to clarify the amount of data that the hash table can store. Correspondingly, the index information specifically refers to the information of the data slots where each hash value is mapped to each slot, which is used to clarify the slots that need to be processed during the add / delete / lookup operation processing.
[0050] Based on this, after creating the hash table data block, in order to support the hash table associated with the hash table data block to be used during the application stage, after applying for continuous memory, the redundant data in the continuous memory can be deleted to release the memory space for the hash table to use. And at the same time, in order to be able to record the information related to the hash table through different parameters, the hash table free slot index information and the hash table used slot quantity information associated with the hash table can also be initialized. At the same time, the hash value range corresponding to the hash table will be determined according to the hash table capacity information. After determining the data slots included in the hash table, the mapping relationship between each hash value and the slot can be established based on the hash value range as the index information for convenient use during the application stage.
[0051] That is to say, during the initialization stage of the hash table, after applying for continuous memory as the hash table data block, the redundant data in the memory will be cleared, that is, set to the default value 0. At this time, since continuous memory is applied to implement the function of the hash table, it can be ensured that all data is in the continuous memory, and the relationship between the data is saved as relative offsets, that is, it does not depend on the runtime memory address.
[0052] Further, in the initialization phase, the index information of the free slots in the hash table is also set to 0 to indicate that all slots in the hash table are empty at the current moment, and the information on the number of used slots in the hash table is set to 0 to indicate that there is no data in the hash table. The capacity of the data block is recorded as the number of initialized slots, that is, the number of slots determined according to the hash table capacity information in the hash table creation phase. At the same time, considering that the hash function is used to calculate the hash value for the key, and the hash value is the basis for adding / deleting / searching in the hash table, it is necessary to converge the hash value within the slot capacity range. For example, if the capacity is N, the range of the hash value is [0, N), which is used to index the slots through the hash value for convenient use in the application phase.
[0053] In summary, after creating the hash table by applying for continuous memory, the relevant information associated with the hash table can be initialized to provide a running environment convenient for the application of the hash table, and at the same time, the parameters to be used are initialized. In the application phase, the relevant information of the hash table can be recorded based on these parameters, so as to clarify the application status of the hash table at any time through this part of information.
[0054] Step S108, when an operation request submitted for the hash table associated with the hash table data block is received, update the hash table according to the operation request.
[0055] Specifically, after the hash table data block is created as described above, it is possible to store the data of the hash table using the hash table data block, and perform operations such as deleting or querying the data in the hash table. On this basis, if an operation request submitted for the hash table associated with the hash table data block is received, it means that at this time, an operation of inserting data, deleting data, or querying data needs to be performed on the basis of the hash table. Therefore, the hash table can be updated in response to the operation request to give a feedback in response to the operation request.
[0056] Further, when the operation request is a data insertion request, it means that new data needs to be inserted into the hash table at this time. In order to successfully insert the data into the hash table and avoid the influence of hash conflicts, the slot for inserting the data can be determined by calculating the hash value and matching. In this embodiment, the specific implementation is as follows:
[0057] When the operation request is a data insertion request, determine the first data index information and the first data carried in the data insertion request; calculate the first hash value corresponding to the first data index information through the hash function; determine the first slot associated with the first hash value in the hash table, and write the first data into the first slot as an update to the hash table.
[0058] Specifically, the data insertion request specifically refers to a request to insert new data into the hash table; correspondingly, the first data index information specifically refers to the key in the key-value pair data to be inserted, the first data specifically refers to the value in the key-value pair data to be inserted, and correspondingly, the first hash value specifically refers to the hash value obtained by performing a hash calculation on the first data index information; correspondingly, the first slot specifically refers to the slot in the hash table that is associated with the first hash value and can perform an insertion process on the first data.
[0059] Based on this, when a data insertion request related to the hash table is received, it indicates that new data needs to be inserted into the hash table at this time. Then, the data index information and its associated first data can be determined according to the data insertion request. After that, the first hash value corresponding to the first data index information is calculated through a hash function. Then, the first slot associated with the first hash value is queried in the hash table, and the first data is written into the first slot to complete the response to the data insertion request.
[0060] In summary, by selecting the first slot associated with the first hash value to perform an insertion process on the first data, it is possible to dynamically increase data in the hash table, and the slot where the data is inserted is a slot in the hash table that has not been used, effectively improving the insertion efficiency.
[0061] On this basis, considering the existence of hash conflicts in the hash table, it may occur that the slot where the first data needs to be inserted cannot be used. To quickly resolve hash conflicts and the data insertion process, the storage state can be detected before insertion. In this embodiment, the specific implementation method is as follows:
[0062] Determine the second slot corresponding to the first hash value in the hash table, and detect the storage state of the second slot; when the storage state of the second slot is the idle state, use the second slot as the first slot; when the storage state of the second slot is the occupied state, determine the first idle slot in the hash table, and determine the first slot according to the first idle slot.
[0063] Specifically, the second slot specifically refers to the slot in the hash table that is associated with the first hash value. When the storage state is idle, the second slot can be used as the first slot; when the storage state is the occupied state, another idle slot that forms a linked list with the second slot can be selected as the first slot; correspondingly, the idle state specifically refers to the state where the slot has not been used and no data is stored; correspondingly, the occupied state specifically refers to the state where the slot has been used and other data is stored; correspondingly, the first idle slot specifically refers to the slot in the hash table that has not been used, and this slot is the slot with the highest priority among the idle slots.
[0064] Based on this, after obtaining the first hash value corresponding to the first data index information, the second slot having a mapping relationship with the first hash value can be first determined in the hash table, and then the storage status of the second slot is detected. If the storage status is the idle state, it indicates that the second slot can write data at this time, then the second slot is used as the first slot, and the first data is written into this slot. If the storage status is the occupied state, it indicates that there is a hash conflict in the hash table at this time, and the second slot has been occupied by other data due to the hash conflict. In order to ensure that the first data can be successfully inserted into the hash table, the first idle slot with the highest priority can be determined in the hash table, and the first slot for storing the first data is determined according to the first idle slot, and then the data writing process operation can be performed.
[0065] In summary, to avoid the influence brought by the hash conflict, the status detection of the slot is performed before determining the first slot, so as to determine the slot used as the first slot according to the status detection result, and to realize the writing process of the first data, thereby improving the data insertion efficiency.
[0066] Furthermore, in the process of determining the first slot according to the first idle slot, since it has been determined that there is a hash conflict in the hash table at this time, in order to solve the influence brought by the hash conflict, the first slot needs to be determined by comparing the hash values. In this embodiment, the specific implementation method is as follows:
[0067] Determine the second hash value corresponding to the second data index information of the data stored in the second slot, and compare the second hash value with the first hash value; in the case where the second hash value is the same as the first hash value, form a first linked list according to the second slot and the first idle slot, and use the idle slots in the first linked list as the first slot; in the case where the second hash value is different from the first hash value, write the placeholder data stored in the second slot into the first idle slot, and use the second slot as the first slot according to the writing result.
[0068] Specifically, the second hash value specifically refers to the hash value obtained by performing a hash operation on the second data index information of the data stored in the second slot. Correspondingly, the first linked list specifically refers to a linked list composed of slots with the same hash value but different data, which is used to index data with the same hash value and facilitate traversal in the query and deletion phases.
[0069] Based on this, when it is determined that there is a hash collision in the hash table, it indicates that the second slot is already occupied at this time. In order to successfully write the newly inserted first data into the hash table, the second data index information corresponding to the data stored in the second slot can be determined first, and the second hash value obtained through calculation; the second hash value is compared with the first hash value; if the two are the same, it means that the data stored in the second slot has the same hash value as the newly inserted first data, but the data content is different, further indicating that there is a hash collision between the two. In order to solve the hash collision, a linked list can be formed according to the second slot and the already selected first free slot, which is used to link the second slot and the first free slot. That is to say, the slots with the same hash value can be linked together through the first linked list, so that when deleting or querying data, the linked list can be determined according to the hash value, and then the data associated with the original key to be queried or deleted can be selected from the linked list for deletion or query. That is to say, after determining the first linked list, the free slot in the first linked list can be used as the first slot, and then the write processing operation of the first data can be carried out.
[0070] If the two are inconsistent, it means that the data stored in the second slot has a different hash value from the newly inserted first data, which further indicates that the second slot may be occupied due to hash collisions in other slots. However, the current second slot should be used for the newly written data. Therefore, the placeholder data stored in the second slot can be written into the already confirmed first free slot, and then the vacated second slot can be used as the first slot, and then the write processing operation of the first data can be carried out.
[0071] Based on this, in order to solve the hash collision, free slots can be found first. The determination of free slots can be achieved through free slot index information. Then, the hash value of the key of the conflict slot (the second slot) in the hash table is calculated. After that, this hash value can be compared with the hash value of the inserted data. If they are the same, the free slot and the conflict slot in the hash table can be directly connected to form a linked list, and then new data can be filled through the linked list. If they are inconsistent, it means that this slot is occupied by a previous conflict. At this time, the free slot needs to be used to replace this slot to ensure accurate hit during the next query. After the replacement is completed, the input insertion process can be carried out.
[0072] In summary, by adopting the method of comparing hash values to determine the first slot, the data can be successfully written into the hash table through the first slot, avoiding the influence caused by hash collisions, and at the same time improving the data insertion efficiency.
[0073] In addition, considering that when inserting data, the hash table may reach its storage limit; or due to hash collisions, the data that is constantly being displaced has no available slots, so after the hash table reaches its storage limit, the storage space can be increased by means of expansion processing. In this embodiment, the specific implementation method is as follows:
[0074] When the hash table meets the expansion condition, apply for target continuous memory in the memory according to a set multiple; migrate the hash table in the continuous memory to the target continuous memory, and update the hash table in the target continuous memory.
[0075] Specifically, the expansion condition specifically refers to the condition for judging whether the hash table needs to be expanded. Correspondingly, the set multiple specifically refers to the multiple set according to actual requirements, which is used to select the multiple according to the size of the original continuous memory when applying for the target continuous memory, so as to apply for the target continuous memory. Correspondingly, updating the hash table in the target continuous memory means updating the relevant information of the hash table, including but not limited to the index information of the hash table, the number of slots in the hash table, the number of unused slots in the hash table, etc.
[0076] Based on this, when it is determined that the hash table meets the expansion condition, a continuous memory can be applied for in the memory according to the set multiple at this time as the target continuous memory, and then the hash table in the continuous memory is migrated to the target continuous memory, and the hash table in the target continuous memory is updated.
[0077] For example, when a request to insert data into the hash table is received, first determine the key1 and value1 carried by the request according to the request, and then calculate the hash value corresponding to key1 as Hash_1 through the hash function. And obtain the slot index corresponding to the hash value Hash_1 by querying the hash table, and determine that the slot corresponding to the hash value Hash_1 is SP_1 according to the index; at this time, it will be detected whether the storage state of the slot SP_1 is an idle state or a storage state; when the storage state of the slot SP_1 is an idle state, it means that the slot SP_1 is not used, and the key-value pair (key1 value1) carried by the request can be directly written into the slot SP_1.
[0078] When the storage state of slot SP_1 is the storage state, it indicates that slot SP_1 has been used, further indicating that there is a hash conflict problem in the hash table. To solve the hash conflict, an idle slot SP_N can be determined in the hash table; at the same time, the hash value Hash_2 corresponding to slot SP_1 is determined, and then the hash value Hash_2 is compared with the hash value Hash_1. If the two are the same, it means that the newly inserted key-value pair has the same hash value as the key-value pair already stored in slot SP_1, and there is a hash conflict relationship between them. To enable the newly inserted key-value pair to be inserted into the hash table, slot SP_N and slot SP_1 can be linked to form a linked list. Then, the key-value pair (key1 value1) can be written into slot SP_N in the linked list, so that in the query stage, if the hash value is Hash_1, the keys corresponding to slot SP_N and slot SP_1 can be determined in the linked list, and then the value that meets the query requirements can be selected for feedback.
[0079] If the two are inconsistent, it means that the newly inserted key-value pair has a different hash value from the key-value pair already stored in slot SP_1, further indicating that the key-value pair stored in slot SP_1 is a key-value pair stored due to other hash conflicts. Therefore, at this time, the key-value pair in slot SP_1 can be moved to slot SP_N, and after slot SP_1 is idle, the key-value pair (key1value1) can be written into slot SP_1. In addition, after the key-value pair in the original slot SP_1 is moved to slot SP_N, the index also needs to be updated. For example, the original slot SP_1 and slot SP_N1 form a linked list, and their hash values are the same; but when the key-value pair in the original slot SP_1 is moved to slot SP_N, a linked list needs to be formed based on slot SP_N1 and slot SP_N to enable data query at any stage and avoid the feedback result not meeting the user's needs.
[0080] In addition, considering that the hash table will be used up over time, in order to be able to meet the storage scenarios of more data, the hash table can be expanded. When it is determined that the hash table meets the expansion conditions, twice the original memory can be applied for, and new continuous memory is applied for in the memory. Then, the original hash table is traversed, and the data in the hash table is inserted into the hash table with twice the continuous memory one by one. At the same time, the information of the new hash table needs to be updated to meet the subsequent usage requirements.
[0081] Furthermore, when the hash table is migrated due to application requirements, in order to avoid the impact caused by the migration, the hash table also needs to be serialized and deserialized. In this embodiment, the specific implementation method is as follows:
[0082] In the case of receiving a migration request submitted for the hash table, serialize the hash table in the source process to obtain a hash table to be migrated; in response to the migration request, deserialize the hash table to be migrated in the target process to obtain the hash table.
[0083] Specifically, the migration request specifically refers to a request to migrate a hash table from one process to another according to actual needs; correspondingly, the source process specifically refers to the process where the hash table originally exists; the target process specifically refers to the process to which the hash table needs to be migrated.
[0084] Based on this, in the case of receiving a migration request submitted for the hash table, at this time, the hash table in the source process can be serialized to obtain a hash table to be migrated; then, in response to the migration request, the hash table to be migrated is deserialized in the target process, and the hash table in the target process can be obtained.
[0085] In specific implementation, since the present application uses continuous memory to create hash table data blocks, the data stored in the slots are all indexes, and these indexes are all offsets relative to the starting position of the memory. Therefore, in the serialization stage, the data can be directly copied, and then the hash table data block, data block capacity, number of used slots in the hash table, and free slot indexes of the hash table are saved to the target process.
[0086] In the deserialization stage, it is the reverse operation of the serialization process. At the same time, when deserializing, a continuous memory of the same size needs to be applied for, a memory copy is performed, and then the hash table data block, data block capacity, number of used slots in the hash table, and free slot indexes of the hash table are assigned.
[0087] The present application provides a hash table processing method. When a hash table creation request carrying hash table capacity information is obtained, in order to avoid the maintenance difficulty problem caused by memory fragmentation, the memory space information consumed can be calculated according to the hash table capacity information and the storage data type associated with the hash table creation request. Then, in response to the hash table creation request, continuous memory is applied for in the memory as the hash table data block, so as to realize that continuous memory space can be applied for and used for the hash table creation request, which can effectively reduce the maintenance cost; at the same time, in the deserialization and serialization processes, because continuous memory does not require additional information to mark the memory position, the processing efficiency can be effectively improved; it is realized that after receiving an operation request related to the hash table, the hash table can be directly updated according to the hash table creation request to improve the processing efficiency of addition / deletion / query.
[0088] Corresponding to the hash table processing method provided in the above embodiment, the present embodiment also provides a second hash table processing method. Figure 2The flowchart of the second hash table processing method provided according to an embodiment of the present application is shown, which specifically includes the following steps:
[0089] Step S202, obtain a hash table creation request, where the hash table capacity information is carried in the hash table creation request;
[0090] Step S204, calculate the memory space information according to the hash table capacity information and the storage data type associated with the hash table creation request;
[0091] Step S206, in response to the hash table creation request, apply for continuous memory in the memory as the hash table data block according to the memory space information;
[0092] The second hash table processing method provided in this embodiment is similar to the first hash table processing method provided in the above embodiment. For the same or corresponding description content, reference can be made to the above embodiment, and this embodiment will not be elaborated here too much.
[0093] Step S208, in the case of receiving a data query request submitted to the hash table associated with the hash table data block, determine the third data index information carried in the data query request, and calculate the third hash value corresponding to the third data index information through a hash function.
[0094] Step S210, according to the slot information corresponding to the hash table, determine whether there is a second linked list associated with the third hash value in the hash table; if it exists, execute step S212; if it does not exist, execute step S214.
[0095] Step S212, if it exists, traverse the second linked list according to the third data index information to obtain the first target data in response to the data query request as the update to the hash table.
[0096] Step S214, if it does not exist, determine the third slot in the hash table according to the third hash value, and read the second target data stored in the third slot as the update to the hash table.
[0097] Specifically, the data query request specifically refers to a request for querying data in the hash table. Correspondingly, the third data index information specifically refers to the key carried in the query request. Correspondingly, the third hash value specifically refers to the hash value obtained after performing a hash operation on the third data index information; correspondingly, the slot information specifically refers to the information recording the relationship between the hash value and the slot index in the hash table; correspondingly, the second linked list specifically refers to a linked list in the hash table composed of slots with the same hash value but different stored data due to hash conflicts; correspondingly, the first target data and the second target data specifically refer to the query result data for the data query request.
[0098] Based on this, when a data query request is received, the data query request can be parsed first to determine the third data index information carried in the data query request; then it is operated on by a hash function to obtain the third hash value corresponding to the third data index information. Considering that there may be hash collisions in the hash table, it is possible to determine whether there is a second linked list associated with the third hash value in the hash table according to the slot information corresponding to the hash table.
[0099] If it exists, it means that there are at least two slots in the hash table whose hash values are both the third hash value, and the at least two slots form a second linked list, and the data to be queried is also in this linked list. Therefore, the second linked list can be traversed according to the third data index information to determine the index information that matches the third data index information in the second linked list, and select the corresponding first target data as the response to the data query request.
[0100] If it does not exist, it means that there is no linked list associated with the third hash value in the hash table, that is, there is no hash collision associated with the third hash value. Therefore, the third slot corresponding to the third data index information can be directly determined in the hash table, and the second target data stored in the third slot can be read as the response to the data query request.
[0101] For example, when a data query request is received, the data query request can be parsed to obtain key2, and then the hash function is used to calculate key2, and the obtained hash value corresponding to key2 is Hash_3. Then the slot corresponding to the hash value Hash_3 is determined in the hash table, and then key matching is performed. Considering the existence of hash collisions, it is possible to first understand whether there are hash collisions through the slot information. If there are, then at this time, the linked list associated with the hash value Hash_3 can be determined first. It is determined that the linked list is composed of slots SP_4 -> SP_6 -> SP_8 (the hash value of each slot is Hash_3). Then at this time, key2 can be used to traverse the slots SP_4 -> SP_6 -> SP_8, and according to the traversal result, it is determined that the key-value pair stored in slot SP_6 is (key2, value2). Therefore, value2 stored in slot SP_6 can be selected as the feedback of the data query request. If it does not exist, it means that the queried key2 does not exist in the hash table, and then a null value can be fed back for the data query request.
[0102] In summary, in the data query stage, by using the method of hash operation to determine the linked list and adopting different methods to query the target data according to the problem of hash collisions, it is possible to accurately hit the data to be queried at this stage and give feedback, effectively improving the accuracy and efficiency of data query.
[0103] Corresponding to the hash table processing method provided in the above embodiment, this embodiment also provides a third hash table processing method. Figure 3 The flowchart of the third hash table processing method provided in an embodiment of the present application is shown, which specifically includes the following steps:
[0104] Step S302: Obtain a hash table creation request, where the hash table creation request carries hash table capacity information.
[0105] Step S304: Calculate memory space information according to the hash table capacity information and the storage data type associated with the hash table creation request.
[0106] Step S306: In response to the hash table creation request, apply for continuous memory in the memory as a hash table data block according to the memory space information.
[0107] The third hash table processing method provided in this embodiment is similar to the first hash table processing method provided in the above embodiment. For the same or corresponding description content, reference can be made to the above embodiment, and this embodiment will not be elaborated too much here.
[0108] Step S308: In the case of receiving a data deletion request submitted to the hash table associated with the hash table data block, determine the fourth data index information carried in the data deletion request, and calculate the fourth hash value corresponding to the fourth data index information through a hash function.
[0109] Step S310: According to the slot information corresponding to the hash table, determine whether there is a third linked list associated with the fourth hash value in the hash table; if so, execute step S312; if not, execute step S314.
[0110] Step S312: If so, traverse the third linked list according to the fourth data index information to obtain the fourth slot corresponding to the data deletion request, update the third linked list, and delete the third target data stored in the fourth slot according to the update result as an update to the hash table.
[0111] Step S314: If not, determine the fifth slot in the hash table according to the fourth hash value, and delete the fourth target data stored in the fifth slot as an update to the hash table.
[0112] Specifically, the data deletion request specifically refers to a request to delete specified data in the hash table; correspondingly, the fourth data index information specifically refers to the key carried in the data deletion request; correspondingly, the fourth hash value specifically refers to the hash value obtained by performing a hash operation on the fourth data index information; correspondingly, the slot information specifically refers to the information in the hash table that records the relationship between the hash value and the slot index; correspondingly, the third linked list specifically refers to the linked list in the hash table composed of multiple slots with the same hash value but different stored data due to hash conflicts; correspondingly, the third target data and the fourth target data specifically refer to the data to be deleted for the data deletion request.
[0113] Based on this, when receiving a data deletion request submitted for the hash table associated with the hash table data block, the data deletion request can be parsed first to obtain the fourth data index information, and then it can be operated on through a hash function to obtain the fourth hash value corresponding to the fourth data index information. Considering that there may be hash conflicts in the hash table, the slot information corresponding to the hash table can be used to determine whether there is a third linked list associated with the fourth data index information in the hash table.
[0114] If it exists, it means that there are at least two slots in the hash table with the same fourth hash value, and the at least two slots form the third linked list, and the data to be deleted is also in this linked list. Therefore, the third linked list can be traversed according to the fourth data index information to determine the index information that matches the fourth data index information in the third linked list, and select the corresponding third target data as the response to the data deletion request.
[0115] If it does not exist, it means that there is no linked list associated with the fourth hash value in the hash table, that is, there is no hash conflict associated with the fourth hash value. Therefore, the fifth slot corresponding to the fourth data index information can be directly determined in the hash table, and the fourth target data stored in the fifth slot can be deleted as the response to the data deletion request.
[0116] For example, when receiving a data deletion request, the data deletion request can be parsed to obtain key3, and then the hash function is used to calculate key3 to obtain the hash value corresponding to key3 as Hash_4. According to the hash value Hash_4, its corresponding slot in the hash table is determined to be SP_7. Then, the key7 in the slot SP_7 can be taken to match with key3. If the two are the same, it means that the slot SP_7 is the slot to be deleted, and then it can be deleted. If key7 and key3 are not the same, further detection is required, that is, it is necessary to determine whether there is a hash conflict in the hash table.
[0117] Specifically, first, take out the key7 of slot SP_7, perform a hash operation on key7 using a hash function to obtain a hash value of Hash_7. Then, compare the hash value Hash_7 with the hash value Hash_4. If the two are inconsistent, it means that slot SP_7 is an occupied slot, and at the same time, it is further determined that the key3 that the data deletion request needs to delete does not exist in the hash table, then no processing is required. If the two are consistent, it means that there is a hash conflict in the hash table. At this time, it is necessary to traverse the linked list corresponding to the hash value Hash_4. If it is determined that the linked list is composed of slots SP_7 -> SP_9 -> SP_10 (the hash value of each slot is Hash_4), then at this time, it is possible to traverse slots SP_7 -> SP_9 -> SP_10 according to key3, and according to the traversal result, it is determined that the key-value pair stored in slot SP_10 is (key3, value3). Therefore, it is possible to select the value3 stored in slot SP_10 for deletion processing. If there is no hash conflict, it means that key3 does not exist in the hash table and no deletion processing is required.
[0118] In addition, if it is determined according to the traversal result that the key-value pair stored in slot SP_7 is (key3, value3), after selecting the value3 stored in slot SP_7 for deletion processing, at this time, the linked list will store an empty slot. In order to support subsequent deletion, query and other processing operations, and considering that slot SP_7 is the starting traversed slot and the starting position of the traversed slot cannot be changed, the data stored in slots SP_9 and SP_10 can be moved, that is, move the key-value pair stored in slot SP_9 to slot SP_7, and move the key-value pair stored in SP_10 to slot SP_9, so that the updated linked list consists of slots SP_7 -> SP_9, which is convenient for subsequent use.
[0119] In summary, in the data deletion stage, by using the method of hash operation to determine the linked list and adopting different methods to process data deletion according to the problem of hash conflict, it is possible to accurately hit the data that needs to be deleted and process it in this stage, effectively improving the accuracy and efficiency of data deletion.
[0120] Corresponding to the above method embodiment, the present application also provides an embodiment of a hash table processing device. Figure 4 The structural schematic diagram of a hash table processing device provided by an embodiment of the present application is shown. As Figure 4 shown, the device includes:
[0121] An obtaining module 402, configured to obtain a hash table creation request, where the hash table creation request carries hash table capacity information;
[0122] A calculation module 404, configured to calculate memory space information according to the hash table capacity information and the storage data type associated with the hash table creation request;
[0123] An application module 406, configured to, in response to the hash table creation request, apply for continuous memory in the memory as a hash table data block according to the memory space information;
[0124] An update module 408, configured to, when an operation request for the hash table associated with the hash table data block is received, update the hash table according to the operation request.
[0125] In an optional embodiment, the apparatus further includes:
[0126] An initialization module, configured to delete redundant data in the continuous memory and initialize hash table information corresponding to the hash table; wherein the hash table information includes hash table free slot index information and hash table used slot quantity information.
[0127] In an optional embodiment, the apparatus further includes:
[0128] A creation information module, configured to determine a hash value range corresponding to the hash table according to the hash table capacity information; determine data slot positions included in the hash table, and create index information corresponding to the data slot positions according to the hash value range.
[0129] In an optional embodiment, the update module 408 is further configured to:
[0130] When the operation request is a data insertion request, determine first data index information and first data carried in the data insertion request; calculate a first hash value corresponding to the first data index information through a hash function; determine a first slot position associated with the first hash value in the hash table, and write the first data into the first slot position as an update to the hash table.
[0131] In an optional embodiment, the update module 408 is further configured to:
[0132] Determine a second slot position corresponding to the first hash value in the hash table, and detect the storage state of the second slot position; when the storage state of the second slot position is an idle state, use the second slot position as the first slot position; when the storage state of the second slot position is an occupied state, determine a first free slot position in the hash table, and determine the first slot position according to the first free slot position.
[0133] In an optional embodiment, the update module 408 is further configured to:
[0134] Determine the second hash value corresponding to the second data index information associated with the second slot, and compare the second hash value with the first hash value; in the case where the second hash value is the same as the first hash value, form a first linked list according to the second slot and the first free slot, and use the free slots in the first linked list as the first slot; in the case where the second hash value is different from the first hash value, write the placeholder data stored in the second slot into the first free slot, and use the second slot as the first slot according to the write result.
[0135] In an optional embodiment, the update module 408 is further configured to:
[0136] In the case where the operation request is a data query request, determine the third data index information carried by the data query request, and calculate the third hash value corresponding to the third data index information through a hash function; according to the slot information corresponding to the hash table, determine whether there is a second linked list associated with the third hash value in the hash table; if so, traverse the second linked list according to the third data index information to obtain the first target data in response to the data query request as an update to the hash table; if not, determine a third slot in the hash table according to the third hash value, and read the second target data stored in the third slot as an update to the hash table.
[0137] In an optional embodiment, the update module 408 is further configured to:
[0138] In the case where the operation request is a data deletion request, determine the fourth data index information carried by the data deletion request, and calculate the fourth hash value corresponding to the fourth data index information through a hash function; according to the slot information corresponding to the hash table, determine whether there is a third linked list associated with the fourth hash value in the hash table; if so, traverse the third linked list according to the fourth data index information to obtain the fourth slot corresponding to the data deletion request, update the third linked list, and delete the third target data stored in the fourth slot according to the update result as an update to the hash table; if not, determine a fifth slot in the hash table according to the fourth hash value, and delete the fourth target data stored in the fifth slot as an update to the hash table.
[0139] In an optional embodiment, the apparatus further includes:
[0140] A migration module, configured to apply for target continuous memory in the memory according to a set multiple when the hash table meets the expansion condition; migrate the hash table in the continuous memory to the target continuous memory, and update the hash table in the target continuous memory.
[0141] In an optional embodiment, the apparatus further includes:
[0142] A serialization processing module, configured to perform serialization processing on the hash table in the source process to obtain a hash table to be migrated when receiving a migration request submitted for the hash table; and perform deserialization processing on the hash table to be migrated in the target process in response to the migration request to obtain the hash table.
[0143] This application provides a hash table processing apparatus. When a hash table creation request carrying hash table capacity information is obtained, in order to avoid the maintenance difficulty problem caused by memory fragmentation, the memory space information consumed can be calculated according to the hash table capacity information and the storage data type associated with the hash table creation request. Then, in response to the hash table creation request, continuous memory is applied for in the memory as a hash table data block, so as to realize that continuous memory space can be applied for and used for the hash table creation request, which can effectively reduce the maintenance cost; at the same time, during the deserialization and serialization processes, since continuous memory does not require additional information to mark the memory location, the processing efficiency can be effectively improved; it is realized that after receiving an operation request related to the hash table, the hash table can be directly updated according to the hash table creation request to improve the processing efficiency of addition / deletion / query.
[0144] The above is a schematic solution of a hash table processing apparatus in this embodiment. It should be noted that the technical solution of the hash table processing apparatus and the technical solution of the above hash table processing method belong to the same concept. For the details not described in detail in the technical solution of the hash table processing apparatus, reference can be made to the description of the technical solution of the above hash table processing method. In addition, each component in the apparatus embodiment should be understood as a functional module that must be established to implement each step of the program flow or each step of the method. Each functional module is not an actual functional division or separation limitation. The apparatus claim defined by such a set of functional modules should be understood as mainly implementing the functional module architecture of the solution through the computer program recorded in the specification, rather than mainly implementing the entity device of the solution through hardware means.
[0145] Figure 5FIG. 0 shows a structural block diagram of a computing device 500 provided according to an embodiment of the present application. The components of the computing device 500 include, but are not limited to, a memory 510 and a processor 520. The processor 520 is connected to the memory 510 via a bus 530, and a database 550 is used to store data.
[0146] The computing device 500 further includes an access device 540, which enables the computing device 500 to communicate via one or more networks 560. Examples of these networks include the Public Switched Telephone Network (PSTN), Local Area Network (LAN), Wide Area Network (WAN), Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of wired or wireless network interfaces (e.g., Network Interface Card (NIC)), such as an IEEE802.11 Wireless Local Area Network (WLAN) wireless interface, Worldwide Interoperability for Microwave Access (Wi-MAX) interface, Ethernet interface, Universal Serial Bus (USB) interface, cellular network interface, Bluetooth interface, Near Field Communication (NFC) interface, and so on.
[0147] In an embodiment of the present application, the above components of the computing device 500 and Figure 5 other components not shown in FIG. may also be connected to each other, for example, via a bus. It should be understood that Figure 5 the shown structural block diagram of the computing device is for illustrative purposes only and is not a limitation on the scope of the present application. Those skilled in the art can add or replace other components as needed.
[0148] The computing device 500 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smart phones), wearable computing devices (e.g., smart watches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs. The computing device 500 can also be a mobile or stationary server.
[0149] Among them, the processor 520 is used to execute computer-executable instructions of the hash table processing method.
[0150] The above is a schematic solution of a computing device in this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the above hash table processing method belong to the same concept. For the details not described in the technical solution of the computing device, reference can be made to the description of the technical solution of the above hash table processing method.
[0151] An embodiment of the present application further provides a computer-readable storage medium storing computer instructions, which are executed by a processor for a hash table processing method.
[0152] The above is a schematic solution of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium and the technical solution of the above hash table processing method belong to the same concept. For the details not described in detail in the technical solution of the storage medium, reference can be made to the description of the technical solution of the above hash table processing method.
[0153] The computer instructions include computer program code, which may be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content included in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0154] An embodiment of the present application further provides a chip storing a computer program, which implements the steps of the hash table processing method when executed by the chip.
[0155] It should be noted that for the foregoing method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present application is not limited by the described action sequence, because according to the present application, certain steps may be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present application.
[0156] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0157] The preferred embodiments of the present application disclosed above are only used to help illustrate the present application. The alternative embodiments do not describe all the details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and variations can be made according to the content of the present application. These embodiments are selected and specifically described in order to better explain the principles and practical applications of the present application, so that those skilled in the art can well understand and utilize the present application. The present application is only limited by the claims and their full scope and equivalents.
Claims
1. A hash table processing method, characterized in that, Including: Obtain a hash table creation request, where the hash table capacity information is carried in the hash table creation request; Calculate the memory space information according to the hash table capacity information and the storage data type associated with the hash table creation request; In response to the hash table creation request, apply for continuous memory in the memory as the hash table data block according to the memory space information; When an operation request for the hash table associated with the hash table data block is received, update the hash table according to the operation request; Among them, when an operation request for the hash table associated with the hash table data block is received, updating the hash table according to the operation request includes: determining the data index information carried in the operation request, and calculating the hash value corresponding to the data index information through a hash function; determining a slot in the hash table according to the hash value, and updating the hash table based on the data in the slot.
2. The method according to claim 1, wherein After the step of applying for continuous memory in the memory as the hash table data block in response to the hash table creation request according to the memory space information, it further includes: Delete redundant data in the continuous memory, and initialize the hash table information corresponding to the hash table; where the hash table information includes hash table free slot index information and hash table used slot quantity information.
3. The method according to claim 1, characterized in that, After the step of applying for continuous memory in the memory as the hash table data block in response to the hash table creation request according to the memory space information, it further includes: Determine the hash value range corresponding to the hash table according to the hash table capacity information; Determine the data slots included in the hash table, and create index information corresponding to the data slots according to the hash value range.
4. The method according to claim 1, wherein The updating the hash table according to the operation request includes: When the operation request is a data insertion request, determine the first data index information and the first data carried in the data insertion request; Calculate the first hash value corresponding to the first data index information through a hash function; Determine the first slot associated with the first hash value in the hash table, and write the first data into the first slot as an update to the hash table.
5. The method according to claim 4, wherein The determining the first slot associated with the first hash value in the hash table includes: Determine the second slot corresponding to the first hash value in the hash table, and detect the storage status of the second slot; When the storage status of the second slot is the idle state, use the second slot as the first slot; When the storage status of the second slot is the occupied state, determine the first free slot in the hash table, and determine the first slot according to the first free slot.
6. The method according to claim 5, characterized in that, The determining the first slot according to the first free slot includes: Determine the second hash value corresponding to the second data index information associated with the second slot, and compare the second hash value with the first hash value; When the second hash value is the same as the first hash value, form a first linked list according to the second slot and the first free slot, and use the free slot in the first linked list as the first slot; When the second hash value is different from the first hash value, write the placeholder data stored in the second slot into the first free slot, and use the second slot as the first slot according to the writing result.
7. The method according to claim 1, characterized in that The updating the hash table according to the operation request includes: When the operation request is a data query request, determine the third data index information carried by the data query request, and calculate the third hash value corresponding to the third data index information through a hash function; According to the slot information corresponding to the hash table, determine whether there is a second linked list associated with the third hash value in the hash table; If it exists, traverse the second linked list according to the third data index information to obtain the first target data in response to the data query request as the update to the hash table; If it does not exist, determine a third slot in the hash table according to the third hash value, and read the second target data stored in the third slot as the update to the hash table.
8. The method according to claim 1, wherein The updating the hash table according to the operation request includes: When the operation request is a data deletion request, determine the fourth data index information carried by the data deletion request, and calculate the fourth hash value corresponding to the fourth data index information through a hash function; According to the slot information corresponding to the hash table, determine whether there is a third linked list associated with the fourth hash value in the hash table; If it exists, traverse the third linked list according to the fourth data index information to obtain the fourth slot corresponding to the data deletion request, update the third linked list, and delete the third target data stored in the fourth slot according to the update result as the update to the hash table; If it does not exist, determine a fifth slot in the hash table according to the fourth hash value, and delete the fourth target data stored in the fifth slot as the update to the hash table.
9. The method according to claim 6, wherein After the step of updating the hash table according to the operation request is executed, it further includes: When the hash table meets the expansion condition, apply for target continuous memory in the memory according to a set multiple; Migrate the hash table in the continuous memory to the target continuous memory, and update the hash table in the target continuous memory.
10. The method according to any one of claims 1-9, characterized in that, After the step of updating the hash table according to the operation request is executed, it further includes: When a migration request for the hash table is received, serialize the hash table in the source process to obtain a hash table to be migrated; In response to the migration request, deserialize the hash table to be migrated in the target process to obtain the hash table.
11. A hash table processing device, characterized in that, It includes: An acquisition module configured to acquire a hash table creation request, where the hash table creation request carries hash table capacity information; A calculation module, configured to calculate memory space information according to the hash table capacity information and the storage data type associated with the hash table creation request; An application module, configured to, in response to the hash table creation request, apply for continuous memory in the memory as a hash table data block according to the memory space information; An update module, configured to, when an operation request submitted for the hash table associated with the hash table data block is received, update the hash table according to the operation request; wherein, when an operation request submitted for the hash table associated with the hash table data block is received, updating the hash table according to the operation request includes: determining data index information carried in the operation request, and calculating a hash value corresponding to the data index information through a hash function; determining a slot in the hash table according to the hash value, and updating the hash table based on the data in the slot.
12. A computing device, characterized in that, Comprising: A memory and a processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the steps of the method according to any one of claims 1 to 10.
13. A computer-readable storage medium storing computer instructions, characterized in that, When the instruction is executed by the processor, the steps of the method according to any one of claims 1 to 10 are implemented.
14. A computer program product, characterized in that, Including computer instructions, when the computer instructions are executed by the processor, the steps of the method according to any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
Ten million-level network session table management method, system, medium and equipment based on Hash algorithm
CN109634966A
Hash table creating method and system, computing device and storage medium
CN109885576A