A method for quickly querying market code memory addresses based on hash algorithm
By using the fast query method of quotation code memory address based on hash algorithm in the financial trading system, the problems of query delay and low memory utilization in the existing technology are solved, the effect of fast query and update is achieved, and the memory utilization is improved.
Patent Information
- Application Number
- CN202111530823.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2025-05-20
- Estimated Expiration
- 2041-12-14
AI Technical Summary
In financial trading systems, it is difficult for the existing technology to quickly query and update the memory address corresponding to the market code, resulting in uncertain query delay and low memory utilization.
The fast query method of quotation code memory address based on hash algorithm is adopted. By initializing a dual-port random access memory, and using hash operations to convert the quotation code into memory addresses, quickly querying and updating is achieved.
The hash algorithm reduces memory footprint, improves memory utilization, and achieves the effect of fast query and updates, meeting the high-speed needs of the financial transaction field.
Smart Images

Figure CN114281711B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a method for quickly querying the memory address of a market quotation code based on a hash algorithm, belonging to the technical field of data processing. Background Art
[0002] In a financial trading system, the original market quotation data generated by an exchange is divided into full-volume data and incremental data. The data that must ultimately be provided to users after being processed by the market quotation system must be full-volume data, which requires the supplementation of incremental data. Therefore, the full-volume trading data of each stock needs to be stored in the system memory and the data at the corresponding position in the memory can be updated according to the latest field information in the incremental data. In order to accurately update the data in the memory, a certain relationship needs to be established between the offset of the data address in the memory and the market quotation code. The general approach is to write the corresponding market quotation code at the head address of each memory segment and use a sequential query method. This method needs to traverse all the head addresses before the target address, so there are problems of uncertain query delay and too long query time. There is also a method of binary search. Although it can improve the query speed to a certain extent, in today's financial trading field where speed is prioritized, it still cannot meet the needs of customers. If a one-to-one correspondence is established between the market quotation code with a bit width of m and 2m memory low and middle ends in the memory, the speed of data query, reading and writing can be improved. However, the daily market quotation code volume of data trading is only a small part and does not reach 2m, which will cause a great waste of memory and greatly reduce the memory utilization rate.
[0003] Therefore, a method that can both meet the query speed and does not occupy too much storage space is needed for data query, reading and writing of market quotation codes. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a method for quickly querying the memory address of a market quotation code that can both meet the query speed and does not occupy too much storage space.
[0005] To solve the above technical problem, the technical solution proposed by the present invention is: A method for quickly querying the memory address of a market quotation code based on a hash algorithm, which performs the following steps:
[0006] 1) Initial establishment of a hash table;
[0007] 1-1) Instantiate a dual-port random access memory for storing market quotation codes;
[0008] 1-2) Receive the market quotation code and confirm whether the initialization is completed. If completed, go to step 1-7); if not completed, go to step 1-3);
[0009] 1-3) Perform a hash operation on the market code or the value obtained by adding x times a constant to the market code, and use the operation result as the retrieval address of the random access memory, and read the data in the random access memory corresponding to the retrieval address;
[0010] 1-4) If the data read in step 1-3) is zero, then store the market code in step 1-3) under this retrieval address, and proceed to step 1-6);
[0011] 1-5) If the data read in step 1-3) is not zero, then add x times a constant to the market code in step 1-3), and jump to 1-3);
[0012] 1-6) Notify the host computer that the initialization of the current market code is completed, and proceed to step 1-2);
[0013] 1-7) Initialization ends;
[0014] 2) Query of the market code address;
[0015] 2-1) Receive the market code;
[0016] 2-2) Perform a hash operation on the market code in step 2-1) or the value obtained by adding x times a constant to the market code in step 2-1), and use the operation result as the retrieval address of the random access memory, and read the data in the random access memory corresponding to the retrieval address;
[0017] 2-3) If the data read in step 2-2) is equal to the market code in step 2-1), then return hash_r * STEP_SIZE + BASE_ADDR as the starting address of the market code data in the random access memory in step 2-1), and continue to execute in step 2-1); if the data read in step 2-2) is not equal to the market code in step 2-1), then add x times a constant to this market code, and continue to execute in step 2-2).
[0018] Wherein, x is the number of times of hash operation performed on the market code, STEP_SIZE is the storage depth of one market data, BASE_ADDR is the base address of the market data segment, and hash_r is the result of the hash operation.
[0019] A further improvement of the above solution is: In step 1-1), instantiate a dual-port random access memory with a bit width of m and a depth of 2n to store the initialized market code; wherein, m > n, m is the width of the market code, and n is the address bit width of the random access memory.
[0020] A further improvement of the above solution is: The bit width of hash_r is n.
[0021] The beneficial effects of the present invention are as follows: By performing data bit-width transformation through the hash algorithm, the data bit-width is reduced, the occupied space of the memory is decreased, and the memory utilization rate is improved. Description of the Drawings
[0022] Figure 1 It is a logical operation block diagram of a method for quickly querying the memory address of a market quotation code based on the hash algorithm according to an embodiment of the present invention. Detailed Embodiment
[0023] Embodiment 1
[0024] A method for quickly querying the memory address of a market quotation code based on the hash algorithm in this embodiment, and its logical block diagram is as Figure 1 shown, including an address mapping module, a hash algorithm module, a hash table maintenance module, and an address query module.
[0025] The implementation of this method has two major steps: the initialization and establishment of the hash table and the query of the memory address corresponding to the current market quotation code.
[0026] 1. Initialization and establishment of the hash table:
[0027] (1) Instantiate a dual-port RAM (random access memory) with a bit-width of m and a depth of 2n to store the initialized market quotation code; (m > n, m is the width of the market quotation code, and n is the address bit-width of the RAM).
[0028] (2) Receive the market quotation code sent by the upper computer. And determine whether the initialization is completed. If the initialization is completed, jump to (7); otherwise, jump to (3) to continue execution.
[0029] (3) Send the market quotation code or the value of the market quotation code plus x times the constant value to the hash operation module for calculation. The result of the hash operation, hash_r (with a bit-width of n), is used as the RAM retrieval address, and data is read from the RAM. (x is the number of times of performing the hash operation on the current market quotation code)
[0030] (4) If the data read from the RAM in (3) is zero, it means that the current RAM address is empty. Then store the current market quotation code under this retrieval address and jump to (6) to continue execution.
[0031] (5) If the data read from the RAM in (3) is not zero, it means that the current RAM address has stored other market quotation codes. Then add x times the constant value to this market quotation code and jump to (3) to execute.
[0032] (6) Notify the upper computer that the initialization of the current market quotation code is completed. Jump to (2) to continue execution.
[0033] (7) Initialization completed.
[0034] 2. Query the memory address corresponding to the current market code, receive the market code data sent by the real-time market analysis module, and return the starting address of the current market code data in the memory after the query is completed. The specific implementation is as follows:
[0035] (1) Receive the market code sent by the real-time market analysis module.
[0036] (2) Send the market code or the value of the market code plus x times the constant value to the hash operation module for calculation. The result of the hash operation, hash_r (bit width is n), is used as the RAM retrieval address, and data is read from the RAM.
[0037] (3) If the data read from the RAM in (2) is equal to the current market code, it indicates that the query is successful. Then, return hash_r * STEP_SIZE + BASE_ADDR as the starting address of the current market code data in the memory, and jump to (1) to continue execution. Otherwise, add x times the constant value to the market code and jump to (2) to continue execution.
[0038] Among them, STEP_SIZE is the storage depth of a market data, and BASE_ADDR is the base address of the market data segment.
[0039] The present invention is not limited to the specific technical solutions described in the above embodiments. In addition to the above embodiments, the present invention may also have other implementation manners. For those skilled in the art, any technical solutions formed by making any modifications, equivalent replacements, improvements, etc. within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for quickly querying the memory address of a market code based on a hash algorithm, characterized in that: Follow these steps: 1) Initialization of hash table; 1-1) Instantiate a dual-port random access memory with a bit width of m and a depth of 2n to store the initialized market code; where m>n, m is the width of the market code, and n is the address bit width of the random access memory; 1-2) Receive the market code and confirm whether the initialization has been completed. If it is completed, go to step 1-7. If it is not completed, go to step 1-3); 1-3) performing a hash operation on the market code or the market code plus a value of a constant times x, using the operation result as a search address of the random access memory, and reading data in the random access memory corresponding to the search address; 1-4) If the data read in step 1-3) is zero, the market code in step 1-3) is stored under the search address, and then go to step 1-6); 1-5) If the data read in step 1-3) is not zero, add x times the constant to the market code in step 1-3) and jump to 1-3); 1-6) Notify the host computer that the current market code initialization is complete, go to step 1-2); 1-7) Initialization is completed; 2) Query of market code address; 2-1) Receive the market code; 2-2) performing a hash operation on the market code of step 2-1) or the market code of step 2-1) plus a value of x times a constant, using the operation result as the search address of the random access memory, and reading the data in the random access memory corresponding to the search address; 2-3) If the data read in step 2-2) is equal to the market code in step 2-1), then hash_r*STEP_SIZE+BASE_ADDR is returned as the first address of the market code data in step 2-1) in the random access memory, and the execution continues to step 2-1); if the data read in step 2-2) is not equal to the market code in step 2-1), then the market code is multiplied by a constant x, and the execution continues to step 2-2); Among them, x is the number of times the market code performs hash operation, STEP_SIZE is the storage depth of a market data, BASE_ADDR is the base address of the market data segment, hash_r is the result of hash operation, and the bit width of hash_r is n.
Citation Information
Patent Citations
Apparatus and method for hash table storage, searching
CN101604337A
Method for optimizing performance of interface functions in JNI mechanism based on Dalvik virtual machine
CN104035809A