Hashmap data processing method, device and system and related equipment

By introducing a cache module in HashMap, data with a high probability of being retrieved and fast searching is solved, the problem of low data retrieval efficiency in the prior art is solved, and more efficient data retrieval is achieved.

CN119201350APending Publication Date: 2024-12-27HYGON INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411354878.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The search efficiency of existing HashMap data needs to be improved, especially for data with a high probability of being retrieved, which is difficult for the existing technology to quickly locate and retrieve.

Method used

By introducing a cache module, data with a high probability of being retrieved is stored, and it is quickly searched in the cache module before retrieval. If it does not exist in the cache module, it is searched in the main module, thereby improving the data retrieval efficiency.

Benefits of technology

It improves the retrieval efficiency of data with a high probability of being retrieved in HashMap, and overall improves the data retrieval performance of HashMap.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201350A_ABST
    Figure CN119201350A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a Hashmap data processing method, device and system and related equipment, the method is applied to the Hashmap data processing device comprising a main body module and a cache module, and the cache module is used for storing to-be-retrieved data which is stored in the main body module and meets a preset condition; the retrieved probability of the to-be-retrieved data meeting the preset condition is larger than the retrieved probability of other to-be-retrieved data, and the to-be-retrieved data in the cache module is retrieved based on the key data; the method comprises the following steps: judging whether to-be-retrieved key data meets a preset condition or not; and if the key data to be retrieved exists, retrieving in a cache module to determine whether to-be-retrieved data corresponding to the key data to be retrieved exists, if so, acquiring the to-be-retrieved data corresponding to the key data to be retrieved, and if not, performing retrieval on the main body module based on the key data to be retrieved. According to the scheme, the data retrieval efficiency is improved on the whole.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of virtual machine technology, and specifically to a Hashmap data processing method, device, system and related equipment. Background Art

[0002] HashMap (also called hash table or hash map) is a core class in the Java collection framework. It uses an array structure to store key-value pairs (entries) and is an implementation of the Map interface based on a hash table. Since HashMap can provide fast data retrieval capabilities and flexible data organization, it has gradually become the preferred solution for processing key-value data structures.

[0003] However, the data retrieval efficiency of the existing HashMap needs to be further improved. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a Hashmap data processing method, apparatus, system and related equipment to improve the data retrieval efficiency of the HashMap.

[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0006] An embodiment of the present invention provides a Hashmap data processing method, which is applied to a Hashmap data processing device. The Hashmap data processing device includes a main module and a cache module. The main module is used to store data to be retrieved, and the cache module is used to store data to be retrieved that meets preset conditions and is stored in the main module; wherein the probability of retrieval of the data to be retrieved that meets the preset conditions is greater than the probability of retrieval of other data to be retrieved, and the data to be retrieved in the cache module is retrieved based on key data; the method includes:

[0007] Determine whether the key data to be retrieved meets the preset conditions;

[0008] If so, the cache module searches to determine whether there is data to be retrieved corresponding to the key data to be retrieved. If so, the data to be retrieved corresponding to the key data to be retrieved is obtained. If not, a search is performed on the main module based on the key data to be retrieved.

[0009] Optionally, the determining whether the key data to be retrieved meets a preset condition includes:

[0010] Based on the type of the key data to be retrieved, determine whether the key data to be retrieved is of a preset type. If not, it does not meet the preset conditions. If so, determine whether the key data to be retrieved is within a preset threshold range. If not, it does not meet the preset conditions. If so, it meets the preset conditions.

[0011] Optionally, performing the retrieval of the main module based on the key data to be retrieved includes:

[0012] Calculate the hash value corresponding to the key data to be searched, and use the hash value as the search index value of the main module;

[0013] Based on the search index value, determine the position in the main module corresponding to the search index value, and use the position as the target position;

[0014] Determine whether the data in the target position is the data to be retrieved corresponding to the key data to be retrieved;

[0015] If yes, executing the step of obtaining the data to be retrieved corresponding to the key data to be retrieved, if no, determining whether the first node data in the target position is a tree node;

[0016] If it is a tree node, searching the tree structure of the target position to confirm whether there is data to be retrieved corresponding to the key data to be retrieved, and if there is data to be retrieved corresponding to the key data to be retrieved, executing the step of obtaining the data to be retrieved corresponding to the key data to be retrieved;

[0017] If it is not a tree node, retrieve the linked list structure of the target position to confirm whether there is data to be retrieved corresponding to the key data to be retrieved, and if there is data to be retrieved corresponding to the key data to be retrieved, execute the step of obtaining the data to be retrieved corresponding to the key data to be retrieved.

[0018] Optionally, before the step of determining whether the key data to be retrieved meets a preset condition, the following steps are performed:

[0019] Determine whether the cache module is empty and has a length of 0;

[0020] If not, execute the step of determining whether the key data to be retrieved meets the preset conditions; if so, determine whether the main module is empty and has a length of 0. If so, end the retrieval process; if not, execute the step of searching the main module based on the key data to be retrieved.

[0021] Optionally, also include:

[0022] Determine whether the data to be stored meets the preset conditions;

[0023] If so, the data to be stored is stored in the cache module, and the stored data to be stored is used as the data to be retrieved; if not, the data to be stored is stored in the main module, and the stored data to be stored is used as the data to be retrieved.

[0024] Optionally, the data to be stored is a key-value pair, and storing the data to be stored in the cache module is specifically:

[0025] The key-value pairs are stored in an array of the cache module, wherein the key data is used as the subscript of the array, and the value data is used as the data stored in the corresponding position of the array in the cache module.

[0026] Optionally, before the step of storing the data to be stored in the cache module, the step further includes:

[0027] Determine whether the cache module is empty and its length is 0;

[0028] If not, execute the step of storing the data to be stored in the cache module; if so, determine whether the main module is empty and the length is 0, if so, execute the expansion logic, if not, execute the step of storing the data to be stored in the main module.

[0029] Optionally, after the step of storing the data to be stored in the main module, the method further includes:

[0030] Based on the main capacity threshold of the current main module, determine whether to execute the expansion logic;

[0031] If yes, execute the expansion logic; if no, end the storage process.

[0032] Optionally, the expansion logic includes expansion logic for a main module and expansion logic for a cache module; the method further includes:

[0033] Execute the expansion logic for the main module;

[0034] Execute the expansion logic for the cache module.

[0035] Optionally, the executing the expansion logic for the cache module includes:

[0036] Determine if the cache module is empty and has a length of 0;

[0037] An array structure is created for a cache module, and a cache capacity threshold is configured for the array structure of the cache module.

[0038] The embodiment of the present invention further provides a Hashmap data processing device, comprising a cache module, a main module and a retrieval control module, wherein:

[0039] The main body module is used to store the data to be retrieved, and the cache module is used to store the data to be retrieved that meets the preset conditions and is stored in the main body module; wherein the probability of the data to be retrieved that meets the preset conditions being retrieved is greater than the probability of other data to be retrieved being retrieved, and the data to be retrieved in the cache module is retrieved based on the key data;

[0040] The retrieval control module is used to determine whether the key data to be retrieved meets the preset conditions before executing the retrieval of the main module. If so, the cache module is searched to determine whether there is data to be retrieved corresponding to the key data to be retrieved. If so, the data to be retrieved corresponding to the key data to be retrieved is obtained. If not, the retrieval of the main module is executed based on the key data to be retrieved.

[0041] Optionally, the retrieval probability of the data to be retrieved is the historical retrieval probability of the data to be retrieved, or the predicted retrieval probability of the data to be retrieved, or a combination of the historical retrieval probability and the predicted retrieval probability.

[0042] Optionally, the preset condition is used to limit the key data to a preset type, and the preset type is one or more of integer data, floating point data, character data, and custom objects.

[0043] Optionally, the preset condition is used to limit the key data to be of a preset type, and the key data is within a preset threshold range.

[0044] Optionally, the data to be retrieved is a key-value pair, and the cache module stores the data to be retrieved in the form of an array, wherein the key data is used as the subscript of the array and the value data is used as the data stored in the corresponding position of the array in the cache module.

[0045] Optionally, it also includes: a storage control module, which is used to implement storage logic for data to be stored, wherein the data to be stored stored in the Hashmap data processing device is used as data to be retrieved.

[0046] Optionally, it also includes: a capacity expansion module, and the storage control module is used to execute capacity expansion logic.

[0047] An embodiment of the present invention also provides a Hashmap data processing system, which is used to execute the above-mentioned Hashmap data processing method.

[0048] An embodiment of the present invention further provides a computer program, comprising one or more computer executable instructions, which, when executed, implement the above-mentioned Hashmap data processing method.

[0049] The embodiment of the present invention also provides a storage medium, wherein the storage medium stores a program for implementing the above-mentioned Hashmap data processing method.

[0050] The embodiment of the present invention provides a Hashmap data processing method, device, system and related equipment, wherein the Hashmap data processing device includes a cache module, a main body module and a retrieval control module, wherein: the main body module is used to store data to be retrieved, and the cache module is used to store data to be retrieved that meets preset conditions and is stored in the main body module; wherein the probability of retrieval of the data to be retrieved that meets the preset conditions is greater than the probability of retrieval of other data to be retrieved, and the data to be retrieved in the cache module is retrieved based on key data; the method includes: determining whether the key data to be retrieved meets the preset conditions; if so, searching the cache module to determine whether there is data to be retrieved corresponding to the key data to be retrieved, if so, obtaining the data to be retrieved corresponding to the key data to be retrieved, and if not, performing a retrieval of the main body module based on the key data to be retrieved.

[0051] It can be seen that the present invention stores the data to be retrieved that meets the preset conditions (i.e., the probability of being retrieved is greater than the probability of being retrieved of other data to be retrieved) in a retrieval cache module based on key data, so that before executing the retrieval of the main module, a fast retrieval based on the key data to be retrieved is first performed in the cache module, and when the data to be retrieved does not exist in the cache module, the retrieval of the main module is performed, thereby improving the data retrieval efficiency of the data to be retrieved with a higher probability of being retrieved in the HashMap, thereby improving the data retrieval efficiency of the HashMap as a whole. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] 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.

[0053] Figure 1 A schematic diagram of an optional architecture of a HashMap data processing device provided in an embodiment of the present invention;

[0054] Figure 2 An optional flow chart of a HashMap data processing method provided by an embodiment of the present invention;

[0055] Figure 3 Another optional flow chart of a HashMap data processing method provided by an embodiment of the present invention;

[0056] Figure 4 Another optional flow chart of a HashMap data processing method provided by an embodiment of the present invention;

[0057] Figure 5 An optional flow chart of storage logic in a HashMap data processing method provided in an embodiment of the present invention;

[0058] Figure 6 Another optional flow chart of storage logic in a HashMap data processing method provided by an embodiment of the present invention;

[0059] Figure 7 An optional flow chart of step S233 provided for an embodiment of the present invention;

[0060] Figure 8 An optional flow chart of step S234 provided for an embodiment of the present invention;

[0061] Fig. 9 Another optional flow chart of storage logic in a HashMap data processing method provided in an embodiment of the present invention;

[0062] Fig.10 An optional flow chart of the expansion logic in a HashMap data processing method provided in an embodiment of the present invention;

[0063] Fig.11 An optional flow chart of step S310 provided in an embodiment of the present invention;

[0064] Fig.12 An optional flowchart of step S320 provided for an embodiment of the present invention. DETAILED DESCRIPTION

[0065] 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.

[0066] As described in the background technology, the data retrieval efficiency of the existing HashMap needs to be further improved.

[0067] After studying the data retrieval process of HashMap, the inventor found that in HashMap, some data have a higher probability of retrieval, while some data have a lower probability of retrieval. Based on this, the inventor further believes that special processing of data can be considered to perform retrieval of data with a higher probability through a faster method, thereby improving the data retrieval efficiency of HashMap.

[0068] In view of this, an embodiment of the present invention provides a Hashmap data processing method, device, system and related equipment, wherein the device includes a cache module, a main body module and a retrieval control module, wherein: the main body module is used to store the data to be retrieved, and the cache module is used to store the data to be retrieved that meets the preset conditions and is stored in the main body module; wherein the probability of the data to be retrieved that meets the preset conditions being retrieved is greater than the probability of other data to be retrieved being retrieved, and the data to be retrieved in the cache module is retrieved based on the key data; the method includes: determining whether the key data to be retrieved meets the preset conditions; if so, searching the cache module to determine whether there is data to be retrieved corresponding to the key data to be retrieved, if so, obtaining the data to be retrieved corresponding to the key data to be retrieved, and if not, performing a retrieval of the main body module based on the key data to be retrieved.

[0069] It can be seen that the present invention stores the data to be retrieved that meets the preset conditions (i.e., the probability of being retrieved is greater than the probability of being retrieved of other data to be retrieved) in a retrieval cache module based on key data, so that before executing the retrieval of the main module, a fast retrieval based on the key data to be retrieved is first performed in the cache module, and when the data to be retrieved does not exist in the cache module, the retrieval of the main module is performed, thereby improving the data retrieval efficiency of the data to be retrieved with a higher probability of being retrieved in the HashMap, thereby improving the data retrieval efficiency of the HashMap as a whole.

[0070] As an optional example, Figure 1 The schematic diagram of an optional architecture of a HashMap data processing device is shown. The HashMap data processing device includes a cache module 10, a main module 20 and a retrieval control module 30.

[0071] The main module 20 is used to store the data to be retrieved. Specifically, the main module 20 is used to store data based on the HashMap data architecture, that is, to store data based on an array, a linked list, and a red-black tree.

[0072] The data to be retrieved is a key-value pair (also called an entry enty) stored in the HashMap data processing device for retrieval, and the key-value pair may include key data (key) and value data (value) corresponding to the key data, wherein the key data (key) is used to uniquely identify each entry (enty), and the value data is data associated with the key data.

[0073] It can be understood that HashMap is an implementation of the Map interface based on a hash table, in which the array structure used to store key-value pairs can be called a table. The table may include multiple buckets. The storage location of the bucket corresponds to the hash code of the key data, so that the bucket corresponding to the key-value pair can be determined based on the hash code of the key data. When multiple key data correspond to the same or similar hash codes (i.e., hash conflicts), a linked list or a red-black tree can be constructed based on the storage location of the bucket to store key-value pairs with the same or similar hash codes, wherein the bucket can be the root node of a linked list or a red-black tree.

[0074] The cache module 10 is used to store the data to be retrieved that meets the preset conditions and is stored in the main module, wherein the probability of retrieval of the data to be retrieved that meets the preset conditions is greater than the probability of retrieval of other data to be retrieved, and the data to be retrieved in the cache module is retrieved based on the key data.

[0075] Among them, the retrieval probability of the data to be retrieved can be understood as the historical retrieval probability of the data to be retrieved, or it can be the predicted retrieval probability of the data to be retrieved. It can be understood that in some examples, the retrieval probability of the data to be retrieved can be used as the predicted retrieval probability based on experience prediction, and the specific preset condition can be determined based on the predicted retrieval probability. Or, in a further example, the preset condition can also be determined based on the combination of the historical retrieval probability and the predicted retrieval probability. For example, in a specific example, the historical retrieval probability of a certain type of data to be retrieved is relatively large. At the same time, based on the trend, it is predicted that the predicted retrieval probability of the data to be retrieved of this type is relatively large, so that the preset condition can be determined as the data to be retrieved of this type.

[0076] In a specific example, the preset condition may be a limitation on the type corresponding to the key data, such as limiting the key data to a certain type or types of data (i.e., preset types), for example, the preset types may be one or more types of integer data, floating point data, character data, custom objects, etc. In a preferred example, the preset condition limits the key data to a type of data, so that data can be quickly retrieved based on the same type of data, thereby avoiding the possibility of unified data consumption for different types of data.

[0077] In a further example, the preset condition can limit the key data to be of a preset type and further limit the key data to be within a preset threshold range. The preset threshold range can be determined based on the probability of the data to be retrieved being retrieved. Specifically, the probability of the data to be retrieved being retrieved within the preset threshold range can be greater than the probability of the data to be retrieved being retrieved outside the preset threshold range. In other examples, the preset condition can also be directly determined based on the probability of the data to be retrieved being retrieved, that is, without distinguishing between data types, but only based on the probability of the data to be retrieved being retrieved.

[0078] The data to be retrieved in the cache module 10 is retrieved based on the key data, so that it is possible to retrieve and determine whether there is corresponding value data without performing a hash conversion of the key data.

[0079] In a specific example, the cache module 10 can store the data to be retrieved in the form of an array. For example, the key-value pairs are stored in the array of the cache module, with the key data as the subscript of the array and the value data as the data stored in the corresponding position of the array in the cache module.

[0080] Accordingly, the retrieval control module 30 is used to execute the corresponding retrieval logic, specifically, refer to Figure 2 An optional flow chart of a HashMap data processing method is shown, wherein the retrieval control module may perform the following data retrieval process before performing the retrieval of the main module:

[0081] Step S100: determining whether the key data to be retrieved meets the preset conditions;

[0082] The key data to be retrieved is the key data for retrieval provided in the retrieval request. By performing a corresponding judgment on whether the preset conditions are met based on the key data to be retrieved, it is determined whether the data to be retrieved may be stored in the cache module, and then whether to search in the cache module. It can be understood that the cache module stores the data to be retrieved that meets the preset conditions, so it can be determined whether to perform a cache module search based on whether the key data to be retrieved meets the preset conditions.

[0083] When the preset condition is a limitation on the type corresponding to the key data, a preset type can be pre-configured as the type limited by the preset condition. The preset type can be, for example, one or more types of integer data, floating-point data, character data, custom objects, etc. Similarly, this step can determine whether the key data to be retrieved is of the preset type based on the type of the key data to be retrieved. If so, it meets the preset condition and step S110 is executed. If not, it does not meet the preset condition and step S130 is executed.

[0084] In a further example, the preset condition may also limit the key data to be of a certain type and within a preset threshold range. Accordingly, a preset type may be pre-configured as the type limited by the preset condition, and at the same time, a corresponding preset threshold range may be configured. Accordingly, this step may first determine whether the key data to be retrieved is of a preset type based on the type of the key data to be retrieved. If so, a judgment of the preset threshold range is performed. If not, the preset condition is not met. The judgment of the preset threshold range may be, for example, as follows: determining whether the key data to be retrieved is within the preset threshold range. If so, the preset condition is met and step S110 is executed. If not, the preset condition is not met and step S130 is executed.

[0085] Step S110: searching in the cache module to determine whether there is data to be retrieved corresponding to the key data to be retrieved;

[0086] By performing a corresponding search in the cache module, it is first determined whether there is data to be retrieved corresponding to the key data to be retrieved in the cache module.

[0087] It is understandable that when the cache module stores the data to be retrieved based on an array, the subscripts of the data in the array can be compared based on the key data to determine whether corresponding value data exists.

[0088] If yes, execute step S120 to obtain the data to be retrieved, if no, execute step S130 to further search in the main module. It can be understood that even if the data to be retrieved is not retrieved in the cache module, it does not exclude the possibility that the data to be retrieved is still stored in the main module. Therefore, executing step S130 can further confirm the data retrieval.

[0089] Step S120: Acquire the data to be retrieved corresponding to the key data to be retrieved;

[0090] When there is data to be retrieved corresponding to the key data to be retrieved in the cache module, the data to be retrieved can be acquired, and the data to be retrieved can be fed back as retrieval result data.

[0091] Specifically, the data to be retrieved may include key data and corresponding value data. In an optional example, if the retrieval result data only requires the corresponding value data, the corresponding value data may be extracted as the retrieval result data after obtaining the data to be retrieved.

[0092] Step S130: performing a search on the main body module based on the key data to be searched;

[0093] The main module is searched to find the data to be searched that is not found in the cache module.

[0094] It is understandable that for the retrieval of the main module, it is necessary to perform a hash conversion of the key data to be retrieved to achieve the corresponding retrieval. Figure 3 Another optional flow chart of a HashMap data processing method is shown, step S130 may include the following steps:

[0095] Step S131: Calculate the hash value corresponding to the key data to be searched, and use the hash value as the search index value of the main module;

[0096] The search index value is an index used for search in the main module, so that the position of the data to be searched corresponding to the key data to be searched in the main module is determined based on the search index value.

[0097] Step S132: Based on the search index value, determine the position in the main module corresponding to the search index value, and use the position as the target position;

[0098] It is understandable that when the main module is an array, the data corresponding to a certain position in an array can be the data to be retrieved, or it can be the root node of a linked list or red-black tree constructed based on the storage position. Therefore, after determining the target position, it is necessary to further perform a specific search based on the key data to be retrieved in the subsequent steps.

[0099] Step S133: Determine whether the data in the target position is the data to be retrieved corresponding to the key data to be retrieved;

[0100] It is understandable that, based on the key data to be retrieved, the corresponding data to be retrieved can be confirmed. If the data at the target location is the data to be retrieved, step S120 is executed to obtain the data to be retrieved corresponding to the key data to be retrieved; if the data at the target location is not the data to be retrieved, step S134 needs to be further executed to judge the data structure of the target location to determine whether the data at the target location is a linked list or a red-black tree.

[0101] Step S134: Determine whether the first node data in the target position is a tree node;

[0102] It is understandable that when the target location does not store the data to be retrieved, it indicates that the target location stores a linked list structure or a tree structure with multiple node data. Accordingly, the data structure can be judged based on the first node data in the target location.

[0103] Among them, when the first node data is a tree node, it indicates that the data structure of the target position is a tree structure, and step S135 is executed to perform a corresponding search based on the tree structure; when the first node data is not a tree node, it indicates that the data structure of the target position is a linked list structure, and step S136 is executed to perform a corresponding search based on the linked list structure.

[0104] Step S135: searching the tree structure of the target location to confirm whether there is data to be retrieved corresponding to the key data to be retrieved;

[0105] Among them, when the first node data is a tree node, it is considered that the data at the target position is a tree structure, and accordingly, a corresponding search is performed on the tree structure to find the data to be retrieved corresponding to the key data to be retrieved, wherein, if the data to be retrieved corresponding to the key data to be retrieved exists in the tree structure, step S120 is executed to obtain the data to be retrieved corresponding to the key data to be retrieved, and the data to be retrieved is fed back as the search result data; if the data at the target position is not the data to be retrieved, it indicates that no relevant data has been retrieved, the search is ended, and a preset identifier is fed back as the search result data.

[0106] Step S136: searching the linked list structure of the target position to confirm whether there is data to be retrieved corresponding to the key data to be retrieved;

[0107] Among them, when the first node data is not a tree node, it is considered that the data at the target position is a linked list structure, and accordingly, a corresponding search is performed on the linked list structure to find the data to be retrieved corresponding to the key data to be retrieved, wherein, if the data to be retrieved corresponding to the key data to be retrieved exists in the linked list structure, step S120 is executed to obtain the data to be retrieved corresponding to the key data to be retrieved, and the data to be retrieved is fed back as the search result data; if the data at the target position is not the data to be retrieved, it indicates that no relevant data has been retrieved, the search is ended, and a preset identifier is fed back as the search result data.

[0108] It can be seen that the present invention stores the data to be retrieved that meets the preset conditions (i.e., the probability of being retrieved is greater than the probability of being retrieved of other data to be retrieved) in a retrieval cache module based on key data, so that before executing the retrieval of the main module, a fast retrieval based on the key data to be retrieved is first performed in the cache module, and when the data to be retrieved does not exist in the cache module, the retrieval of the main module is performed, thereby improving the data retrieval efficiency of the data to be retrieved with a higher probability of being retrieved in the HashMap, thereby improving the data retrieval efficiency of the HashMap as a whole.

[0109] In a further optional example, before executing step S100, it is also possible to further determine whether the cache module and the main module are empty, and perform corresponding process control based on the corresponding determination results. Figure 4 Another optional flow chart of a HashMap data processing method is shown, before executing step S100, the following process is executed:

[0110] Step S101: Determine whether the cache module is empty and the length is 0;

[0111] If yes, it indicates that there is no storage space in the cache module, and accordingly, there is no stored data, and then step S100 and step S110 can be skipped, and step S102 is executed to determine whether the main module is empty; if no, it indicates that there is storage space in the cache module and data may be stored, and step S100 and subsequent processes are executed based on the above process, wherein, when step S130 needs to be executed, before executing step S130 (refer to Figure 4 When step S130 includes step S131 to step S136, this step S130 is executed starting from step S131), and step S102 is also executed to determine whether the main module is empty to determine whether to execute step S130.

[0112] Step S102: Determine whether the main module is empty and has a length of 0;

[0113] If yes, it indicates that there is no storage space in the main module, and accordingly, there is no stored data, indicating that no relevant data has been retrieved, and step S130 can be skipped (refer to Figure 4 , when step S130 includes step S131 to step S136, this step S130 is executed starting from step S131), the search ends, and the preset identifier is fed back as the search result data; if not, it indicates that there is storage space in the main module and data may be stored, then step S130 and subsequent processes are executed based on the above process.

[0114] In a further optional example, the Hashmap data processing device in the embodiment of the present invention may further include a storage control module, which is used to implement the storage logic of the data to be stored, wherein the data to be stored stored in the Hashmap data processing device is used as the data to be retrieved. Specifically, the corresponding storage control logic can be executed after obtaining the storage instruction of the data to be stored, and the storage instruction can be, for example, a put instruction. Figure 5 An optional flow chart of storage logic in a HashMap data processing method is shown, wherein the storage control logic includes the following data storage process:

[0115] Step S210: Determine whether the data to be stored meets a preset condition;

[0116] Among them, based on the fact that the data to be stored is used as the data to be retrieved after being stored in the Hashmap data processing device, correspondingly, when the data to be retrieved is a key-value pair, the data to be stored is also a key-value pair.

[0117] The storage location of the data to be stored is determined by checking whether the data to be stored meets the preset conditions. Specifically, if yes, it is considered that the data to be stored can be stored in the cache module, and accordingly, step S220 can be executed to store the data to be stored in the cache module, and further step S230 can be executed to store the data to be stored in the main module, so that the data to be stored is stored in the cache module and the main module at the same time, and the stored data to be stored is used as the data to be retrieved; if no, it is considered that the data to be stored is not allowed to be stored in the cache module, and accordingly, step S230 is executed to store the data to be stored in the main module, and the stored data to be stored is used as the data to be retrieved.

[0118] Among them, when the preset condition is a limitation on the type corresponding to the key data, it can be determined whether the type corresponding to the key data in the data to be stored is the preset type. If so, the data to be stored meets the preset condition, and step S220 is executed. If not, the data to be stored does not meet the preset condition, and step S230 is executed.

[0119] Correspondingly, when the preset condition limits the key data to be of a preset type and also limits the key data to be within a preset threshold range, it can be determined whether the type corresponding to the key data in the data to be stored is the preset type. If so, further determination of the preset threshold range is performed; if not, the data to be stored does not meet the preset condition. The determination of the preset threshold range is specifically to determine whether the key data in the data to be stored is within the preset threshold range. If so, the preset condition is met and step S220 is executed; if not, the preset condition is not met and step S230 is executed.

[0120] Step S220: storing the data to be stored in the cache module, and using the stored data to be stored as data to be retrieved;

[0121] When the data to be stored is stored in the cache module in the form of an array, the data to be stored (i.e., key-value pairs) can be stored in the array of the cache module, wherein the key data is used as the subscript of the array and the value data is used as the data stored in the corresponding position of the array in the cache module.

[0122] Step S230: storing the data to be stored in the main module, and using the stored data to be stored as data to be retrieved;

[0123] By storing the data to be stored in the main module, and using the stored data to be stored as the data to be retrieved, a basis is provided for a subsequent retrieval process of the data to be retrieved.

[0124] refer to Figure 6 Another optional flow chart of storage logic in a HashMap data processing method is shown, and the process of storing data to the main module may include:

[0125] Step S231: Calculate the hash value corresponding to the key data to be stored, and use the hash value as the search index value of the main module;

[0126] The search index value is an index used for search in the main module, and can also identify the location of the data to be searched in the main module.

[0127] Step S232: Based on the search index value, determine the position in the main module corresponding to the search index value, and use the position as the position to be stored;

[0128] It is understandable that when the main module is an array, there may be data to be retrieved at a certain position of the array, or there may not be data to be retrieved. When there is data to be retrieved, it can be understood as a hash conflict. Correspondingly, the data to be retrieved at this position can be stored based on a linked list or a red-black tree, and at the same time, the storage position serves as the root node of the constructed linked list or red-black tree.

[0129] Step S233: Determine whether there is a hash conflict in the location to be stored;

[0130] It can be understood that when there is a hash conflict at the location to be stored, step S234 can be executed to store the corresponding data to be stored based on a linked list or a red-black tree. When there is no hash conflict at the location to be stored, step S235 can be executed to insert the data to be stored at the location to be stored.

[0131] Step S234: storing the corresponding data to be stored based on the linked list or the red-black tree.

[0132] Among them, the data structure of the location to be stored can be first confirmed to determine whether the data at the target location is a linked list or a red-black tree, and then the corresponding data storage process is executed based on the corresponding data structure.

[0133] Step S235: inserting the data to be stored into the location to be stored.

[0134] It can be seen that the present invention further provides storage logic for data to be stored, and stores data to be stored that meets preset conditions in the cache module as data to be retrieved, thereby providing a basis for fast retrieval of key data to be retrieved.

[0135] It should be noted that the reference Figure 7 In the optional flow chart of step S233 shown, the determination of whether there is a hash conflict in the storage location may include the following process:

[0136] Step S233a: Determine whether there is data to be retrieved in the storage location;

[0137] Among them, when there is no data to be retrieved, it indicates that there is no hash conflict, and step S324 can be executed to insert the data to be stored in the storage location. When there is data to be retrieved, step S233b needs to be further executed to confirm whether the data to be stored is an update of the data to be retrieved in the storage location.

[0138] Step S233b: Determine whether the key data of the data to be stored is consistent with the key data of the data to be retrieved at the location to be stored.

[0139] Among them, if they are consistent, it indicates that the data to be stored is an update of the data to be retrieved at the storage location, and step S235 is executed to insert the data to be stored in the storage location; if they are inconsistent, it indicates that there is a hash conflict, and step S234 is executed to store the corresponding data to be stored based on a linked list or a red-black tree.

[0140] It can be understood that when the data at the to-be-stored location corresponds to a linked list structure or a red-black tree structure, the data at the to-be-stored location is the root node of the linked list structure or the red-black tree structure. When executing the corresponding data storage process, refer to Figure 8 An optional flow chart of step S234 is shown, and step S234 may include the following process:

[0141] Step S234a: traverse the data to be retrieved of each node, and determine whether the key data of the data to be stored is consistent with the key data of the data to be retrieved stored in the corresponding node;

[0142] If so, it indicates that the data to be stored is an update of the data to be retrieved of the corresponding node, and step S234e is executed to update the data to be stored to a node consistent with the key data of the data to be stored. If not, step S234d is executed to insert the data to be stored.

[0143] It can be understood that, in the process of storing the data to be stored, the data structure of the location to be stored changes based on the change in the amount of data to be retrieved stored corresponding to the location, that is, when the amount of data to be retrieved currently stored is less than or equal to the linked list capacity threshold, the data to be stored is stored in a linked list structure, and when the amount of data to be retrieved is greater than the linked list capacity threshold, the data to be stored is stored in a red-black tree structure, wherein the linked list capacity threshold is used to indicate the maximum amount of data allowed to be stored under the linked list structure, and the linked list capacity threshold can be 8, for example. Accordingly, when the data corresponding to the location to be stored is a linked list structure, before step S234d of this example, the following may be further included:

[0144] Step S234b: determining whether the amount of the to-be-retrieved data in the linked list is greater than or equal to the linked list capacity threshold;

[0145] Among them, when the data amount of the data to be retrieved is equal to the linked list capacity threshold, it indicates that the data amount in the linked list structure has reached its capacity upper limit. Since new data to be stored needs to be stored subsequently (i.e., step S234c), the data structure needs to be converted into a red-black tree structure to carry out the data storage process of step 234d.

[0146] It can be understood that if the amount of data to be retrieved in the linked list is less than the linked list capacity threshold, step S234d is executed; if the amount of data to be retrieved in the linked list is greater than or equal to the linked list capacity threshold, step S234c is executed.

[0147] Step S234c: converting the linked list structure into a red-black tree structure.

[0148] More data to be retrieved can be stored based on the red-black tree structure. Therefore, after the red-black tree is transformed, step S234d can be executed to store the data to be retrieved.

[0149] Step S234d: insert the data to be stored.

[0150] When the structure corresponding to the position to be stored is a linked list structure, the data to be stored is inserted into the linked list; when the structure corresponding to the position to be stored is a red-black tree structure, the data to be stored is inserted into the red-black tree structure.

[0151] Step S234e: Update the data to be stored to a node that is consistent with the key data of the data to be stored.

[0152] The update process specifically covers overwriting the value data of the corresponding node position with the value data of the data to be stored. When updating the data at the storage position, the value data of the data to be stored overwrites the value data of the data to be retrieved at the storage position; when updating the data of the corresponding node of the linked list structure or the red-black tree structure corresponding to the storage position, the value data of the data to be stored overwrites the value data of the data to be retrieved at the corresponding node.

[0153] In a further optional example, it is also possible to determine whether the cache module and the main module are empty, and perform corresponding process control based on the corresponding determination results. Fig. 9 Another optional flow chart of storage logic in a HashMap data processing method is shown. Before executing step S210, the following process is executed:

[0154] Step S201: Determine whether the cache module is empty and the length is 0;

[0155] If so, it indicates that there is no storage space in the cache module, and accordingly, there is no stored data, and step S210 and related processes of the cache module (such as step S220) can be skipped, and step S202 is executed to determine whether the main module is empty; if not, it indicates that there is storage space in the cache module and data may be stored, then step S210 and subsequent processes are executed based on the above process, wherein, when it is necessary to execute step S230, before executing step S230, step S202 is also executed to determine whether the main module is empty to determine whether to perform the expansion logic, and when it is necessary to execute the expansion logic, the expansion logic is executed, and then step S230 is executed.

[0156] Step S202: determine whether the main module is empty and has a length of 0;

[0157] If so, it indicates that there is no storage space in the main module, and accordingly, there is no storage data, and the expansion logic can be executed. The detailed process can refer to the description of subsequent steps S310 to S320; if not, it indicates that there is storage space in the main module, and step S230 is executed based on the above process.

[0158] After executing step S230, the capacity of the main module after storing the data to be stored can be confirmed to determine whether the capacity expansion logic needs to be executed. Specifically, after step S230, the following steps are executed:

[0159] Step S240: determining whether to execute capacity expansion logic based on the main body capacity threshold of the current main body module;

[0160] Among them, the data capacity in the main module can be preset in advance, and the corresponding maximum data capacity of the main module can be the capacity threshold. Accordingly, this step can determine whether the amount of data stored in the current main module is greater than the main capacity threshold. If so, the capacity expansion logic is executed; if not, the storage process is terminated, that is, the storage logic is exited.

[0161] In a further example, an embodiment of the present invention may further include an expansion module, which is used to execute expansion logic to expand the cache module and the main module (such as a hashmap array) to facilitate the storage of more data to be retrieved. Specifically, the corresponding expansion logic can be triggered before or after each instruction is executed to determine whether to execute the expansion and the specific expansion logic. It can also be executed at a preset time. For example, when executing the storage control logic, it is necessary to execute before storing the data to be stored in the main module, or, when executing the storage control logic, after storing the data to be stored in the main module, insert the data to be stored into the array (including inserting into the storage position of the array and inserting into the linked list or red-black tree of the array) to execute. It can also be executed after receiving a specific expansion instruction, wherein the expansion instruction can be, for example, a resize instruction.

[0162] In a specific example, the expansion logic includes expansion logic for the main module and expansion logic for the cache module. For details, refer to Fig.10 An optional flow chart of the expansion logic in a HashMap data processing method is shown, including the following process:

[0163] Step S310: executing the expansion logic for the main module;

[0164] Step S320: executing the capacity expansion logic for the cache module;

[0165] Among them, in the expansion logic, step S310 and step S320 can be executed in sequence, that is, step S310 is executed first, and then step S320 is executed. They can also be executed simultaneously or in reverse order. The present invention does not make specific limitations here.

[0166] Among them, in step S310, reference Fig.11 The optional flow chart of step S310 shown in the figure includes the following process for the expansion logic of the main module:

[0167] Step S311: Determine whether the main module is empty and has a length of 0;

[0168] If yes, it indicates that there is no storage space in the main module, and accordingly, there is no data to be retrieved, and then step S312 can be executed to create a corresponding data structure. If no, step S313 is executed to determine whether the data capacity of the current main module exceeds the preset maximum value, so as to determine whether to perform the expansion of the main module. The preset maximum value is the maximum capacity allowed to be occupied by the preset main module.

[0169] Step S312: creating an array structure for the main module, and configuring a main capacity threshold for the array structure of the main module;

[0170] The main body capacity threshold may be less than or equal to the maximum capacity of the main body module. In a specific example, the main body capacity threshold may be 0.75 times the maximum capacity of the main body module.

[0171] Step S313: Determine whether the data capacity of the current main module exceeds the preset maximum value;

[0172] If yes, it indicates that the current main module is no longer allowed to be expanded, and the process ends. If no, step S314 is executed to expand the capacity of the main module. The preset maximum value can be, for example, 2 30 bits.

[0173] Step S314: expanding the capacity of the main module and configuring a main capacity threshold for the expanded main module;

[0174] To expand the capacity of the main module, the main module may be expanded to a preset multiple of the original data capacity, for example, 2 times, and further based on the expanded data capacity, the main capacity threshold of the main module may be calculated.

[0175] When there is stored data in the original main body module, after executing step S330, the following process may be further executed:

[0176] Step S315: updating the to-be-retrieved data stored in the main module before the expansion to the main module after the expansion.

[0177] Based on the above process, the expansion logic of the main module can be implemented, thereby providing a basis for executing the storage logic of the main module.

[0178] Further, in the embodiment of the present invention, in step S320, reference Fig.12 In the optional flow chart of step S320 shown, the expansion logic of the cache module includes the following process:

[0179] Step S321: Determine whether the cache module is empty and the length is 0;

[0180] If so, it indicates that there is no storage space in the cache module, and accordingly, there is no data to be retrieved, and step S322 can be executed to create a corresponding data structure. If not, it indicates that there is storage space in the cache, and no further application for cache expansion is made, and the process ends.

[0181] Step S322: creating an array structure for the cache module, and configuring a cache capacity threshold for the array structure of the cache module;

[0182] The cache capacity threshold is used to indicate the maximum data capacity value allowed to be stored in the array structure of the cache module. In the optional example, creating an array structure for the cache module may specifically include: applying for a preset capacity of memory for the cache module (for example, applying for 1<<15 bits of memory, i.e., 2 15 bits of memory space) and create an array structure in that memory.

[0183] Based on the above process, the expansion logic of the cache module can be implemented, thereby providing a basis for executing the storage logic of the cache module.

[0184] Optionally, an embodiment of the present invention may also provide a Hashmap data processing system, which is used to execute the above-mentioned Hashmap data processing method.

[0185] Optionally, an embodiment of the present invention may also provide a computer program, which includes one or more computer executable instructions, and the one or more computer executable instructions implement the above-mentioned Hashmap data processing method when executed.

[0186] Optionally, an embodiment of the present invention may also provide a storage medium, which can store a program that implements the above-mentioned Hashmap data processing method.

[0187] The embodiment of the present invention stores the to-be-retrieved data that meets preset conditions (i.e., the probability of being retrieved is greater than the probability of being retrieved of other to-be-retrieved data) in a retrieval cache module based on key data, so that before executing the retrieval of the main module, a fast retrieval based on the to-be-retrieved key data is first executed in the cache module, and when the to-be-retrieved data does not exist in the cache module, the retrieval of the main module is executed, thereby improving the data retrieval efficiency of the to-be-retrieved data with a higher probability of being retrieved in the HashMap, thereby improving the data retrieval efficiency of the HashMap as a whole.

[0188] The above describes multiple implementation schemes provided by the embodiments of the present invention. The various optional methods introduced in the implementation schemes can be combined and cross-referenced with each other without conflict, thereby extending a variety of possible implementation schemes, which can all be considered as implementation schemes disclosed and open in the embodiments of the present invention.

[0189] Although the embodiments of the present invention are disclosed above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the scope defined by the claims.

Claims

1. A Hashmap data processing method, characterized in that: The method is applied to a Hashmap data processing device, the Hashmap data processing device comprises a main module and a cache module, the main module is used to store data to be retrieved, and the cache module is used to store data to be retrieved that meets preset conditions and is stored in the main module; wherein the probability of the data to be retrieved that meets the preset conditions being retrieved is greater than the probability of other data to be retrieved being retrieved, and the data to be retrieved in the cache module is retrieved based on key data; the method comprises: Determine whether the key data to be retrieved meets the preset conditions; If so, the cache module searches to determine whether there is data to be retrieved corresponding to the key data to be retrieved. If so, the data to be retrieved corresponding to the key data to be retrieved is obtained. If not, a search is performed on the main module based on the key data to be retrieved.

2. The Hashmap data processing method according to claim 1, characterized in that: The step of judging whether the key data to be retrieved meets the preset conditions includes: Based on the type of the key data to be retrieved, determine whether the key data to be retrieved is of a preset type. If not, it does not meet the preset conditions. If so, determine whether the key data to be retrieved is within a preset threshold range. If not, it does not meet the preset conditions. If so, it meets the preset conditions.

3. The Hashmap data processing method according to claim 2, characterized in that: The step of performing a search on the main module based on the key data to be searched includes: Calculate the hash value corresponding to the key data to be searched, and use the hash value as the search index value of the main module; Based on the search index value, determine the position in the main module corresponding to the search index value, and use the position as the target position; Determine whether the data in the target position is the data to be retrieved corresponding to the key data to be retrieved; If yes, executing the step of obtaining the data to be retrieved corresponding to the key data to be retrieved, if no, determining whether the first node data in the target position is a tree node; If it is a tree node, searching the tree structure of the target position to confirm whether there is data to be retrieved corresponding to the key data to be retrieved, and if there is data to be retrieved corresponding to the key data to be retrieved, executing the step of obtaining the data to be retrieved corresponding to the key data to be retrieved; If it is not a tree node, retrieve the linked list structure of the target position to confirm whether there is data to be retrieved corresponding to the key data to be retrieved, and if there is data to be retrieved corresponding to the key data to be retrieved, execute the step of obtaining the data to be retrieved corresponding to the key data to be retrieved.

4. The Hashmap data processing method according to claim 1, characterized in that: Before the step of determining whether the key data to be retrieved meets the preset conditions, the method includes: Determine whether the cache module is empty and has a length of 0; If not, execute the step of determining whether the key data to be retrieved meets the preset conditions; if so, determine whether the main module is empty and has a length of 0. If so, end the retrieval process; if not, execute the step of searching the main module based on the key data to be retrieved.

5. The Hashmap data processing method according to claim 1, characterized in that: Also includes: Determine whether the data to be stored meets the preset conditions; If so, the data to be stored is stored in the cache module, and the stored data to be stored is used as the data to be retrieved; if not, the data to be stored is stored in the main module, and the stored data to be stored is used as the data to be retrieved.

6. The Hashmap data processing method according to claim 5, characterized in that: The data to be stored is a key-value pair, and storing the data to be stored in the cache module is specifically: The key-value pairs are stored in an array of the cache module, wherein the key data is used as the subscript of the array, and the value data is used as the data stored in the corresponding position of the array in the cache module.

7. The Hashmap data processing method according to claim 5, characterized in that: Before the step of storing the data to be stored in the cache module, the method further includes: Determine whether the cache module is empty and its length is 0; If not, execute the step of storing the data to be stored in the cache module; if so, determine whether the main module is empty and the length is 0, if so, execute the expansion logic, if not, execute the step of storing the data to be stored in the main module.

8. The Hashmap data processing method according to claim 7, characterized in that: After the step of storing the data to be stored in the main module, the method further includes: Based on the main capacity threshold of the current main module, determine whether to execute the expansion logic; If yes, execute the expansion logic; if no, end the storage process.

9. The Hashmap data processing method according to claim 8, characterized in that: The expansion logic includes expansion logic for the main module and expansion logic for the cache module; the method further includes: Execute the expansion logic for the main module; Execute the expansion logic for the cache module.

10. The Hashmap data processing method according to claim 9, characterized in that: The executing the expansion logic for the cache module includes: Determine if the cache module is empty and has a length of 0; An array structure is created for a cache module, and a cache capacity threshold is configured for the array structure of the cache module.

11. A Hashmap data processing device, characterized in that: It includes a cache module, a main module and a retrieval control module, wherein: The main body module is used to store the data to be retrieved, and the cache module is used to store the data to be retrieved that meets the preset conditions and is stored in the main body module; wherein the probability of the data to be retrieved that meets the preset conditions being retrieved is greater than the probability of other data to be retrieved being retrieved, and the data to be retrieved in the cache module is retrieved based on the key data; The retrieval control module is used to determine whether the key data to be retrieved meets the preset conditions before executing the retrieval of the main module. If so, the cache module is searched to determine whether there is data to be retrieved corresponding to the key data to be retrieved. If so, the data to be retrieved corresponding to the key data to be retrieved is obtained. If not, the retrieval of the main module is executed based on the key data to be retrieved.

12. The Hashmap data processing device according to claim 11, characterized in that: The retrieval probability of the data to be retrieved is the historical retrieval probability of the data to be retrieved, or the predicted retrieval probability of the data to be retrieved, or a combination of the historical retrieval probability and the predicted retrieval probability.

13. The Hashmap data processing device according to claim 11, characterized in that: The preset condition is used to limit the key data to a preset type, and the preset type is one or more of integer data, floating point data, character data, and a custom object.

14. The Hashmap data processing device according to claim 13, characterized in that: The preset condition is used to limit the key data to be of a preset type and the key data to be within a preset threshold range.

15. The Hashmap data processing device according to claim 11, characterized in that: The data to be retrieved is a key-value pair, and the cache module stores the data to be retrieved in the form of an array, wherein the key data is used as the subscript of the array, and the value data is used as the data stored in the corresponding position of the array in the cache module.

16. The Hashmap data processing device according to claim 11, characterized in that: Also includes: A storage control module, the storage control module is used to implement storage logic for data to be stored, wherein the data to be stored stored in the Hashmap data processing device is used as data to be retrieved.

17. The Hashmap data processing device according to claim 11, characterized in that: Also includes: The capacity expansion module is used to execute the capacity expansion logic.

18. A Hashmap data processing system, characterized in that: The Hashmap data processing system is used to execute the Hashmap data processing method described in any one of claims 1 to 10.

19. A computer program, characterized in that It comprises one or more computer executable instructions, and when the one or more computer executable instructions are executed, the Hashmap data processing method as described in any one of claims 1-10 is implemented.

20. A storage medium, characterized in that: The storage medium stores a program for implementing the Hashmap data processing method described in any one of claims 1-10.