A data storage method for scheduled lookup

CN118747171BActive Publication Date: 2026-09-01LINKER +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410897280.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-05
Publication Date
2026-09-01
Estimated Expiration
2044-07-05

AI Technical Summary

Technical Problem

[0003]本发明主要是解决现有技术所存在的定时计划查找速度慢、时效性不足等的技术问题,提供一种高效、可靠的针对定时计划查找的数据存储方法

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118747171B_ABST
    Figure CN118747171B_ABST
Patent Text Reader

Abstract

This invention discloses a data storage method for searching scheduled plans. Each scheduled plan is mapped to a hash value using a hash function and stored in a hash table. The hash function specifically includes the following steps: setting the hash value to 0; calculating the hash contribution of year, month, day, hour, minute, and second one by one and adding it to the hash value; shifting the first hash value right by 16 bits to obtain the second hash value; performing an XOR operation on the first and second hash values ​​to obtain the third hash value; performing a multiplication operation on the third hash value using a specific multiplier to obtain the fourth hash value; shifting the fourth hash value right by 16 bits to obtain the fifth hash value; performing an XOR operation on the fifth and fourth hash values ​​to obtain the sixth hash value; using a bitmask to ensure that the hash value is within the range of the hash table size; outputting the final hash value and inserting it into the hash table. This solution has significant advantages in performance and efficiency, and is suitable for storing and searching scheduled plans.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer data storage, and in particular to a data storage method for scheduled lookups. Background Technology

[0002] In modern production and daily life, the execution of various scheduled plans is frequently involved. The execution of these plans requires a high degree of time accuracy. When the amount of data is large, the search operation can be very time-consuming and resource-intensive, and there may even be situations where the plan fails to be executed on time due to untimely searches. Summary of the Invention

[0003] This invention primarily addresses the technical problems of slow search speed and insufficient timeliness in existing technologies for scheduled plans, and provides an efficient and reliable data storage method for searching scheduled plans.

[0004] The present invention addresses the aforementioned technical problems primarily through the following technical solution: a data storage method for searching scheduled plans, wherein the time of the scheduled plan includes year, month, day, hour, minute, and second, and each scheduled plan is mapped to a hash value and stored in a hash table using a hash function. The hash function specifically includes the following steps: S1. Initialize hash value: Set the hash value to 0; S2. Calculate the hash contribution of the year: multiply the year by the first prime number and add it to the hash value; S3. Calculate the hash contribution of the month: multiply the month by the second prime number and add it to the hash value; S4. Calculate the hash contribution of the date: Multiply the date by the third prime number and add it to the hash value; S5. Calculate the hash contribution of the hour: Multiply the hour by the fourth prime number and add it to the hash value; S6. Calculate the hash contribution of the minute: Multiply the minute by the fifth prime number and add it to the hash value; S7. Calculate the hash contribution of seconds: Multiply the seconds by the sixth prime number and add it to the hash value to get the first hash value; S8. Mixed hash value: Shift the first hash value right by 16 bits to obtain the second hash value, and perform an XOR operation on the first hash value and the second hash value to obtain the third hash value; S9. Perform a multiplication operation between a specific multiplier and the third hash value to obtain the fourth hash value; S10. Shift the fourth hash value to the right by 16 bits to obtain the fifth hash value, and XOR the fifth hash value with the fourth hash value to obtain the sixth hash value. S11. Adjust hash values ​​to be within the range of the table size: Use a bitmask to ensure that hash values ​​are within the range of the hash table size; S12, Return Hash Value: Output the final hash value and insert it into the hash table.

[0005] Preferably, the first prime number is 1231, the second is 1229, the third is 1237, the fourth is 1249, the fifth is 1259, and the sixth is 1277. These six prime numbers can ensure good uniformity and coverage of the results while also minimizing computational complexity.

[0006] Preferably, in step S11, the bitmask is specifically: performing a bitwise AND operation between the sixth hash value and the mask, the mask is 2 to the power of N minus 1, and the size of the current hash table is 2 to the power of N.

[0007] In this scheme, the hash table size is a power of 2, so a bitmask can be used instead of modulo. The bitwise AND operation limits the hash value to the range of 0 to the hash table size - 1; essentially, it's a modulo operation on the hash table size, but the bitwise AND operation is faster.

[0008] Preferably, the specific multiplier in step S9 is 0x45d9f3b. 0x45d9f3b is chosen as the multiplier because it is a prime number close to the golden ratio, and this number has good distribution characteristics in binary representation. After multiplying by this number, the bits of the hash value can be further mixed through bit shifting and XOR operations, making the final hash value more random and uniform.

[0009] Preferably, the size of the hash table is dynamically adjusted in the following way: A1. Monitor load factor: Calculate the current load factor after each insertion operation; A2. Expanding or shrinking: When the load factor exceeds the upper limit threshold, create a new hash table with a size twice that of the original table; when the load factor is less than the lower limit threshold, create a new hash table with a size half that of the original table. A3. Rehashing: Recalculate the hash value of all elements in the original table using a new hash function and insert them into the new hash table.

[0010] The load factor is a metric used to measure how full a hash table is. It is calculated by dividing the actual number of elements stored in the hash table by the total capacity of the hash table. This ratio reflects the efficiency of the hash table's use.

[0011] For example, if a hash table has 100 slots and 80 elements are already stored, then the load factor is 80 divided by 100, which is 0.8.

[0012] Preferably, the upper threshold is 0.75 and the lower threshold is 0.25.

[0013] The hash function of this invention uses bitwise operations and multiplication to generate hash values. Shifting the input key (right-shifted by 16 bits) and XORing it helps to mix the input bits, making the hash values ​​more evenly distributed. Multiplication is performed using a specific multiplier (0x45d9f3b), which helps map different inputs to different hash values. This method is repeated over six time parameters, increasing the randomness and evenness of the hash values. Finally, the result is right-shifted by 16 bits and XORed with itself to ensure that the lower 16 bits of the hash value contain information from the higher 16 bits, thereby increasing the evenness of the distribution. The final hash value is modulo the hash table's capacity to ensure that the hash value falls within the hash table's index range. This hash function design helps to evenly distribute different keys across the hash table, reducing the possibility of collisions.

[0014] When the load factor of the hash table exceeds a preset threshold (e.g., 0.75), the algorithm dynamically increases the hash table's capacity. The benefit of this is that by increasing the hash table size, the number of elements at each position can be reduced, thus improving the uniformity of distribution. After resizing, all existing elements need to have their hash values ​​recalculated and be reinserted into the new hash table, which helps to redistribute elements more evenly across a larger space. This mechanism of dynamically adjusting the hash table size helps maintain the hash table's uniformity and distribution, ensuring high performance even with varying data volumes.

[0015] The design of the hash function and the mechanism for dynamically adjusting the size of the hash table work together to improve the uniformity and distribution of the hash table, thereby optimizing the performance of the hash table.

[0016] The substantial effect of this invention is that it has significant advantages in performance and efficiency, and can provide a more efficient and reliable solution for data storage and retrieval. Attached Figure Description

[0017] Figure 1 This is a flowchart of a hash function calculation method according to the present invention. Detailed Implementation

[0018] The technical solution of the present invention will be further described in detail below through embodiments and in conjunction with the accompanying drawings.

[0019] Example: This example describes a data storage method for searching scheduled plans. The time of the scheduled plan includes year, month, day, hour, minute, and second. Each scheduled plan is mapped to a hash value using a hash function and stored in a hash table, such as... Figure 1 As shown, a hash function specifically includes the following steps: S1. Initialize hash value: Set the hash value to 0; S2. Calculate the hash contribution of the year: multiply the year by the prime number 1231 and add it to the hash value; S3. Calculate the hash contribution of the month: Multiply the month by the prime number 1229 and add it to the hash value; S4. Calculate the hash contribution of the date: Multiply the date by the prime number 1237 and add it to the hash value; S5. Calculate the hash contribution of the hour: Multiply the hour by the prime number 1249 and add it to the hash value; S6. Calculate the hash contribution of the minute: Multiply the minute by the prime number 1259 and add it to the hash value; S7. Calculate the hash contribution of seconds: Multiply the second by the prime number 1277 and add it to the hash value to get the first hash value; multiply each time unit (year, month, day, hour, minute, second) by a different prime number, which helps to maintain the randomness and uniformity of the hash value distribution; S8. Mixed Hash Value: The first hash value is right-shifted by 16 bits to obtain the second hash value, and the first and second hash values ​​are XORed to obtain the third hash value; XOR and right shift operations are used to mix the high and low bits of the hash value to further improve the uniformity of the distribution. S9. Perform a multiplication operation between a specific multiplier and the third hash value to obtain the fourth hash value; S10. Shift the fourth hash value to the right by 16 bits to obtain the fifth hash value, and XOR the fifth hash value with the fourth hash value to obtain the sixth hash value. S11. Adjust hash values ​​to be within the range of the table size: Use a bitmask to ensure that hash values ​​are within the range of the hash table size; S12, Return Hash Value: Output the final hash value and insert it into the hash table.

[0020] In step S11, the bitmask is specifically: performing a bitwise AND operation between the sixth hash value and the mask, the mask is 2 to the power of N minus 1, and the size of the current hash table is 2 to the power of N.

[0021] The specific multiplier in step S9 is 0x45d9f3b. 0x45d9f3b is chosen as the multiplier because it is a prime number close to the golden ratio, and this number has good distribution characteristics in binary representation. After multiplying by this number, the bits of the hash value can be further mixed through bit shifting and XOR operations, making the final hash value more random and uniform.

[0022] This solution also includes a method for dynamically adjusting the hash table size, which is achieved by dynamically adjusting the hash table size in the following ways: A1. Monitor load factor: Calculate the current load factor after each insertion operation; A2. Expanding or shrinking: When the load factor exceeds the upper limit threshold, create a new hash table with a size twice that of the original table; when the load factor is less than the lower limit threshold, create a new hash table with a size half that of the original table. A3. Rehashing: Recalculate the hash value of all elements in the original table using a new hash function and insert them into the new hash table.

[0023] The load factor is a metric used to measure how full a hash table is. It's calculated by dividing the number of elements actually stored in the hash table by its total capacity. This ratio reflects the efficiency of the hash table's usage. For example, if a hash table has 100 slots and 80 elements are already stored, the load factor is 80 divided by 100, resulting in 0.8. Dynamic resizing strategies, based on real-time data statistics and analysis, can maximize hash table efficiency, reduce hash collisions, and improve query performance while ensuring data integrity.

[0024] The upper threshold is 0.75 and the lower threshold is 0.25.

[0025] The hash function of this invention uses bitwise operations and multiplication to generate hash values. Shifting the input key (right-shifted by 16 bits) and XORing it helps to mix the input bits, making the hash values ​​more evenly distributed. Multiplication is performed using a specific multiplier (0x45d9f3b), which helps map different inputs to different hash values. This method is repeated over six time parameters, increasing the randomness and evenness of the hash values. Finally, the result is right-shifted by 16 bits and XORed with itself to ensure that the lower 16 bits of the hash value contain information from the higher 16 bits, thereby increasing the evenness of the distribution. The final hash value is modulo the hash table's capacity to ensure that the hash value falls within the hash table's index range. This hash function design helps to evenly distribute different keys across the hash table, reducing the possibility of collisions.

[0026] When the load factor of the hash table exceeds a preset threshold (e.g., 0.75), the algorithm dynamically increases the hash table's capacity. The benefit of this is that by increasing the hash table size, the number of elements at each position can be reduced, thus improving the uniformity of distribution. After resizing, all existing elements need to have their hash values ​​recalculated and be reinserted into the new hash table, which helps to redistribute elements more evenly across a larger space. This mechanism of dynamically adjusting the hash table size helps maintain the hash table's uniformity and distribution, ensuring high performance even with varying data volumes.

[0027] The design of the hash function and the mechanism for dynamically adjusting the size of the hash table work together to improve the uniformity and distribution of the hash table, thereby optimizing the performance of the hash table.

[0028] The specific embodiments described herein are merely illustrative of the spirit of the invention. Those skilled in the art to which this invention pertains may make various modifications or additions to the described specific embodiments or use similar methods to substitute them, without departing from the spirit of the invention or exceeding the scope defined by the appended claims.

[0029] Although this paper makes frequent use of terms such as hash contribution, XOR, and bitmask, the possibility of using other terms is not excluded. These terms are used merely for the convenience of describing and explaining the essence of this invention; interpreting them as any additional limitation would contradict the spirit of this invention.

Claims

1. A data storage method for scheduled lookup, characterized in that, The time frame for each scheduled event includes the year, month, day, hour, minute, and second. Each scheduled event is mapped to a hash value using a hash function and stored in a hash table. The hash function specifically includes the following steps: S1. Initialize hash value: Set the hash value to 0; S2. Calculate the hash contribution of the year: multiply the year by the first prime number and add it to the hash value; S3. Calculate the hash contribution of the month: multiply the month by the second prime number and add it to the hash value; S4. Calculate the hash contribution of the date: Multiply the date by the third prime number and add it to the hash value; S5. Calculate the hash contribution of the hour: Multiply the hour by the fourth prime number and add it to the hash value; S6. Calculate the hash contribution of the minute: Multiply the minute by the fifth prime number and add it to the hash value; S7. Calculate the hash contribution of seconds: Multiply the seconds by the sixth prime number and add it to the hash value to get the first hash value; S8. Mixed hash value: Shift the first hash value right by 16 bits to obtain the second hash value, and perform an XOR operation on the first hash value and the second hash value to obtain the third hash value; S9. Perform a multiplication operation between a specific multiplier and the third hash value to obtain the fourth hash value; S10. Shift the fourth hash value to the right by 16 bits to obtain the fifth hash value, and XOR the fifth hash value with the fourth hash value to obtain the sixth hash value. S11. Adjust hash values ​​to be within the range of the table size: Use a bitmask to ensure that hash values ​​are within the range of the hash table size; S12, Return Hash Value: Output the final hash value and insert it into the hash table; The first prime number is 1231, the second prime number is 1229, the third prime number is 1237, the fourth prime number is 1249, the fifth prime number is 1259, and the sixth prime number is 1277.

2. The data storage method for scheduled lookup according to claim 1, characterized in that, In step S11, the bitmask is specifically: performing a bitwise AND operation between the sixth hash value and the mask, the mask is 2 to the power of N minus 1, and the size of the current hash table is 2 to the power of N.

3. A data storage method for scheduled lookup according to claim 1 or 2, characterized in that, The specific multiplier in step S9 is 0x45d9f3b.

4. The data storage method for scheduled lookup according to claim 1, characterized in that, The size of the hash table is dynamically adjusted in the following ways: A1. Monitor load factor: Calculate the current load factor after each insertion operation; A2. Expanding or shrinking: When the load factor exceeds the upper limit threshold, create a new hash table with a size twice that of the original table; when the load factor is less than the lower limit threshold, create a new hash table with a size half that of the original table. A3. Rehashing: Recalculate the hash value of all elements in the original table using a new hash function and insert them into the new hash table.

5. The data storage method for scheduled lookup according to claim 4, characterized in that, The upper threshold is 0.75 and the lower threshold is 0.25.

Citation Information

Patent Citations

  • Processing method and processing device of timer

    CN103106222A

  • Hash search method for reducing hash collision

    CN104504038A