Hash table look-up test method and device, electronic equipment and storage medium
By generating an index array and storing hash keywords to index addresses, and calculating the index address according to the hash polynomial and required conditions, the difficult problem of controlling the hit and conflict probabilities in hash table lookup testing is solved, and efficient specific index testing is achieved.
Patent Information
- Application Number
- CN202510790968.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-13
- Publication Date
- 2025-09-26
AI Technical Summary
In existing hash table lookup tests, it is difficult to accurately control the hit and conflict probabilities, and specific indexes cannot be implemented, resulting in low test efficiency.
By generating an index array, storing hash keywords to index addresses, and calculating the index addresses of hash keywords based on preset hash polynomials and required conditions, ensuring that the index addresses are stored after meeting specific conditions, precise control of hit and conflict probabilities is achieved.
The efficiency of hash table lookup testing is improved, and the hit and conflict probabilities can be accurately controlled to implement testing of specific index addresses.
Smart Images

Figure CN120705040A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of testing technology, and in particular to a hash table lookup testing method, device, electronic device, and storage medium. Background Art
[0002] Currently, a hash algorithm is often used to perform table entry lookups. The hash algorithm can generate a corresponding hash keyword from the message, and then obtain the corresponding index address through the operation of the hash polynomial, and then perform a table lookup through the index address to obtain the final search content.
[0003] In the related art, when performing hash table lookup simulation tests, randomly generated hash keywords are often used for table lookup tests. However, this method is difficult to control the hit and conflict probabilities, so a large number of regression tests are often required, resulting in low test efficiency. In addition, since the addressing space of the test table items is very large, for example, ranging from thousands to tens of millions, it is impossible to implement specific indexes in this process, such as only indexing even addresses. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide a hash table lookup test method, device, electronic device and storage medium to accurately control the hit probability during the hash table lookup test, improve the test efficiency and realize specific indexing.
[0005] In order to achieve the above objectives, the technical solutions adopted in the embodiments of the present application are as follows:
[0006] In a first aspect, the present application provides a hash table lookup test method, which is applied to an electronic device, wherein the electronic device stores an index array, the index array including multiple index addresses, each index address corresponding to a hash keyword, and the method includes:
[0007] Receive a test instruction sent by a user; the test instruction includes a target index address to be indexed; determine a corresponding target hash keyword based on the target index address and the index array, and input the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table entry in the test module; wherein the test table entry is consistent with the index array.
[0008] In an optional implementation manner, before receiving the test instruction sent by the user, the method further includes:
[0009] Generating the index array according to a preset hash polynomial;
[0010] For each hash keyword stored in the index array, the hash keyword is stored in the test table entry of the module to be tested according to the index address corresponding to the hash keyword.
[0011] In an optional embodiment, generating the index array according to a preset hash polynomial includes:
[0012] Establishing an initial storage array according to the number of the hash polynomials and the address space corresponding to the test table entry;
[0013] Randomly generate the hash keyword, and calculate the index address corresponding to the hash keyword according to the hash polynomial and preset requirement conditions, and store the hash keyword at the index address if the index address meets the preset condition;
[0014] Determining whether there is an index address in the initial storage array that does not store the hash keyword;
[0015] If an index address not storing the hash keyword exists in the initial storage array, the steps of randomly generating the hash keyword, calculating the index address corresponding to the hash keyword according to the hash polynomial and a preset requirement, and storing the hash keyword at the index address if the index address meets the preset condition are re-executed until no index address not storing the hash keyword exists in the initial storage array;
[0016] If the index address not storing the hash keyword does not exist in the initial storage array, the initial storage array is determined as the storage array.
[0017] In an optional embodiment, the randomly generating the hash keyword, calculating an index address corresponding to the hash keyword according to the hash polynomial and a preset requirement, and storing the hash keyword at the index address if the index address meets the preset condition, includes:
[0018] Randomly generate a hash keyword each time;
[0019] Determine a target hash polynomial from the plurality of hash polynomials according to the requirement, and calculate a corresponding index address according to the target hash polynomial and the hash keyword;
[0020] Determine whether other hash keywords are already stored at the index address;
[0021] If other hash keywords are already stored at the index address, a new hash keyword is randomly generated, and a new index address is calculated according to the target hash polynomial and the new hash keyword, until no other hash keywords are stored at the new index address;
[0022] If the other hash keyword is not stored at the index address, the hash keyword is stored at the index address.
[0023] In a second aspect, the present application provides a hash table lookup test device, which is applied to an electronic device, wherein the electronic device stores an index array, the index array includes multiple index addresses, and each index address stores a corresponding hash keyword, the device comprising:
[0024] A receiving module, configured to receive a test instruction sent by a user; the test instruction includes a target index address to be indexed;
[0025] A test module is used to determine the corresponding target hash keyword based on the target index address and the index array, and input the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table entry in the test module; wherein the test table entry is consistent with the index array.
[0026] In an optional embodiment, a generation module is further included;
[0027] The generating module is configured to generate the index array according to a preset hash polynomial; and for each hash keyword stored in the index array, store the hash keyword in a test entry of the module to be tested according to an index address corresponding to the hash keyword.
[0028] In an optional embodiment, the generation module is further used to establish an initial storage array based on the number of hash polynomials and the address space corresponding to the test table entry; randomly generate the hash keyword, and calculate the index address corresponding to the hash keyword based on the hash polynomial and preset requirement conditions, and store the hash keyword at the index address if the index address meets the preset condition; determine whether there is an index address in the initial storage array that does not store the hash keyword; if there is an index address in the initial storage array that does not store the hash keyword, re-execute the steps of randomly generating the hash keyword, calculating the index address corresponding to the hash keyword based on the hash polynomial and preset requirement conditions, and storing the hash keyword at the index address if the index address meets the preset condition, until there is no index address in the initial storage array that does not store the hash keyword; if there is no index address in the initial storage array that does not store the hash keyword, determine the initial storage array as the storage array.
[0029] In an optional embodiment, the generation module is further used to randomly generate one hash keyword each time; determine a target hash polynomial from the multiple hash polynomials according to the requirement conditions, and calculate a corresponding index address according to the target hash polynomial and the hash keyword; determine whether other hash keywords have been stored at the index address; if other hash keywords have been stored at the index address, randomly generate a new hash keyword again, and calculate a new index address according to the target hash polynomial and the new hash keyword until the other hash keywords are not stored at the new index address; if the other hash keywords are not stored at the index address, store the hash keyword at the index address.
[0030] In a third aspect, the present application provides an electronic device comprising a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the method described in any one of the aforementioned embodiments.
[0031] In a fourth aspect, the present application provides a storage medium having a computer program stored thereon, which implements the method described in any one of the aforementioned embodiments when the computer program is executed by a processor.
[0032] The embodiments of the present application provide a hash table lookup test method, device, electronic device, and storage medium. An index array is stored in the electronic device, and a hash keyword is stored at each index address in the index array. When performing a test, the electronic device can determine the target hash keyword from the storage array according to the target index address that the user wants to hit, and send the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table item. Therefore, the hit and conflict probabilities can be accurately controlled, the test efficiency can be improved, and specific indexing for the target index address can be achieved.
[0033] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0035] Figure 1 A block diagram of an electronic device provided in an embodiment of the present application is shown;
[0036] Figure 2 A schematic diagram of a flow chart of a hash table lookup test method provided in an embodiment of the present application is shown;
[0037] Figure 3 Another flow chart of the hash table lookup test method provided in an embodiment of the present application is shown;
[0038] Figure 4 A functional module diagram of a hash table lookup test device provided in an embodiment of the present application is shown;
[0039] Figure 5 Another functional module diagram of the hash table lookup test device provided in an embodiment of the present application is shown.
[0040] Icon: 100 - memory; 110 - processor; 120 - communication module; 200 - receiving module; 210 - testing module; 220 - generation module. DETAILED DESCRIPTION
[0041] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Generally, the components of the embodiments of the present application described and shown in the drawings herein can be arranged and designed in various different configurations.
[0042] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for protection, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making any creative efforts shall fall within the scope of protection of the present application.
[0043] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0044] Currently, hash algorithms are often used to perform table lookups. These algorithms generate a hash keyword from a message, then calculate a hash polynomial to obtain the corresponding index address. This index address is then used to perform a table lookup to obtain the final search result. For example, hash algorithms can be used to perform table lookups during the design of switching chips.
[0045] In the related art, table lookup testing can generally be performed in the following ways: 1. Generate a random hash keyword and input it into the module to be tested for testing; 2. Establish a dynamic array containing D random hash keywords, and divide the dynamic array into 2N-1 continuous hash keyword segments according to the number of hash polynomials N, and each hash keyword segment does not overlap, and then the keywords in each hash keyword segment are allocated to the hash memory according to the given rules, so that when the hash keywords selected from the keyword dynamic array are input as test stimuli into the module to be tested, it can be guaranteed that at least one will hit, and finally the keywords in the keyword dynamic array are input as test stimuli into the module to be tested for testing.
[0046] However, all of the above methods have certain problems. For the first method, due to the particularity of the hash algorithm, the randomly generated hash keyword has only a very small probability of hitting the test table item. Therefore, in order to ensure that all index addresses can be hit, a large number of regression tests are required, which is inefficient. In addition, since the addressing space of the test table items is very large, ranging from thousands to hundreds of thousands, it is difficult to index all the table item spaces or accurately control specific index behaviors during the test process, such as addressing from 1000 to 2000, or only indexing even addresses.
[0047] As for the second method, since this scheme cannot guarantee that all addresses or specified addresses in the hash memory can cover the hash keyword when the hash keyword is allocated to the hash memory according to the hash polynomial, it can only increase the probability of hash keyword hits, and cannot accurately control the probability of hits and conflicts at specific addresses.
[0048] Based on this, embodiments of the present application provide a hash table lookup test method, device, electronic device, and storage medium to solve the above problems.
[0049] Figure 1 For a block diagram of an electronic device provided in an embodiment of the present application, see Figure 1 The electronic device includes a memory 100, a processor 110, and a communication module 120. The memory 100, processor 110, and communication module 120 are electrically connected to each other directly or indirectly to enable data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines.
[0050] The memory 100 is used to store computer programs or data that can be executed by the processor. The memory 100 can be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0051] The processor 110 is used to read / write data or computer programs stored in the memory and execute the computer program to implement the hash table lookup test method provided in the embodiment of the present application.
[0052] The communication module 120 is used to establish a communication connection between the electronic device and other communication terminals through a network, and to send and receive data through the network.
[0053] It should be understood that Figure 1 The structure shown is only a schematic diagram of the structure of the electronic device. The electronic device may also include Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown. Figure 1 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0054] Optionally, the electronic device may store an index array, the index array including a plurality of index addresses, and a hash keyword is stored at each index address.
[0055] Next, the above Figure 1 The electronic device in the embodiment is the execution subject, and the hash table lookup test method provided in the embodiment of the present application is exemplarily introduced in combination with the flow chart.
[0056] Specifically, Figure 2 A flow chart of the hash table lookup test method provided in the embodiment of the present application is shown in FIG. Figure 2 , the method comprising:
[0057] Step S20: receiving a test instruction sent by the user.
[0058] The test instruction includes a target index address to be indexed.
[0059] Optionally, the user can select a target index address from the storage array according to specific test requirements.
[0060] In this embodiment, the target index address may be a specific index address, or may be a specific partial index address or all index addresses, such as all even-numbered index addresses.
[0061] Step S21 , determining a corresponding target hash keyword according to the target index address and the index array, and inputting the target hash keyword as a test stimulus into the module to be tested, so as to perform a hash table lookup test on the test table entry.
[0062] The test table entry is consistent with the index array.
[0063] Optionally, the module to be tested may be a switch chip.
[0064] It can be understood that the electronic device can obtain the target hash keyword corresponding to the target index address based on the index array, and input the target hash keyword as a test stimulus into the module to be tested. Since the test module stores test table entries consistent with the index array, the target hash keyword can accurately hit the content corresponding to the target index address.
[0065] The hash table lookup test method provided in the embodiment of the present application is that an index array is stored in the electronic device, and a hash keyword is stored at each index address in the index array. When performing a test, the electronic device can determine the target hash keyword from the storage array according to the target index address that the user wants to hit, and send the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table item. Therefore, the hit and conflict probabilities can be accurately controlled, the test efficiency can be improved, and specific indexing for the target index address can be achieved.
[0066] Optionally, to facilitate the hash table lookup test, the electronic device may generate and store an index array in advance.
[0067] Specifically, in Figure 2 On the basis of Figure 3 For another flow chart of the hash table lookup test method provided in the embodiment of the present application, please refer to Figure 3 Before the above step S20, the method further includes:
[0068] Step S10: Generate an index array according to a preset hash polynomial.
[0069] Step S11 : for each hash keyword stored in the index array, store the hash keyword into a test entry of the module to be tested according to the index address corresponding to the hash keyword.
[0070] Optionally, the hash polynomial generally refers to a hash function construction method based on polynomial operations, which is used to map an input hash keyword to a corresponding index address.
[0071] In this embodiment, the electronic device may store the hash keywords corresponding to the respective index addresses in the index array into the memory of the module to be tested, thereby obtaining corresponding test entries.
[0072] Optionally, the index array may be established according to the number of hash polynomials and the size of the address space corresponding to the test table entries, so that the size of the index array corresponds to the size of the test table entries in the module to be tested.
[0073] In this embodiment, the electronic device can establish an initial storage array based on the number of hash polynomials and the address space corresponding to the test table entries, randomly generate hash keywords, and calculate the index address corresponding to the hash keyword based on the hash polynomial and preset requirement conditions. If the index address meets the preset conditions, the hash keyword is stored at the index address.
[0074] In a possible implementation, if the number of hash polynomials is N and the address space size of the test entry is D, then the initial storage array M may be (N, D).
[0075] Optionally, the requirement condition may include which hash polynomials are used to calculate the index address corresponding to the hash keyword. It is understandable that the requirement condition may be set in advance according to actual application conditions, for example, setting the index address corresponding to the hash keyword to be calculated according to all hash polynomials.
[0076] Optionally, considering that the storage space may be large, generating a hash keyword once may not be enough to fully store the initial storage array. Therefore, it is also necessary to determine whether there are any index addresses in the initial storage array that do not store hash keywords.
[0077] In one possible implementation, if there are still index addresses in the initial storage array that do not store hash keywords, the steps of randomly generating hash keywords are re-executed, and the index address corresponding to the hash keyword is calculated according to preset requirement conditions. If the index address meets the preset conditions, the hash keyword is stored at the index address until there are no index addresses in the initial storage array that do not store hash keywords.
[0078] In another possible implementation, if the initial storage array does not contain an index address that does not store a hash keyword, the initial storage array is determined as the storage array.
[0079] In this embodiment, if the initial storage array is not full, it is necessary to continue generating hash keywords and storing them at corresponding index addresses until the initial storage array is full.
[0080] Optionally, considering that there are multiple hash polynomials, it is also necessary to verify all hits and partial hits of the hash polynomials. In the related art, to test whether the input hash keyword hits one polynomial and multiple polynomials, a lot of stimuli need to be sent to achieve this, resulting in low test efficiency. Based on this, the hash table lookup test method provided in the embodiment of the present application can realize the test for the situation where the hash keyword hits one polynomial and multiple polynomials by setting different requirement conditions.
[0081] Optionally, different requirement conditions can be set for each hash keyword generated. For example, for some hash keywords, it is set that the index address corresponding to the hash keyword needs to be calculated based on the entire hash polynomial, and for some hash keywords, it is set that the index address corresponding to the hash keyword needs to be calculated based on part of the hash polynomial.
[0082] In one example, a probability value can be preset. For example, the corresponding requirement when generating a hash keyword for the first time may be to calculate its corresponding index address based on all hash polynomials, the corresponding requirement when generating a hash keyword for the second time may be to calculate its corresponding index address based on ninety percent of the hash polynomials, and the corresponding requirement when generating a hash keyword for the third time may be to calculate its corresponding index address based on eighty percent of the hash polynomials, and so on.
[0083] It can be understood that in this way, some hash keywords can correspond to all hash polynomials, and some hash keywords can correspond to some hash polynomials. Therefore, during actual testing, the corresponding hash keywords can be selected according to the test requirements, thereby realizing testing for some or all hash polynomial hits.
[0084] Next, we provide a possible implementation method for randomly generating hash keywords, calculating the index address corresponding to the hash keyword according to preset requirements, and storing the hash keyword at the index address when the index address meets the preset conditions.
[0085] In this embodiment, the electronic device can randomly generate a hash keyword each time, determine a target hash polynomial from multiple hash polynomials according to the required conditions, calculate the corresponding index address according to the target hash polynomial and the hash keyword, and determine whether other hash keywords have been stored at the index address.
[0086] Optionally, the target hash polynomial can be determined according to the requirement condition. For example, if the requirement condition is to calculate the index address corresponding to the hash keyword based on all hash polynomials, then the target hash polynomial is all hash polynomials. If the requirement condition is to calculate the index address corresponding to the hash keyword based on eighty percent of the hash polynomials, then eighty percent of the hash polynomials can be randomly selected from all the hash polynomials as the target hash polynomial.
[0087] Optionally, considering that the hash keyword is randomly generated, there may be a situation where a hash keyword is already stored at the calculated index address. In this case, if other hash keywords are already stored at the index address, the currently generated hash keyword should not be stored again.
[0088] It is understandable that the preset condition includes that no other hash keywords are stored at the index address corresponding to the hash keyword. In one possible implementation, if another hash polynomial is already stored at the index address, a new hash keyword is randomly generated, and a new index address is calculated based on the target hash polynomial and the new hash keyword until no other hash keywords are stored at the new index address.
[0089] In another possible implementation, if no other hash keyword is stored at the index address, the hash keyword is stored at the index address.
[0090] Optionally, the index address corresponding to the hash keyword may be one or more. If the index address corresponding to the hash keyword is one and other hash keywords have already been stored at the index address, the hash keyword needs to be regenerated. It can be understood that the target hash polynomial does not need to be re-determined at this time. The new index address can be directly calculated based on the previously determined target polynomial and the hash keyword to determine whether other hash keywords are stored at the new index address. Until no other hash keywords are stored at the new index address, the currently generated hash keyword will be stored at the new index address.
[0091] Optionally, if there are multiple index addresses corresponding to the hash keyword, and other hash keywords are already stored at these multiple index addresses, then the hash keyword needs to be regenerated. It is understandable that the target hash polynomial does not need to be re-determined at this time. A new index address can be directly calculated based on the previously determined target polynomial and the hash keyword, and whether other hash keywords are stored at the new index address is determined. If no other hash keywords are stored at at least one new index address, the currently generated hash keyword is stored at the new index address.
[0092] Optionally, if there are multiple index addresses corresponding to the hash keyword, and there is at least one index address among the multiple index addresses that does not store other hash keywords, the hash keyword is directly stored at the index address.
[0093] In this embodiment, after the hash keyword is stored, it may be determined whether the initial storage array is full.
[0094] Optionally, in order to facilitate confirmation of whether other hash keywords have been stored at the index address, a storage identifier can be set for the index address. After storing the hash keyword at the corresponding index address, the electronic device can update the storage identifier to indicate that a hash keyword has been stored at the index address at this time.
[0095] For example, a storage flag Flag=0 indicates that no hash keyword is stored at the index address, and a storage flag Flag=1 indicates that a hash keyword is stored at the index address.
[0096] In order to execute the corresponding steps in the above embodiments and various possible methods, an implementation of a hash table lookup test device is given below. Figure 4 , Figure 4 This is a functional module diagram of the hash table lookup test device provided in an embodiment of the present application. It should be noted that the basic principles and technical effects of the hash table lookup test device provided in this embodiment are the same as those of the above-mentioned embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding contents of the above-mentioned embodiments. The hash table lookup test device includes: a receiving module 200 and a testing module 210.
[0097] The receiving module 200 is used to receive a test instruction sent by a user; the test instruction includes a target index address to be indexed.
[0098] It can be understood that the receiving module 200 can also be used to execute the above step S20.
[0099] The test module 210 is used to determine the corresponding target hash keyword based on the target index address and the index array, and input the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table items in the test module; wherein the test table items are consistent with the index array.
[0100] It is understandable that the testing module 210 can also be used to execute the above step S21.
[0101] Optionally, in Figure 4 On the basis of Figure 5 For another functional module diagram of the hash table lookup test device provided in the embodiment of the present application, please refer to Figure 5The hash table lookup test device also includes a generation module 220.
[0102] The generation module 220 is configured to generate an index array according to a preset hash polynomial; and for each hash keyword stored in the index array, store the hash keyword into a test entry of the module to be tested according to the index address corresponding to the hash keyword.
[0103] It is understandable that the generation module 220 can also be used to execute the above steps S10 to S11.
[0104] Optionally, the generation module 220 is further used to establish an initial storage array based on the number of hash polynomials and the address space corresponding to the test table entry; randomly generate a hash keyword, and calculate the index address corresponding to the hash keyword based on the hash polynomial and preset requirement conditions, and store the hash keyword at the index address if the index address meets the preset condition; determine whether there is an index address in the initial storage array that does not store the hash keyword; if there is an index address in the initial storage array that does not store the hash keyword, re-execute the steps of randomly generating a hash keyword, and calculating the index address corresponding to the hash keyword based on the hash polynomial and preset requirement conditions, and storing the hash keyword at the index address if the index address meets the preset condition, until there is no index address in the initial storage array that does not store the hash keyword; if there is no index address in the initial storage array that does not store the hash keyword, determine the initial storage array as the storage array.
[0105] Optionally, the generation module 220 is also used to randomly generate a hash keyword each time; determine a target hash polynomial from multiple hash polynomials according to required conditions, and calculate a corresponding index address according to the target hash polynomial and the hash keyword; determine whether other hash keywords have been stored at the index address; if other hash keywords have been stored at the index address, randomly generate a new hash keyword again, and calculate a new index address according to the target hash polynomial and the new hash keyword, until no other hash keywords are stored at the new index address; if no other hash keywords are stored at the index address, store the hash keyword at the index address.
[0106] The hash table lookup test device provided in the embodiment of the present application stores an index array in the electronic device, and a hash keyword is stored at each index address in the index array. When performing a test, the electronic device can determine the target hash keyword from the storage array according to the target index address that the user wants to hit, and send the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table item. Therefore, the hit and conflict probabilities can be accurately controlled, the test efficiency can be improved, and specific indexing for the target index address can be achieved.
[0107] Optionally, the above modules can be stored in the form of software or firmware. Figure 1 The memory shown in FIG. 1 or the operating system (OS) of the electronic device may be fixed therein and may be Figure 1 Meanwhile, the data and program codes required to execute the above modules may be stored in the memory.
[0108] An embodiment of the present application further provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the hash table lookup test method provided in the embodiment of the present application can be implemented.
[0109] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of the devices, methods, and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment, or a portion of code, and the module, program segment, or a portion of code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the boxes can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or can be implemented using a combination of dedicated hardware and computer instructions.
[0110] In addition, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0111] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0112] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application shall be included within the scope of protection of the present application.
Claims
1. A hash table lookup test method, characterized in that: Applied to an electronic device, the electronic device stores an index array, the index array includes multiple index addresses, each index address stores a corresponding hash keyword, the method includes: Receive a test instruction sent by a user; the test instruction includes a target index address to be indexed; Determine the corresponding target hash keyword according to the target index address and the index array, and input the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table entry in the test module; wherein the test table entry is consistent with the index array.
2. The method according to claim 1, characterized in that Before receiving the test instruction sent by the user, the method further includes: Generating the index array according to a preset hash polynomial; For each hash keyword stored in the index array, the hash keyword is stored in the test table entry of the module to be tested according to the index address corresponding to the hash keyword.
3. The method according to claim 2, characterized in that Generating the index array according to a preset hash polynomial includes: Establishing an initial storage array according to the number of the hash polynomials and the address space corresponding to the test table entry; Randomly generate the hash keyword, and calculate the index address corresponding to the hash keyword according to the hash polynomial and preset requirement conditions, and store the hash keyword at the index address if the index address meets the preset condition; Determining whether there is an index address in the initial storage array that does not store the hash keyword; If an index address not storing the hash keyword exists in the initial storage array, the steps of randomly generating the hash keyword, calculating the index address corresponding to the hash keyword according to the hash polynomial and a preset requirement, and storing the hash keyword at the index address if the index address meets the preset condition are re-executed until no index address not storing the hash keyword exists in the initial storage array; If the index address not storing the hash keyword does not exist in the initial storage array, the initial storage array is determined as the storage array.
4. The method according to claim 3, characterized in that The randomly generating the hash keyword, calculating the index address corresponding to the hash keyword according to the hash polynomial and a preset requirement, and storing the hash keyword at the index address if the index address meets the preset condition, includes: Randomly generate a hash keyword each time; Determine a target hash polynomial from the plurality of hash polynomials according to the requirement, and calculate a corresponding index address according to the target hash polynomial and the hash keyword; Determine whether other hash keywords are already stored at the index address; If other hash keywords are already stored at the index address, a new hash keyword is randomly generated, and a new index address is calculated according to the target hash polynomial and the new hash keyword, until no other hash keywords are stored at the new index address; If the other hash keyword is not stored at the index address, the hash keyword is stored at the index address.
5. A hash table lookup test device, characterized in that: Applied to an electronic device, the electronic device stores an index array, the index array includes multiple index addresses, each index address stores a corresponding hash keyword, the device includes: A receiving module, configured to receive a test instruction sent by a user; the test instruction includes a target index address to be indexed; A test module is used to determine the corresponding target hash keyword based on the target index address and the index array, and input the target hash keyword as a test stimulus to the module to be tested to perform a hash table lookup test on the test table entry in the test module; wherein the test table entry is consistent with the index array.
6. The device according to claim 5, characterized in that Also includes a generation module; The generating module is configured to generate the index array according to a preset hash polynomial; For each hash keyword stored in the index array, the hash keyword is stored in the test table entry of the module to be tested according to the index address corresponding to the hash keyword.
7. The device according to claim 6, characterized in that The generation module is further configured to establish an initial storage array according to the number of the hash polynomials and the address space corresponding to the test table entry; randomly generate the hash keyword, and calculate the index address corresponding to the hash keyword according to the hash polynomial and preset requirement conditions, and store the hash keyword at the index address if the index address meets the preset condition; Determining whether there is an index address in the initial storage array that does not store the hash keyword; If an index address not storing the hash keyword exists in the initial storage array, the steps of randomly generating the hash keyword, calculating the index address corresponding to the hash keyword according to the hash polynomial and a preset requirement, and storing the hash keyword at the index address if the index address meets the preset condition are re-executed until no index address not storing the hash keyword exists in the initial storage array; If the index address not storing the hash keyword does not exist in the initial storage array, the initial storage array is determined as the storage array.
8. The device according to claim 7, characterized in that The generating module is further configured to randomly generate one of the hash keywords each time; determine a target hash polynomial from the plurality of hash polynomials according to the requirement, and calculate a corresponding index address according to the target hash polynomial and the hash keyword; Determine whether other hash keywords are already stored at the index address; If other hash keywords are already stored at the index address, a new hash keyword is randomly generated, and a new index address is calculated according to the target hash polynomial and the new hash keyword, until no other hash keywords are stored at the new index address; If the other hash keyword is not stored at the index address, the hash keyword is stored at the index address.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the method according to any one of claims 1 to 4.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.