Hash table data insertion method, system and electronic device

By combining the primary hash bucket and the secondary hash bucket, setting the culling threshold and priority principle, the loop kick problem of cuckoo hashing when adding data is solved, and the data addition efficiency and data table utilization are improved.

CN119988374BActive Publication Date: 2025-10-17DAPUSTOR CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411994793.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-10-17
Estimated Expiration
2044-12-31

AI Technical Summary

Technical Problem

The existing Cuckoo Hash is prone to loop kicking when adding data, resulting in low data addition efficiency and reduced data table utilization.

Method used

The structure of main hash bucket and secondary hash bucket is adopted, the culling times threshold is set, and the culling subslot and alternative bucket are determined through the new element priority principle and the culling element priority principle. The secondary hash bucket subslot is shifted cyclically to find an idle position to insert the new element.

Benefits of technology

It improves the efficiency of data addition, avoids the loop kick phenomenon, and improves the utilization rate of data tables.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119988374B_ABST
    Figure CN119988374B_ABST
Patent Text Reader

Abstract

The embodiment of the application relates to the technical field of data processing, and discloses a data insertion method and system of a hash table and electronic equipment, the method comprises the following steps: obtaining a new element, calculating the address of a main hash bucket and the address of a secondary hash bucket according to the new element, determining that there is no empty slot in the main hash bucket, the secondary hash bucket and the main candidate bucket corresponding to the sub-slot of the main hash bucket, judging whether there is an empty slot in the candidate bucket corresponding to the sub-slot of the secondary hash bucket, if there is an empty slot, determining the elimination sub-slot in the secondary hash bucket according to the new element priority principle, adding the element in the elimination sub-slot to the candidate bucket corresponding to the elimination sub-slot, inserting the new element into the elimination sub-slot of the secondary hash bucket, if there is no empty slot, determining the elimination sub-slot in the secondary hash bucket according to the elimination element priority principle, circularly shifting the sub-slot in the secondary hash bucket, and then executing the judging step until there is a free sub-slot in the candidate bucket corresponding to the secondary candidate bucket, so that the data addition efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, in particular to a data insertion method and system of a hash table and an electronic device. BACKGROUND

[0002] In the field of computer algorithm, database management and information processing technology, the utilization rate of the data table is a key indicator to measure the system performance and resource use efficiency, especially in the big data processing scene, the utilization rate of the data table is directly related to the data scale and processing speed that the system can process.

[0003] At present, the cuckoo hash is usually used to manage the data table, wherein the cuckoo hash is a data structure which stores key-value pairs by selecting hash buckets and sub-slots through hash values, but when a new key-value pair needs to be added, if a full hash bucket is encountered, random replacement of other hash buckets and sub-slots is needed, and in the replacement process, the hash buckets and sub-slots that have been occupied or previously accessed will be encountered, resulting in a loop kicking phenomenon, which reduces the efficiency of data addition and the utilization rate of the data table. SUMMARY

[0004] The embodiments of the present application provide a data insertion method and system of a hash table and an electronic device, which can improve the efficiency of data addition.

[0005] To solve the above technical problems, the embodiments of the present application provide the following technical solutions:

[0006] In a first aspect, the embodiments of the present application provide a data insertion method of a hash table, the hash table comprising a main hash bucket and a secondary hash bucket, and the method comprising:

[0007] Setting a threshold of the number of rejection times, obtaining a new element to be inserted;

[0008] According to the new element, obtaining the address of the main hash bucket and the address of the secondary hash bucket, obtaining the main hash bucket according to the address of the main hash bucket, and obtaining the secondary hash bucket according to the address of the secondary hash bucket, wherein the main hash bucket and the secondary hash bucket each comprise a plurality of sub-slots, each sub-slot corresponds to a candidate bucket, and the sub-slot is used to store the new element;

[0009] When the main hash bucket, the secondary hash bucket and the candidate bucket corresponding to the main hash bucket all do not have an idle sub-slot, judging whether there is an empty slot in the candidate bucket corresponding to the secondary hash bucket;

[0010] If there is an idle sub-slot in the candidate bucket corresponding to the secondary candidate bucket, determining a first rejection sub-slot and a first candidate bucket according to the priority principle of the new element, wherein the first rejection sub-slot is one of the plurality of sub-slots in the secondary candidate bucket, and the first candidate bucket is the candidate bucket corresponding to the first rejection sub-slot;

[0011] adding the element of the first rejection sub-slot into the first candidate bucket, inserting the new element into the first rejection sub-slot, and success of the adding;

[0012] If there is no free sub-slot in the candidate bucket corresponding to the secondary candidate bucket, determining, according to the rejection element priority principle, a second rejection sub-slot in the secondary candidate hash bucket and a second candidate bucket corresponding to the second rejection sub-slot, wherein the second rejection sub-slot is one of the sub-slots in the secondary candidate hash bucket, and the second candidate bucket is the candidate bucket corresponding to the second rejection sub-slot;

[0013] After circularly shifting all the sub-slots in the secondary candidate hash bucket in order, covering the hash bucket, and increasing the rejection times by one;

[0014] Replacing the second candidate bucket with the secondary candidate bucket, and determining whether there is a free sub-slot in the secondary candidate bucket until there is a free sub-slot in the candidate bucket corresponding to the secondary candidate bucket or the rejection times equal the rejection times threshold.

[0015] In some embodiments, the hash table includes a plurality of domain segments, each domain segment including a plurality of hash buckets, and the new element priority principle includes a most free sub-slot quantity principle of the hash buckets, a most free sub-slot quantity principle of the domain segments, and a tail preference principle;

[0016] According to the new element priority principle, determining the first rejection sub-slot and the first candidate bucket includes:

[0017] According to the most free sub-slot quantity principle of the hash buckets, determining a third candidate bucket, wherein the third candidate bucket is the candidate bucket with the most free sub-slots among all the candidate buckets corresponding to the secondary hash bucket;

[0018] If the number of the third candidate buckets is greater than a preset number, according to the most free sub-slot quantity principle of the domain segments, determining a fourth candidate bucket, wherein the fourth candidate bucket is a candidate bucket in the third candidate buckets;

[0019] If the number of the fourth candidate buckets is greater than the preset number, according to the tail preference principle, determining a fifth candidate bucket, and taking the fifth candidate bucket as the first candidate bucket, wherein the fifth candidate bucket is one of the plurality of fourth candidate buckets;

[0020] Taking the sub-slot in the secondary hash bucket corresponding to the first candidate bucket as the first rejection sub-slot.

[0021] In some embodiments, the rejection element priority principle includes a tail preference rejection principle or a head preference rejection principle;

[0022] According to the rejection element priority principle, determining the second rejection sub-slot in the secondary candidate hash bucket and the second candidate bucket corresponding to the second rejection sub-slot includes:

[0023] If the rejection element priority principle is the tail preference rejection principle, taking the first sub-slot at the tail of the secondary hash bucket as the second rejection sub-slot;

[0024] If the element priority principle is the head priority principle, the first sub-slot of the head of the secondary hash bucket is taken as the second deletion sub-slot;

[0025] The alternative bucket corresponding to the second deletion sub-slot is taken as the second alternative bucket.

[0026] In some embodiments, all sub-slots in the secondary alternative hash bucket are circularly shifted in order, including:

[0027] All sub-slots in the secondary alternative hash bucket are sequentially shifted one position towards the tail of the secondary alternative hash bucket until all sub-slots in the secondary alternative hash bucket are completed.

[0028] In some embodiments, the method further includes:

[0029] If the number of the third alternative buckets is equal to the preset number, the third alternative bucket is taken as the first alternative bucket;

[0030] If the number of the fourth alternative buckets is equal to the preset number, the fourth alternative bucket is taken as the first alternative bucket.

[0031] In some embodiments, the method further includes:

[0032] If the primary hash bucket has free sub-slots and the secondary hash bucket has no free sub-slots, the new element is inserted into the free sub-slot of the primary hash bucket;

[0033] If the primary hash bucket has no free sub-slots and the secondary hash bucket has free sub-slots, the new element is inserted into the free sub-slot of the secondary hash bucket;

[0034] If the primary hash bucket and the secondary hash bucket both have free sub-slots, the hash bucket is determined according to the new element priority principle, and the new element is inserted into the hash bucket, wherein the hash bucket is one of the primary hash bucket and the secondary hash bucket;

[0035] If the primary hash bucket has no free sub-slots and the secondary hash bucket has no free sub-slots, the primary alternative bucket corresponding to the sub-slot of the primary hash bucket has free sub-slots, the new element is inserted into the free sub-slot of the primary alternative bucket corresponding to the sub-slot of the primary hash bucket;

[0036] If the primary hash bucket has no free sub-slots and the secondary hash bucket has no free sub-slots, the primary alternative bucket corresponding to the sub-slot of the primary hash bucket has no free sub-slots, and the secondary alternative bucket corresponding to the sub-slot of the secondary hash bucket has free sub-slots, the new element is inserted into the free sub-slot of the secondary alternative bucket corresponding to the sub-slot of the secondary hash bucket.

[0037] In a second aspect, the embodiments of the present application provide a data insertion system of a hash table, the hash table including a primary hash bucket and a secondary hash bucket, the system including:

[0038] The hash bucket determination unit is configured to obtain a new element to be inserted, and obtain an address of a primary hash bucket and an address of a secondary hash bucket according to the new element, wherein the primary hash bucket and the secondary hash bucket are used to store data, the primary hash bucket includes a plurality of sub-slots, and the secondary hash bucket includes a plurality of sub-slots, each of the sub-slots in the primary hash bucket corresponds to a primary candidate bucket, and each of the sub-slots in the secondary hash bucket corresponds to a secondary candidate bucket;

[0039] The element elimination priority determination unit is configured to determine, based on the address of the primary hash bucket and the address of the secondary hash bucket, that when there is no idle sub-slot in the primary hash bucket, the secondary hash bucket, all the primary candidate buckets corresponding to the primary hash bucket, and all the secondary candidate buckets corresponding to the secondary hash bucket, the first elimination sub-slot corresponding to the secondary hash bucket is determined according to an element elimination priority principle, wherein the first elimination sub-slot is one of the sub-slots in the secondary hash bucket.

[0040] The new element priority determination unit is configured to, based on the first elimination sub-slot, circularly shift all the sub-slots in the secondary hash bucket in order to obtain a shifted secondary hash bucket, obtain a first candidate bucket corresponding to each of the sub-slots in the shifted secondary hash bucket, and determine a second candidate bucket according to a new element priority principle if there is an idle sub-slot in the first candidate bucket, wherein the second candidate bucket is one of the plurality of first candidate buckets.

[0041] The elimination replacement unit is configured to add an element in the first elimination sub-slot to an idle sub-slot in the second candidate bucket, and cover the new element to the first elimination sub-slot.

[0042] In some embodiments, the system further includes:

[0043] The hash table is configured to store the new element.

[0044] The element elimination random memory is configured to record an elimination number of each of the sub-slots in the hash table.

[0045] In a third aspect, an embodiment of the present application provides an electronic device, including:

[0046] at least one processor, and

[0047] a memory in communication connection with the at least one processor, wherein

[0048] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the data insertion method of the hash table according to the first aspect.

[0049] The beneficial effects of the embodiments of the present application are that, different from the prior art, the data insertion method of the hash table provided by the embodiments of the present application includes a primary hash bucket and a secondary hash bucket, and the method includes setting an elimination number threshold, obtaining a new element to be inserted,

[0050] According to the new element, the address of the main hash bucket and the address of the secondary hash bucket are obtained, the main hash bucket is obtained according to the address of the main hash bucket, and the secondary hash bucket is obtained according to the address of the secondary hash bucket, wherein the main hash bucket and the secondary hash bucket each include a plurality of sub-slots, each sub-slot corresponds to a candidate bucket, and the sub-slot is used to store the new element. When there is no free sub-slot in the main hash bucket, the secondary hash bucket and the candidate bucket corresponding to the main hash bucket, it is judged whether there is a free sub-slot in the candidate bucket corresponding to the secondary hash bucket. If there is a free sub-slot in the candidate bucket corresponding to the secondary hash bucket, the first elimination sub-slot and the first candidate bucket are determined according to the new element priority principle, wherein the first elimination sub-slot is one of the plurality of sub-slots in the secondary candidate bucket, and the first candidate bucket is the candidate bucket corresponding to the first elimination sub-slot. The elements of the first elimination sub-slot are added to the first candidate bucket, and the new element is inserted into the first elimination sub-slot. If the secondary candidate bucket corresponding to the candidate bucket does not exist, the second elimination sub-slot in the secondary candidate bucket and the second candidate bucket are determined according to the elimination element priority principle, wherein the second elimination sub-slot is one of the sub-slots in the secondary candidate hash bucket, and the second candidate bucket is the candidate bucket corresponding to the second elimination sub-slot. After the sub-slots in the secondary candidate hash bucket are circularly shifted in order, the candidate hash bucket is overwritten, the elimination times are increased by one, the second candidate bucket is replaced by the secondary candidate bucket, and it is judged whether there is a free sub-slot in the secondary candidate bucket. Until there is a free sub-slot in the candidate bucket corresponding to the secondary candidate bucket or the elimination times equal the elimination times threshold.

[0051] By obtaining a new element, the address of the main hash bucket and the address of the secondary hash bucket are calculated according to the new element. It is determined that there is no empty slot in each main candidate bucket corresponding to the sub-slot of the main hash bucket and the secondary hash bucket. Then it is judged whether there is an empty slot in each candidate bucket corresponding to the sub-slot of the secondary hash bucket. If there is an empty slot, the elimination sub-slot in the secondary hash bucket is determined according to the new element priority principle. The elements in the elimination sub-slot are added to the candidate bucket corresponding to the elimination sub-slot. The new element is inserted into the elimination sub-slot of the secondary hash bucket. If there is no empty slot, the elimination sub-slot in the secondary hash bucket is determined according to the elimination element priority principle. The sub-slots in the secondary hash bucket are circularly shifted, and the judgment step is executed again until there is a free sub-slot in the candidate bucket corresponding to the secondary candidate bucket. This can avoid repeated elimination path, so as to improve the efficiency of data addition. BRIEF DESCRIPTION OF DRAWINGS

[0052] One or more embodiments are illustrated by way of example in the figures that form a part of this patent document. These illustrations are not intended to limit the application in any way, but to illustrate only the illustrative principles of the application. Elements having the same reference numbers in the figures indicate identical elements unless otherwise specifically indicated. The figures in the drawings are not necessarily to scale, except where otherwise noted.

[0053] Figure 1 is a flowchart of a data insertion method of a hash table provided by an embodiment of the present application;

[0054] Figure 2 This is an example schematic diagram of inserting a new element into a hash table provided by an embodiment of the present application;

[0055] Figure 3 yes Figure 1 A detailed flowchart of step S1010 in FIG.

[0056] Figure 4 This is another example schematic diagram of inserting a new element into a hash table provided by an embodiment of the present application;

[0057] Figure 5 yes Figure 1 A detailed flowchart of step S1011 in FIG.

[0058] Figure 6 yes Figure 1 A detailed flowchart of step S1012 in FIG.

[0059] Figure 7 This is another example schematic diagram of inserting a new element into a hash table provided by an embodiment of the present application;

[0060] Figure 8 This is a structural diagram of a hash table data insertion system provided in an embodiment of the present application;

[0061] Figure 9 It is a structural diagram of an electronic device provided in an embodiment of the present application.

[0062] Description of Figure Numbers:

[0063] DETAILED DESCRIPTION

[0064] In order to make the purpose, technical solutions and advantages of this application more clearly understood, the present application is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0065] It should be noted that, if there is no conflict, the various features in the embodiments of the present application can be combined with each other and are all within the scope of protection of the present application. In addition, although the functional modules are divided in the device schematic and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a different order than the module division in the device or the order in the flow chart. Furthermore, the words "first", "second", "third", etc. used in this application do not limit the data and execution order, but only distinguish between the same items or similar items with basically the same functions and effects.

[0066] In addition, the technical features involved in each embodiment of the present application described below can be combined with each other as long as they do not conflict with each other.

[0067] Before introducing the embodiments of the present application, a brief introduction to the prior art known to the inventors of the present application is first given to facilitate subsequent understanding of the embodiments of the present application.

[0068] Cuckoo Hash is a data structure that stores key-value pairs using hash buckets and subslots. When a new key-value pair needs to be added, if a full hash bucket is encountered, a random subslot is randomly selected from the hash bucket to replace it. During the replacement process, occupied or previously accessed hash buckets and subslots may be encountered, resulting in a loop kick phenomenon, which reduces the efficiency of data addition and the utilization of the data table.

[0069] In response to the above problems, the present application provides a data insertion method for a hash table, which obtains a new element and calculates the address of the main hash bucket and the address of the secondary hash bucket based on the new element, determines whether there are empty slots in the main alternative bucket corresponding to the main hash bucket, the secondary hash bucket, and the subslot of the main hash bucket, then determines whether there are empty slots in the alternative bucket corresponding to the subslot of the secondary hash bucket. If there are empty slots, the removal subslot in the secondary hash bucket is determined according to the priority principle of the newly added elements, and the elements in the removal subslot are added to the alternative bucket corresponding to the removal subslot, and the new element is inserted into the removal subslot of the secondary hash bucket. If there are no empty slots, the removal subslot in the secondary hash bucket is determined according to the priority principle of the removed elements, and the subslots in the secondary hash bucket are cyclically shifted, and then the judgment step is executed until there are free subslots in the alternative bucket corresponding to the secondary alternative bucket, which can improve the efficiency of data addition.

[0070] The technical solution of this application is described in detail below with reference to the accompanying drawings:

[0071] See also Figure 1 , Figure 1 This is a flow chart of a method for inserting data into a hash table provided in an embodiment of the present application.

[0072] The method for inserting data into a hash table is applied to an electronic device. Specifically, the method for inserting data into a hash table is executed by one or at least two processors of the electronic device.

[0073] like Figure 1 As shown, the data insertion method of the hash table includes:

[0074] Step S1001: Set a threshold for the number of times elements are removed and obtain a new element to be inserted.

[0075] In the embodiments of the present application, the hash table is a data structure for implementing a mapping relationship of key-value pairs, and the hash table maps a key to a certain position in an array through a hash function, thereby realizing fast search, insertion and deletion operations on records.

[0076] The hash table includes a plurality of hash buckets, and each hash bucket is a container or a slot for storing a key-value pair.

[0077] Specifically, a new element to be inserted into the hash table is obtained, and the new element is an element that is inserted into the hash table for the first time.

[0078] The threshold of the number of times of elimination is the maximum number of times of elimination of each sub-slot.

[0079] In the embodiments of the present application, when a new element is inserted, an idle sub-slot needs to be found from a hash bucket to store the new element, and when the hash bucket has no idle sub-slot, an idle sub-slot needs to be found from a candidate bucket corresponding to the hash bucket, and a sub-slot is selected from the hash bucket for replacement. When the number of times of replacement of the sub-slot is more, the data insertion rate of the hash table will be lower and lower. When no idle sub-slot is found, the operation of circularly searching for an idle sub-slot will be performed. In order to avoid the phenomenon of circular elimination, the threshold of the number of times of elimination needs to be set to limit the number of times of elimination of each sub-slot.

[0080] Step S1002: An address of a primary hash bucket and an address of a secondary hash bucket are obtained according to the new element, the primary hash bucket is obtained according to the address of the primary hash bucket, and the secondary hash bucket is obtained according to the address of the secondary hash bucket.

[0081] In the embodiments of the present application, the hash bucket includes a primary hash bucket and a secondary hash bucket, the primary hash bucket includes a plurality of sub-slots, and the secondary hash bucket includes a plurality of sub-slots.

[0082] Specifically, the new element includes a key and a data item, a hash function hash_function() is used to perform hash calculation on the key of the new element, and the address of the primary hash bucket and the address of the secondary hash bucket are obtained, for example, (pri_bucket_addr, sec_bucket_addr) = hash_function(key), where key is the key, pri_bucket_addr is the address of the primary hash bucket, and sec_bucket_addr is the address of the secondary hash bucket.

[0083] Specifically, the address of the primary hash bucket and the address of the secondary hash bucket are input into a obtaining function to obtain the primary hash bucket and the secondary hash bucket, for example, the obtaining function is get_bucket(), (pri_bucket, sec_bucket) = get_bucket(pri_bucket_addr, sec_bucket_addr), pri_bucket_addr is the address of the primary hash bucket, sec_bucket_addr is the address of the secondary hash bucket, pri_bucket is the primary hash bucket, and sec_bucket is the secondary hash bucket.

[0084] Step S1003: Determine whether the primary hash bucket has a free sub-slot.

[0085] Specifically, whether the primary hash bucket has a free sub-slot is determined by a detection function, if the primary hash bucket has a free sub-slot, the process jumps to step S1004, and if the primary hash bucket does not have a free sub-slot, the process jumps to step S1005.

[0086] The detection function can be IsEmptySlot(), for example, IsEmptySlot(pri_bucket), and pri_bucket is the primary hash bucket.

[0087] Step S1004: Insert the new element into the free sub-slot of the primary hash bucket.

[0088] Specifically, when the primary hash bucket has a free sub-slot, the new element is inserted into the free sub-slot of the primary hash bucket.

[0089] In the embodiment of the present application, the primary hash bucket includes multiple sub-slots, and when the primary hash bucket has multiple free sub-slots, the new element is inserted from the tail of the primary hash bucket.

[0090] Step S1005: Determine whether the secondary hash bucket has a free sub-slot.

[0091] Specifically, whether the secondary hash bucket has a free sub-slot is determined by a detection function, if the secondary hash bucket has a free sub-slot, the process jumps to step S1006, and if the secondary hash bucket does not have a free sub-slot, the process jumps to step S1007.

[0092] The detection function can be IsEmptySlot(), for example, IsEmptySlot(sec_bucket), and sec_bucket is the secondary hash bucket.

[0093] Step S1006: Insert the new element into the free sub-slot of the secondary hash bucket.

[0094] Specifically, when the secondary hash bucket has a free sub-slot, the new element is inserted into the free sub-slot of the secondary hash bucket.

[0095] In the embodiment of the present application, the secondary hash bucket includes a plurality of sub-slots, and when the secondary hash bucket has a plurality of idle sub-slots, the new element is inserted from the tail of the secondary hash bucket.

[0096] In the embodiment of the present application, the primary hash bucket and the secondary hash bucket can be detected simultaneously, and the order is not limited. When the primary hash bucket and the secondary hash bucket both have idle sub-slots, one of the primary hash bucket and the secondary hash bucket is determined as the corresponding bucket of the new element according to the priority principle of the new element. The specific content of the priority principle of the new element is described in detail in Figure 3 .

[0097] Please refer to Figure 2 , Figure 2 is an example schematic diagram provided by the embodiment of the present application for inserting a new element into a hash table.

[0098] As shown in Figure 2 , this Figure 2 is an example diagram for inserting a new element into a hash table when the primary hash bucket and the secondary hash bucket both have idle sub-slots. It is assumed that the hash table has five domain segments, domain segment 0 to domain segment 4, each domain segment includes four hash buckets, one hash bucket (bucket) has four sub-slots (slots), a total of 80 slots, 20 buckets, bucket 0 to bucket 19, the maximum load (i.e. the number of sub-slots) of each domain segment is 16 slots, H (head) represents the head of the hash bucket, T (tail) represents the tail of the hash bucket. After obtaining the new element key, the primary hash bucket H1 is calculated as bucket 2 and the secondary hash bucket H2 is calculated as bucket 12 through hash calculation. There are idle sub-slots in bucket 2 and bucket 12, the number of idle sub-slots of bucket 2 is 2, and the number of idle sub-slots of bucket 12 is 1. Then the new element key is inserted into the idle sub-slot of bucket 2.

[0099] Step S1007: determining whether the primary hash bucket has an idle sub-slot.

[0100] In the embodiment of the present application, the primary hash bucket and the secondary hash bucket both include a plurality of sub-slots, and each sub-slot corresponds to one candidate bucket.

[0101] Specifically, when the primary hash bucket and the secondary hash bucket both do not have idle sub-slots, the candidate bucket corresponding to each sub-slot of the primary hash bucket is obtained, and it is determined whether the candidate bucket corresponding to the primary hash bucket has an idle sub-slot. If the candidate bucket corresponding to the sub-slot of the primary hash bucket has an idle sub-slot, the step S1008 is jumped to. If the candidate bucket corresponding to the sub-slot of the primary hash bucket does not have an idle sub-slot, the step S1009 is jumped to.

[0102] In the embodiment of the present application, the address of the primary candidate bucket is known, and the address of each sub-slot of the primary candidate bucket is known, and according to the address of the sub-slot in the primary candidate bucket, the candidate bucket corresponding to the sub-slot of the primary candidate bucket can be obtained, each sub-slot corresponds to one candidate bucket, for example, when there are four sub-slots, {pri_slot3, pri_slot2, pri_slot1, pri_slot0} = pri_bucket, pri_bucket is the primary candidate bucket, and pri_slot3, pri_slot2, pri_slot1, and pri_slot0 are four sub-slots of the primary candidate bucket, and the primary candidate buckets corresponding to pri_slot3, pri_slot2, pri_slot1, and pri_slot0 are {sec_bucket3, sec_bucket2, sec_bucket1, sec_bucket0}, respectively.

[0103] Step S1008: According to the new element priority principle, a hash bucket is determined, and the new element is inserted into the hash bucket.

[0104] Specifically, when the sub-slot of the primary hash bucket corresponds to a candidate bucket with a free sub-slot, according to the new element priority principle, a hash bucket is determined, and the new element is inserted into the hash bucket. The specific content of the new element priority principle is described in detail in Figure 3 .

[0105] In the embodiment of the present application, since the primary hash bucket has multiple sub-slots, each sub-slot corresponds to a candidate bucket, and when each sub-slot of the primary hash bucket corresponds to a candidate bucket with a free sub-slot, a candidate bucket needs to be determined from all candidate buckets corresponding to the primary hash bucket, to further insert the new element into the hash bucket.

[0106] Step S1009: Determine whether the candidate bucket corresponding to the secondary hash bucket has a free sub-slot.

[0107] Specifically, when the sub-slot of the primary hash bucket corresponds to a candidate bucket without a free sub-slot, the candidate bucket corresponding to each sub-slot of the secondary hash bucket is obtained, and it is determined whether the candidate bucket corresponding to the secondary hash bucket has a free sub-slot, if the sub-slot of the secondary hash bucket corresponds to a candidate bucket with a free sub-slot, step S1010 is jumped to, and if the sub-slot of the secondary hash bucket corresponds to a candidate bucket without a free sub-slot, step S1011 is jumped to.

[0108] In the embodiment of the present application, the address of the secondary candidate bucket is known, and the address of each sub-slot of the secondary candidate bucket is known, and according to the address of the sub-slot in the secondary candidate bucket, the candidate bucket corresponding to the sub-slot of the secondary candidate bucket can be obtained, each sub-slot corresponds to one candidate bucket, for example, when the secondary candidate bucket has four sub-slots, {sec_slot3, sec_slot2, sec_slot1, sec_slot0} = sec_bucket, sec_bucket is the secondary candidate bucket, sec_slot3, sec_slot2, sec_slot1, sec_slot0 are four sub-slots of the secondary candidate bucket, and the secondary candidate buckets corresponding to {sec_slot3, sec_slot2, sec_slot1, sec_slot0} are {sec_bucket3, sec_bucket2, sec_bucket1, sec_bucket0} respectively.

[0109] Step S1010: determining the first rejection sub-slot and the first candidate bucket according to the new element priority principle.

[0110] The new element priority principle includes the maximum number of free sub-slots of the hash bucket principle, the maximum number of free sub-slots of the domain segment principle, and the tail priority principle.

[0111] Specifically, when the candidate bucket corresponding to the sub-slot of the secondary hash bucket has a free sub-slot, the new element priority principle is used to determine the first rejection sub-slot and the first candidate bucket, wherein the first rejection sub-slot is one sub-slot in the secondary hash bucket, and the first candidate bucket is the candidate bucket corresponding to the first rejection sub-slot.

[0112] Please refer to Figure 3 , Figure 3 is Figure 1 the detailed flowchart of step S1010 in

[0113] As Figure 3 shown, this step S1010 includes:

[0114] Step S11101: determining the third candidate bucket according to the maximum number of free sub-slots of the hash bucket principle.

[0115] Specifically, the number of free sub-slots in the candidate bucket corresponding to each sub-slot of the secondary hash bucket is obtained, and the candidate bucket with the maximum number of free sub-slots is taken as the third candidate bucket.

[0116] For example, the secondary hash bucket has four sub-slots, and the number of free sub-slots in the candidate buckets corresponding to the four sub-slots is (1, 2, 3, 4) respectively, and the candidate bucket with four free sub-slots is taken as the third candidate bucket.

[0117] In the embodiments of the present application, there can be a case that the number of idle sub-slots in the candidate buckets corresponding to each sub-slot of the secondary hash bucket is equal, for example, the secondary hash bucket has 4 sub-slots, and the number of idle sub-slots in the candidate buckets corresponding to the 4 sub-slots is (4, 4, 3, 4) respectively, then the candidate bucket with 4 idle sub-slots is taken as the third candidate bucket, then there are three third candidate buckets, and then one third candidate bucket needs to be further selected from the three third candidate buckets.

[0118] In the embodiments of the present application, the more the number of idle sub-slots of the hash bucket, the lighter the load of the bucket.

[0119] Step S11102: Determine whether the number of third candidate buckets is greater than a preset number.

[0120] The preset number is 1.

[0121] Specifically, it is determined whether the number of third candidate buckets is greater than a preset number, if the number of third candidate buckets is equal to the preset number, then jump to step S11103, if the number of third candidate buckets is greater than the preset number, then jump to step S11104.

[0122] Step S11103: Determine the third secondary candidate bucket as the first secondary candidate bucket.

[0123] Specifically, when the number of third candidate buckets is equal to the preset number, the third secondary candidate bucket is taken as the first secondary candidate bucket, that is, the candidate bucket with the most idle sub-slots in the multiple candidate buckets corresponding to the secondary hash bucket is taken as the first secondary candidate bucket.

[0124] Step S11104: Determine the fourth candidate bucket according to the principle of the most idle sub-slots of the domain segment.

[0125] In the embodiments of the present application, the hash table includes multiple domain segments, and each domain segment includes multiple hash buckets.

[0126] Specifically, when the number of third candidate buckets is greater than the preset number, the fourth candidate bucket is determined according to the principle of the most idle sub-slots of the domain segment, the fourth candidate bucket is a candidate bucket in the third candidate bucket, and the number of idle sub-slots in the domain segment where the fourth candidate bucket is located is greater than the number of idle sub-slots in the domain segment where the candidate bucket in the third candidate bucket is located.

[0127] For example, there are three third candidate buckets, and the domain segments where the three third candidate buckets are located are domain segment 1, domain segment 2 and domain segment 3 respectively, the number of idle sub-slots of domain segment 1 is 7, the number of idle sub-slots of domain segment 2 is 8, and the number of idle sub-slots of domain segment 3 is 8, then the third candidate buckets in domain segment 2 and domain segment 3 are taken as the fourth candidate buckets, at this time, there is one more candidate bucket, then one candidate bucket needs to be further selected from the multiple fourth candidate buckets.

[0128] The more the number of idle sub-slots of the domain segment is, the lighter the load of the domain segment is.

[0129] Step S11105: determining whether the number of the fourth sub-candidate buckets is greater than a preset number.

[0130] Specifically, it is determined whether the number of the fourth sub-candidate buckets is greater than a preset number. If the number of the fourth sub-candidate buckets is equal to the preset number, the process proceeds to step 11106. If the number of the fourth sub-candidate buckets is greater than the preset number, the process proceeds to step 11107.

[0131] Step S11106: determining that the fourth sub-candidate bucket is the first sub-candidate bucket.

[0132] Specifically, when the number of the fourth sub-candidate buckets is equal to the preset number, the fourth sub-candidate bucket is determined as the first sub-candidate bucket, i.e., the fourth sub-candidate bucket is selected as the first sub-candidate bucket, i.e., the sub-candidate bucket with the largest number of idle sub-slots in the domain segment corresponding to the sub-hash bucket is selected as the first sub-candidate bucket.

[0133] Step S11107: determining a fifth sub-candidate bucket according to a tail-first principle, and selecting the fifth sub-candidate bucket as the first sub-candidate bucket.

[0134] In the embodiment of the present application, each hash bucket in the hash table corresponds to a serial number.

[0135] The tail-first principle means that the sub-candidate bucket with the largest serial number is selected first.

[0136] Specifically, according to the tail-first principle, the sub-candidate bucket with the largest serial number in the fourth sub-candidate bucket is selected as the fifth sub-candidate bucket, and the fifth sub-candidate bucket is selected as the first sub-candidate bucket.

[0137] For example, there are two fourth sub-candidate buckets with serial numbers 12 and 18 respectively, and the fourth sub-candidate bucket with the serial number 18 is selected as the fifth sub-candidate bucket.

[0138] Step S11108: selecting the sub-slot in the sub-hash bucket corresponding to the first sub-candidate bucket as the first rejection sub-slot.

[0139] Specifically, the sub-slot in the sub-hash bucket corresponding to the first sub-candidate bucket is selected as the first rejection sub-slot.

[0140] For example, the first sub-candidate bucket is the sub-candidate bucket corresponding to the first sub-slot in the sub-hash bucket, and the first sub-slot in the sub-hash bucket is selected as the first rejection sub-slot.

[0141] In the embodiment of the present application, after the first rejection sub-slot and the first sub-candidate bucket are determined, the elements in the first rejection sub-slot are moved to the idle sub-slots of the first sub-candidate bucket, and the new elements are added to the first rejection sub-slot.

[0142] Please refer toFigure 4 , Figure 4 is another example of inserting a new element into a hash table provided by an embodiment of the present application.

[0143] As shown in Figure 4 , the Figure 4 is an example of inserting a new element into a hash table in the case that there is no free sub-slot in the main hash bucket and the secondary hash bucket, and there is a free sub-slot in the sub-slot corresponding to the alternative bucket of the main hash bucket. It is assumed that there are five domain segments, domain segment 0 to domain segment 4, in the hash table, each of which includes four hash buckets, and each hash bucket includes four sub-slots, so that there are a total of 80 slots and 20 buckets, bucket 0 to bucket 19. The maximum load (i.e., the number of sub-slots) of each domain segment is 16 slots. H (head) represents the head of a hash bucket, and T (tail) represents the tail of a hash bucket. After obtaining a new element key, the main hash bucket H1 is calculated to be bucket 2, and the secondary hash bucket H2 is calculated to be bucket 9. There is no free sub-slot in bucket 2 and bucket 9. The sub-slot corresponding to the main alternative bucket of the main hash bucket H1 (i.e., bucket 2) is obtained. There is a free sub-slot in the alternative bucket corresponding to bucket 2. The alternative buckets corresponding to all sub-slots {slot 3, slot 2, slot 1, slot 0} of bucket 2 are {bucket 10, bucket 8, bucket 5, bucket 4}, respectively. The bucket loads of {bucket 10, bucket 8, bucket 5, bucket 4} are {1, 1, 1, 0}, respectively. The domain segment loads of {bucket 10, bucket 8, bucket 5, bucket 4} are {7, 7, 1, 1}, respectively. The smaller the bucket load is, the more free sub-slots there are in the hash bucket. The smaller the domain segment load is, the more free sub-slots there are in the domain segment. According to the priority principle of adding an element, the hash bucket with the smallest bucket load is selected preferentially. The bucket load of bucket 4 is the smallest. The sub-slot of bucket 2 corresponding to bucket 4 is slot 0. Slot 0 is selected as the removal sub-slot. The element of slot 0 is moved to the free sub-slot of bucket 4. The new element key is inserted into slot 0 of bucket 2.

[0144] Step S1011: According to the removal element priority principle, the second removal sub-slot and the second alternative bucket in the secondary alternative bucket are determined.

[0145] Specifically, when there is no free sub-slot in the main hash bucket, the secondary hash bucket, the alternative bucket corresponding to the main hash bucket, and the alternative bucket corresponding to the secondary hash bucket, the second removal sub-slot and the second alternative bucket in the secondary alternative bucket are determined according to the removal element priority principle.

[0146] The element elimination priority principle includes a tail-first elimination principle and a head-first elimination principle. The tail-first elimination principle means that a sub-slot at a tail of the hash bucket is preferentially selected to eliminate the sub-slot at the tail of the hash bucket. The head-first elimination principle means that a sub-slot at a head of the hash bucket is preferentially selected to eliminate the sub-slot at the head of the hash bucket.

[0147] Referring to Figure 5 , Figure 5 is Figure 1 a refinement of step S1011 in

[0148] As shown in Figure 5 , step S1011 includes:

[0149] Step S1111: Determine whether the element elimination priority principle is the tail-first elimination principle.

[0150] Specifically, when the element elimination priority principle is not the tail-first elimination principle, the process jumps to step S1112. When the element elimination priority principle is the tail-first elimination principle, the process jumps to step S1113.

[0151] Step S1112: Take the first sub-slot at the head of the secondary hash bucket as the second elimination sub-slot.

[0152] The second elimination sub-slot is a sub-slot in the secondary hash bucket.

[0153] Specifically, when the element elimination priority principle is the head-first elimination principle, the first sub-slot at the head of the secondary hash bucket is taken as the second elimination sub-slot. For example, the second elimination sub-slot kickout_slot = HeadSlot(sec_bucket) = sec_slot0, and sec_bucket is the secondary hash bucket.

[0154] Step S1113: Take the first sub-slot at the tail of the secondary hash bucket as the second elimination sub-slot.

[0155] Specifically, when the element elimination priority principle is the tail-first elimination principle, the first sub-slot at the tail of the secondary hash bucket is taken as the first elimination sub-slot. For example, the first elimination sub-slot kickout_slot = TailSlot(sec_bucket) = sec_slot3, and sec_bucket is the secondary hash bucket.

[0156] Step S1114: Take the candidate bucket corresponding to the second elimination sub-slot as the second candidate bucket.

[0157] Specifically, the candidate bucket corresponding to the second elimination sub-slot is taken as the second candidate bucket.

[0158] Step S1012: After sequentially circularly shifting all sub-slots in the secondary candidate hash bucket, the candidate hash bucket is overwritten, and the number of exclusions is incremented by one.

[0159] Specifically, after sequentially circularly shifting all sub-slots in the secondary candidate hash bucket, the candidate hash bucket is overwritten, and the number of exclusions is incremented by one, that is, all sub-slots in the secondary hash bucket are moved one position based on the second exclusion sub-slot to obtain a new secondary hash bucket, the new secondary hash bucket is overlaid on the original secondary hash bucket, and the number of exclusions of the current secondary hash bucket is incremented by 1. The secondary candidate hash bucket is the secondary hash bucket.

[0160] Please refer to Figure 6 , Figure 6 is Figure 1 the detailed flowchart of step S1012 in

[0161] As shown in Figure 6 , this step S1012 includes:

[0162] Step S1121: sequentially move all sub-slots in the secondary candidate hash bucket to the tail of the secondary candidate hash bucket by one position until all sub-slots in the secondary candidate hash bucket are shifted.

[0163] Specifically, sequentially move all sub-slots in the secondary candidate hash bucket to the tail of the secondary candidate hash bucket by one position until all sub-slots in the secondary candidate hash bucket are shifted, that is, sequentially move all sub-slots in the secondary hash bucket to the tail of the secondary hash bucket by one position until all sub-slots in the secondary hash bucket are shifted.

[0164] Wherein, the shift of the sub-slot is realized by CyclicShift().

[0165] For example, the secondary hash bucket sec_bucket has four sub-slots {slot3, slot2, slot1, slot0}, and the tail priority exclusion principle is selected, then slot3 is the exclusion sub-slot, and the secondary hash bucket after shifting is CyclicShift(sec_bucket) = {slot2, sec_slot1, slot0, slot3}.

[0166] In the embodiments of the present application, when sequentially circularly shifting all sub-slots in the secondary hash bucket, the second exclusion sub-slot can also be moved in the direction of the head of the secondary hash bucket.

[0167] Step S1013: replace the second candidate bucket with the secondary candidate bucket.

[0168] Wherein, the second candidate bucket is the candidate bucket corresponding to the second exclusion sub-slot

[0169] Specifically, if all the candidate buckets corresponding to the sub-slots in the secondary hash bucket have no free sub-slot, the second candidate bucket is taken as the secondary candidate bucket, that is, the second candidate bucket is determined as the candidate bucket which is not currently required to determine the elimination sub-slot.

[0170] Specifically, all the candidate buckets corresponding to the sub-slots of the second candidate bucket are obtained, it is determined whether there is a free sub-slot in the candidate buckets corresponding to the sub-slots of the second candidate bucket, if there is a free sub-slot, an elimination sub-slot is selected from the second candidate bucket according to the elimination element priority principle, the elements in the elimination sub-slot in the second candidate bucket are moved to the candidate bucket corresponding to the elimination sub-slot in the second candidate bucket, the elements in the second elimination sub-slot are moved to the elimination sub-slot in the second candidate bucket, the first elimination sub-slot is moved to the second elimination sub-slot, and the new element is added to an elimination sub-slot.

[0171] For example, refer to Figure 7 , Figure 7 is another example of inserting a new element into a hash table provided by the embodiment of the application, as shown in Figure 7 , the Figure 7An example diagram of inserting a new element into a hash table in the case that there is no free slot in the primary hash bucket, the secondary hash bucket, the alternative bucket corresponding to the sub-slot of the primary hash bucket, and the alternative bucket corresponding to the sub-slot of the secondary hash bucket. It is assumed that there are five domain segments in the hash table, domain segment 0 to domain segment 4, each domain segment includes four hash buckets, one hash bucket (bucket) has four sub-slots (slots), a total of 80 slots, 20 buckets, bucket 0 to bucket 19, the maximum load (i.e., the number of sub-slots) of each domain segment is 16 slots, H (head) represents the head of the hash bucket, T (tail) represents the tail of the hash bucket, after obtaining the new element key, the primary hash bucket H1 is calculated as bucket 2 and the secondary hash bucket H2 is calculated as bucket 9, there is no free sub-slot in bucket 2 and bucket 9, the alternative bucket corresponding to the sub-slot of the primary hash bucket H1 (i.e., bucket 2) is obtained, the alternative buckets corresponding to all sub-slots {slot 3, slot 2, slot 1, slot 0} of bucket 2 are {bucket 10, bucket 8, bucket 5, bucket 4} respectively, bucket 10, bucket 8, bucket 5, and bucket 4 all have no free sub-slot, the alternative bucket corresponding to the sub-slot of the secondary hash bucket H1 (i.e., bucket 9) is further obtained, the alternative buckets corresponding to all sub-slots {slot 3, slot 2, slot 1, slot 0} of bucket 9 are {bucket 2, bucket 12, bucket 15, bucket 19} respectively, bucket 2, bucket 12, bucket 15, and bucket 19 all have no free sub-slot, according to the priority principle of removing elements, the removal sub-slot corresponding to the secondary hash bucket is determined, for example, the tail priority removal principle is used as the priority principle of removing elements, the removal sub-slot of the secondary hash bucket H1 (i.e., bucket 9) is slot 3, all sub-slots in bucket 9 are circularly shifted in order, the order of all sub-slots in the shifted bucket 9 is {slot 2, slot 1, slot 0, slot 3}, the alternative bucket corresponding to slot 3 is re-obtained, the alternative bucket corresponding to slot 3 in the shifted bucket 9 is bucket 19, bucket 19 has no free sub-slot, the alternative bucket corresponding to each sub-slot of the shifted bucket 19 is obtained, it is found that there is a free sub-slot in the alternative bucket corresponding to the sub-slot of bucket 19, the alternative buckets corresponding to each sub-slot of the shifted bucket 19 are {bucket 13, bucket 11, bucket 18, bucket 7}, bucket 13, bucket 11, bucket 18, and bucket 7 all have free sub-slots, according to the priority principle of adding new elements,The bucket loads of the buckets 13, 11, 18 and 7 are respectively determined as {1, 1, 0, 0}, the domain segment loads are respectively determined as {9, 13, 7, 9}, according to the principle of the largest number of free sub-slots (i.e., the smaller the bucket load), the buckets 18 and 7 are selected, and according to the second priority principle (i.e., the smaller the domain segment load), the bucket 18 is selected, the sub-slot 1 of the bucket 19 corresponding to the bucket 18 is taken as the elimination sub-slot, the element of the slot 1 of the bucket 19 is moved to the free sub-slot of the bucket 18, the element of the slot 3 in the bucket 9 after the shift is moved to the slot 1 of the bucket 19, and the new element key is moved to the slot 3 in the bucket 9 after the shift.

[0172] In the embodiments of the present application, the free sub-slot is found through the elimination element priority principle and the new element priority principle, a loop in the elimination path is avoided, the efficiency of the path of each elimination is greatly improved, and the delay of adding a new element is reduced.

[0173] Step S1014: It is judged whether the elimination times are greater than or equal to the elimination times threshold.

[0174] In the embodiments of the present application, when the insertion of a new element conflicts, the next available sub-slot needs to be found in the hash table to store data. If the elimination times of the sub-slot are not limited, the sub-slot will be repeatedly found and eliminated in the hash table, so that an available sub-slot cannot be found to store data, thereby forming a dead loop. Therefore, when the sub-slot is eliminated, it is also necessary to determine whether the times of the selected sub-slot exceed the maximum elimination times, so as to avoid the problem of a dead loop when a new element is inserted.

[0175] Specifically, before the sub-slot in the hash bucket is shifted, it is necessary to judge whether the elimination times of the sub-slot are greater than or equal to the elimination times threshold. If the elimination times of the sub-slot are less than the elimination times threshold, and there is also no free sub-slot in the current selected candidate bucket, the current candidate is taken as the secondary hash bucket, and the step S1009 is jumped to continue to find the free sub-slot.

[0176] For example, the second candidate bucket has no free sub-slot. In order to find a free sub-slot, the second candidate bucket is taken as the candidate bucket whose elimination sub-slot needs to be determined, i.e., the second candidate bucket is taken as the secondary hash bucket in the step S1009, so as to circularly find the free sub-slot until a free sub-slot is found.

[0177] It should be noted that the secondary hash bucket refers to the currently selected hash bucket, for example, if there is no sub-slot corresponding to the second sub-slot in the second alternative bucket, all sub-slots corresponding to the alternative bucket in the second alternative bucket need to be found to see if there is a free sub-slot, and then the second alternative bucket is used as the currently selected alternative bucket, that is, the second alternative bucket is used as the secondary hash bucket.

[0178] In the embodiment of the application, an element priority principle is used to select a sub-slot from the secondary hash bucket as a first removed sub-slot, and the sub-slots in the secondary hash bucket are circularly shifted, and a sub-slot in the alternative bucket corresponding to the shifted sub-slot of the secondary hash bucket is determined as a second removed sub-slot, the element of the second removed sub-slot is moved to a free position, and the element of the first removed sub-slot is overwritten to the second removed sub-slot, thereby creating space for a new element and inserting the new element into the first removed sub-slot. By circularly shifting and reallocating elements, the space utilization of the hash table can be optimized, and the entire hash table can continue to work without being unable to insert a new element into a certain sub-slot.

[0179] In addition, according to the new element priority principle and the removed element priority principle, the alternative bucket and the removed sub-slot are selected, which can reduce the impact on frequently accessed elements and avoid the problem of dead loop caused by frequently accessing a certain sub-slot, thereby reducing the problem of reduced data insertion efficiency of the hash table caused by conflict processing.

[0180] Please refer to Figure 8 , Figure 8 is a structural schematic diagram of a data insertion system of a hash table provided by the embodiment of the application.

[0181] As Figure 8 shown, the data insertion method system 800 of the hash table includes a hash bucket determination unit 801, a removed element priority judgment unit 802, a new element priority judgment unit 803, a removed element replacement unit 804, a hash table 805, and a removed element random storage 806.

[0182] The hash table includes a primary hash bucket and a secondary hash bucket.

[0183] The hash bucket determination unit 801 is configured to obtain a new element to be inserted, and obtain an address of a primary hash bucket and an address of a secondary hash bucket according to the new element, wherein the primary hash bucket and the secondary hash bucket are used to store data, the primary hash bucket includes a plurality of sub-slots, the secondary hash bucket includes a plurality of sub-slots, each sub-slot in the primary hash bucket corresponds to a primary alternative bucket, and each sub-slot in the secondary hash bucket corresponds to a secondary alternative bucket.

[0184] The element elimination priority judgment unit 802 is configured to determine, based on the address of the primary hash bucket and the address of the secondary hash bucket, that there is no idle sub-slot in the primary hash bucket, the secondary hash bucket, all primary candidate buckets corresponding to the primary hash bucket, and all secondary candidate buckets corresponding to the secondary hash bucket, and determine, according to an element elimination priority principle, a first elimination sub-slot corresponding to the secondary hash bucket, where the first elimination sub-slot is one sub-slot in the secondary hash bucket.

[0185] The element addition priority judgment unit 803 is configured to, based on the first elimination sub-slot, circularly shift all sub-slots in the secondary hash bucket to obtain a shifted secondary hash bucket, obtain a first candidate bucket corresponding to each sub-slot in the shifted secondary hash bucket, and determine, according to an element addition priority principle, a second candidate bucket if there is an idle sub-slot in the first candidate bucket, where the second candidate bucket is one of the plurality of first candidate buckets.

[0186] The element elimination replacement unit 804 is configured to add elements in the first elimination sub-slot to the idle sub-slot in the second candidate bucket, and cover new elements to the first elimination sub-slot.

[0187] The hash table 805 is configured to store new elements.

[0188] The element elimination random storage 806 is configured to record the number of eliminations of each sub-slot in the hash table.

[0189] In the embodiments of the present application, the units of the data insertion system of the hash table cooperate with each other to improve the efficiency of adding data.

[0190] Please refer to Figure 9 , Figure 9 FIG. 1 is a structural schematic diagram of an electronic device provided in the embodiments of the present application.

[0191] As Figure 9 shown, the electronic device 900 includes one or more processors 901 and a memory 902. Among them, Figure 9 In the embodiments of the present application, the processor 901 is taken as an example.

[0192] The processor 901 and the memory 902 can be connected through a bus or other means, Figure 9 In the embodiments of the present application, the connection through the bus is taken as an example.

[0193] The processor 901 is configured to provide calculation and control capabilities to control the electronic device 900 to perform corresponding tasks, for example, to control the electronic device 900 to perform the data insertion method of the hash table in any one of the above method embodiments. The method comprises the following steps: obtaining a new element to be inserted; obtaining an address of a primary hash bucket and an address of a secondary hash bucket according to the new element, wherein the primary hash bucket and the secondary hash bucket are used to store data, the primary hash bucket comprises a plurality of sub-slots, and the secondary hash bucket comprises a plurality of sub-slots; when it is determined that there is no idle sub-slot in the primary hash bucket and the secondary hash bucket based on the address of the primary hash bucket and the address of the secondary hash bucket, obtaining a primary candidate bucket corresponding to each sub-slot of the primary hash bucket; when there is no idle sub-slot in the primary candidate bucket corresponding to each sub-slot in the primary hash bucket, obtaining a secondary candidate bucket corresponding to each sub-slot of the secondary hash bucket; and inserting the new element into the secondary candidate bucket corresponding to one of the sub-slots of the secondary hash bucket according to a new element priority principle.

[0194] The processor 901 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof; and can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above-mentioned PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0195] The memory 902, as a non-transitory computer readable storage medium, can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the data insertion method of the hash table in the embodiments of the present application. The processor 901 can implement the data insertion method of the hash table in any one of the method embodiments described above by running the non-transitory software programs, instructions and modules stored in the memory 902. Specifically, the memory 902 can include a volatile memory (VM), such as a random access memory (RAM); the memory 902 can also include a non-volatile memory (NVM), such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD) or other non-transitory solid-state storage device; and the memory 902 can further include a combination of the above types of memories.

[0196] The memory 902 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 902 can optionally include a memory disposed remotely relative to the processor 901, and these remote memories can be connected to the processor 901 through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.

[0197] One or more modules are stored in the memory 902, and when executed by the one or more processors 901, perform the data insertion method of the hash table in any one of the method embodiments described above, for example, perform the above-described Figure 1 each of the steps shown.

[0198] In the embodiments of the present application, the electronic device 900 can also have a wired or wireless network interface, a keyboard and an input / output interface, etc., to perform input / output, and the electronic device 900 can further include other components for implementing device functions, which are not described herein.

[0199] The embodiments of the present application further provide a non-volatile computer readable storage medium, for example, a memory including program codes, which can be executed by a processor to complete the data insertion method of the hash table in the above embodiments. For example, the non-volatile computer readable storage medium can be a Read-Only Memory (ROM), a Random Access Memory (RAM), a Compact Disc Read-Only Memory (CDROM), a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0200] The embodiments of the present application further provide a computer program product including one or more program codes, which are stored in a non-volatile computer readable storage medium. The processor of the flash device reads the program codes from the non-volatile computer readable storage medium, and the processor executes the program codes to complete the method steps of the data insertion method of the hash table provided in the above embodiments.

[0201] Those skilled in the art can understand that all or part of the steps of the above embodiments can be completed by hardware, or by program codes related hardware, which can be stored in a non-volatile computer readable storage medium, and the storage medium mentioned above can be a Read-Only Memory, a magnetic disk or an optical disk, etc.

[0202] Through the above description of the embodiments, those skilled in the art can clearly understand that the embodiments can be realized by means of software plus a general hardware platform, and of course, can also be realized by hardware. Based on such understanding, the above technical solutions or the part that contributes to the related art can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods of the embodiments or some parts of the embodiments.

[0203] Finally, it should be noted that: the above examples are only used to illustrate the technical solutions of the present application, but not to limit them; under the idea of the present application, the technical features in the above examples or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes of different aspects of the present application as described above. In order to be brief, they are not provided in detail; although the present application has been described in detail with reference to the foregoing examples, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing examples, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for inserting data into a hash table, characterized in that: The hash table includes a primary hash bucket and a secondary hash bucket, and the method includes: Set the culling threshold and get the new element to be inserted; According to the new element, an address of a primary hash bucket and an address of a secondary hash bucket are obtained, a primary hash bucket is obtained according to the primary hash bucket address, and a secondary hash bucket is obtained according to the secondary hash bucket address, wherein the primary hash bucket and the secondary hash bucket each include a plurality of subslots, each subslot corresponds to an alternative bucket, and the subslot is used to store the new element; If none of the primary hash bucket, the secondary hash bucket, and the primary candidate bucket corresponding to the primary hash bucket has an empty subslot, determining whether there is an empty slot in the secondary candidate bucket corresponding to the secondary hash bucket; If there is an idle subslot in the secondary candidate bucket corresponding to the secondary hash bucket, determine the first culled subslot and the first candidate bucket according to the priority principle of the newly added elements, wherein the first culled subslot is one of the multiple subslots in the secondary candidate bucket, and the first candidate bucket is the candidate bucket corresponding to the first culled subslot; Add the element of the first culling sub-slot to the first candidate bucket, insert the new element into the first culling sub-slot, and add successfully; If there is no free subslot in the secondary candidate bucket corresponding to the secondary hash bucket, determining the second culling subslot and the second candidate bucket corresponding to the secondary candidate bucket according to the culling element priority principle, wherein the second culling subslot is a subslot in the secondary candidate bucket, and the second candidate bucket is the candidate bucket corresponding to the second culling subslot; After all sub-slots in the secondary candidate bucket are shifted in sequence, they are covered with the candidate bucket, and the number of eliminations is increased by one; The second candidate bucket is replaced with the secondary candidate bucket, and it is determined whether there is an empty slot in the secondary candidate bucket until there is an idle sub-slot in the candidate bucket corresponding to the secondary candidate bucket or the number of eliminations is equal to the elimination number threshold.

2. The method according to claim 1, characterized in that The hash table includes a plurality of domain segments, each of which includes a plurality of hash buckets, and the priority principle of the newly added elements includes a principle of the largest number of free subslots in the hash bucket, a principle of the largest number of free subslots in the domain segment, and a tail priority principle; The step of determining the first elimination sub-slot and the first candidate bucket according to the priority principle of the newly added elements includes: Determine a third candidate bucket based on the principle that the hash bucket has the largest number of free subslots, wherein the third candidate bucket is the candidate bucket with the largest number of free subslots among all the secondary candidate buckets corresponding to the secondary hash bucket; If the number of the third candidate buckets is greater than the preset number, a fourth candidate bucket is determined based on the principle of the largest number of free subslots in the domain segment, wherein the fourth candidate bucket is a candidate bucket in the third candidate bucket; If the number of the fourth candidate buckets is greater than the preset number, a fifth candidate bucket is determined according to the tail-first principle, and the fifth candidate bucket is used as the first candidate bucket, wherein the fifth candidate bucket is one of the multiple fourth candidate buckets; The subslot in the secondary hash bucket corresponding to the first candidate bucket is used as the first eliminated subslot.

3. The method according to claim 2, characterized in that The element removal priority principle includes a tail-first removal principle or a head-first removal principle; Determining the corresponding second culling sub-slot and the second candidate bucket in the secondary candidate bucket according to the culling element priority principle includes: If the element culling priority principle is the tail-first culling principle, the first subslot at the tail of the secondary hash bucket is used as the second culling subslot; If the element removal priority principle is the head-first removal principle, the first subslot at the head of the secondary hash bucket is used as the second removal subslot; The candidate bucket corresponding to the second rejection sub-slot is used as the second candidate bucket.

4. The method according to claim 2, characterized in that The sequentially shifting of all subslots in the secondary candidate bucket includes: All subslots in the secondary candidate bucket are sequentially moved one position toward the end of the secondary candidate bucket until all subslots in the secondary candidate bucket are completely shifted.

5. The method according to claim 2, characterized in that The method further comprises: If the number of the third candidate buckets is equal to the preset number, the third candidate bucket is used as the first candidate bucket; If the number of the fourth candidate buckets is equal to the preset number, the fourth candidate buckets are used as the first candidate buckets.

6. The method according to claim 1, characterized in that The method further comprises: If there is an idle subslot in the primary hash bucket and there is no idle subslot in the secondary hash bucket, insert the new element into the idle subslot in the primary hash bucket; If there is no free subslot in the primary hash bucket and there is a free subslot in the secondary hash bucket, insert the new element into the free subslot in the secondary hash bucket; If both the primary hash bucket and the secondary hash bucket have free subslots, determine a hash bucket based on the priority principle of newly added elements, and insert the new element into the hash bucket, wherein the hash bucket is one of the primary hash bucket and the secondary hash bucket; If there is no free subslot in the primary hash bucket and no free subslot in the secondary hash bucket, and there is a free subslot in the primary candidate bucket corresponding to the subslot of the primary hash bucket, then insert the new element into the free subslot in the primary candidate bucket corresponding to the subslot of the primary hash bucket; If there is no free subslot in the primary hash bucket, and there is no free subslot in the secondary hash bucket, there is no free subslot in the primary candidate bucket corresponding to the subslot of the primary hash bucket, and there is a free subslot in the secondary candidate bucket corresponding to the subslot of the secondary hash bucket, then the new element is inserted into the free subslot of the secondary candidate bucket corresponding to the subslot of the secondary hash bucket.

7. A data insertion system for a hash table, characterized in that: Applied to the method according to any one of claims 1 to 6, the hash table includes a primary hash bucket and a secondary hash bucket, and the system includes: a hash bucket determination unit, configured to obtain a new element to be inserted, and obtain an address of a primary hash bucket and an address of a secondary hash bucket according to the new element, wherein the primary hash bucket and the secondary hash bucket are used to store data, the primary hash bucket includes a plurality of subslots, the secondary hash bucket includes a plurality of subslots, each subslot in the primary hash bucket corresponds to a primary candidate bucket, and each subslot in the secondary hash bucket corresponds to a secondary candidate bucket; a culling element priority judgment unit, configured to determine, based on the address of the primary hash bucket and the address of the secondary hash bucket, a first culling subslot corresponding to the secondary hash bucket according to a culling element priority principle, when determining that none of the primary hash bucket, the secondary hash bucket, all primary candidate buckets corresponding to the primary hash bucket, and all secondary candidate buckets corresponding to the secondary hash bucket have idle subslots, wherein the first culling subslot is a subslot in the secondary hash bucket; a newly added element priority determination unit, configured to, based on the first eliminated subslot, sequentially shift all subslots in the secondary hash bucket to obtain a shifted secondary hash bucket, obtain a first candidate bucket corresponding to each subslot in the shifted secondary hash bucket, and if there is an idle subslot in the first candidate bucket, determine a second candidate bucket according to a newly added element priority principle, wherein the second candidate bucket is one of the first candidate buckets; The culling and replacing unit is configured to add the element in the first culling subslot to an idle subslot in the second candidate bucket, and overwrite the new element to the first culling subslot.

8. The system according to claim 7, characterized in that The system further comprises: A hash table, used to store the new element; The culled element random access memory is used to record the number of culled times for each subslot in the hash table.

9. An electronic device, characterized in that: include: at least one processor, and a memory communicatively coupled to the at least one processor, wherein: The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the data insertion method for the hash table as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • In-memory hash sorting construction method based on novel memory

    CN113254720A

  • Write optimization extensible Hash index structure based on nonvolatile memory and insertion, refreshing and deletion methods

    CN113342706A