A data storage method and related device
By using a sub-function to calculate the index in network devices, a one-dimensional address space is mapped to a two-dimensional space, solving the problem of limited storage resources in high-performance network devices and improving storage efficiency and lookup performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-31
- Publication Date
- 2026-03-17
AI Technical Summary
Existing technologies struggle to efficiently store and retrieve key-value pairs in high-performance network devices, especially on forwarding chips with limited storage resources, resulting in low storage efficiency.
A data storage method is adopted, which calculates the index by determining a sub-function to directly indicate the storage address of the data, simplifying the storage process of network devices. The hash remainder address mapping method is used to map the one-dimensional address space to the two-dimensional space, thereby improving storage efficiency.
It reduces network equipment overhead, improves data storage efficiency, simplifies storage processes, and enhances hash table load rate and lookup performance.
Smart Images

Figure CN115729847B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communications, and more particularly to a data storage method and related equipment. Background Technology
[0002] As the scale of the Internet continues to grow, and the number of network users and content increases, the performance requirements for storing and retrieving massive amounts of data in the field of data communication technology are becoming increasingly stringent.
[0003] Key-value lookup systems have wide applications in current data communication, such as in network forwarding devices where high-speed lookups of MAC address tables and flow tables are required, and in content delivery networks (CDNs) and data center distributed storage systems where large-scale, fast content lookups are needed. In the network device forwarding plane, hash tables are a common implementation method for storing and looking up key-value pairs.
[0004] High-performance network devices place extremely high demands on the scale and lookup performance of key-value pair storage. However, the storage resources of the forwarding chips in these devices are limited and struggle to support complex operations. Therefore, designing and implementing a hash table—an efficient and easy-to-use key-value pair storage and lookup method—is crucial for improving the specifications of network device entries and forwarding performance. How to improve the efficiency of key-value pair storage is a question worthy of careful consideration. Summary of the Invention
[0005] This application provides a data storage method. The process of determining the first seed function by the network device is simple, which reduces the overhead of the network device and improves the efficiency of the network device in storing the first data.
[0006] A first aspect of this application provides a data storage method in which a network device acquires a first key and first data, the first key being used to locate the first data; the network device determines a first seed function based on the first key, the first seed function being used to calculate a first index, the first index being used to indicate the storage address of the first data; the network device calculates the first index based on the first seed function; and the network device stores the first data in a storage list based on the first index.
[0007] In this application, the network device can directly determine the first seed function based on the first key value through a single calculation. The first seed function is used to calculate the first index, which indicates the storage address of the first data. The network device calculates the first index based on the first seed function. The network device then stores the first data in the storage list based on the first index. This simplifies the process of determining the first seed function, reduces the network device's overhead, and improves the efficiency of storing the first data.
[0008] In one possible implementation, the first coordinates include first row coordinates and first column coordinates. The network device determines the target seed function based on the target key value, including: the network device uses a first function to calculate the first key value to obtain the first row coordinates; the network device obtains the first seed function based on the first row coordinates.
[0009] In this possible implementation, the first coordinate includes the first row coordinate and the first column coordinate. In the formula used in the example above, `key` is the first key value, `i` is the first row coordinate, and `j` is the first column coordinate. Substituting `key` into the hash function yields the values of `i` and `j`, which are the first coordinates.
[0010] In one possible implementation, the network device obtains the first seed function based on the first row coordinates, including: the network device obtains multiple key values that have the same row coordinates as the first row coordinates; the network device generates the first seed function based on the first key value and the multiple key values.
[0011] In this possible implementation, once the network device has obtained all the key values, it can calculate a new seed based on the new key and the original key, thus obtaining a perfect hash seed. In other words, the network device generates a first seed function based on the first key value and multiple key values. This possible implementation improves the feasibility of the solution.
[0012] In one possible implementation, the storage list includes a first list and a second list. The network device stores the first data in the storage list according to the first index, including: the network device stores the first data in the first list according to the first index; the method further includes: the network device sets a target calculation result, the target calculation result is used to indicate the calculation result between the value recorded at the address corresponding to the first coordinate and the value recorded at the address corresponding to the second coordinate, the second coordinate being the coordinate of the second address, the second address being located in the second list, the first address being located in the first list, and the target calculation result being used to indicate that the first data is stored in the first list.
[0013] In this method, the network device uses the d-left hash algorithm to calculate the sub-table number d and the hash bucket index i (first row coordinate). A perfect hash function (first seed function) is searched for all keys corresponding to the hash bucket HT_d[i] of the sub-table HT_d and the currently inserted key. If a perfect hash function is found, its seed is recorded in the hash bucket. Otherwise, the insertion fails. According to the table entry index (first index) calculated by the perfect hash function, each value is stored in the hash bucket according to the table entry position corresponding to its key. The mapping relationship between the key and the sub-table number d is inserted into the Othello hash, resulting in a one-dimensional bitmap. Using the hash remainder address mapping method, the logical address index to be modified is mapped to a two-dimensional address space, obtaining the row and column address coordinates (i,j) (first coordinates). The two-dimensional bitmap is written into the corresponding hash bucket according to the row and column addresses. For example, assuming... Figure 7 The data is ultimately stored in hash table HT0. Therefore, the XOR operation on the values written to Bit0 and Bit1 in the two-dimensional bitmap will return 0 (the target result). A value of 0 after XOR indicates that the first data has been written to hash table HT0. This possible implementation provides a concrete approach, improving the feasibility of the solution.
[0014] In one possible implementation, the method further includes: the network device receiving a data query instruction, the data query instruction including the first key value; and the network device querying the first data based on the first key value.
[0015] In one possible implementation, the storage list includes a first list and a second list. The network device queries the first data based on the first key value, including: the network device obtaining a first index and a second index based on the first key value; the network device obtaining third data from the first list based on the first index; the network device obtaining fourth data from the second list based on the second index; the network device confirming the third data as the first data based on the target operation result, where the target operation result indicates the operation result between the value recorded at the address corresponding to the first coordinate and the value recorded at the address corresponding to the second coordinate, the second coordinate being the coordinate of the second address, the second address being located in the second list, and the first address being located in the first list. The target operation result is used to indicate that the first data is stored in the first list.
[0016] In this possible implementation, the network device calculates the hash bucket indices i0 = Hash0(key) % M and i1 = Hash1(key) % M in HT0 and HT1, respectively, corresponding to the search key. It then accesses the hash buckets HT0[i0] and HT1[i1] of the two sub-tables to obtain the Bitmap BM[i0] and BM[i1], as well as the perfect hash seed. and Use respectively and Construct a perfect hash function for the corresponding hash bucket, and use the perfect hash function to calculate the table entry indices k0 and k1 (first and second indices) corresponding to the search key. Access the table entries of the two hash buckets corresponding to the key, obtaining Value0 = HT[i0][k0] and Value1 = HT[i1][k1]. Calculate the indices of the bit values in the Bitmap of the two hash buckets corresponding to the key: j0 = Hash0(key) % N, j1 = Hash1(key) % N. If... Returns Value0. Otherwise, returns Value1. This possible implementation provides a concrete way to query key-value pairs, improving the feasibility of the solution.
[0017] A second aspect of this application provides a network device including at least one processor, a memory, and a communication interface. The processor is coupled to the memory and the communication interface. The memory stores instructions, the processor executes the instructions, and the communication interface communicates with other network devices under the control of the processor. When executed by the processor, the instructions cause the network device to perform the methods described in the first aspect or any possible implementation thereof.
[0018] A third aspect of this application provides a computer program product storing one or more computer-executable instructions, wherein when the computer-executable instructions are executed by the processor, the processor executes the method described in the first aspect or any possible implementation thereof.
[0019] The fourth aspect of this application provides a chip including a processor and a communication interface, wherein the processor is coupled to the communication interface, and the processor is used to read instructions to execute the method described in the first aspect or any possible implementation thereof.
[0020] The fifth aspect of this application is a network system, which includes the first network device described in the first aspect or any possible implementation thereof.
[0021] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0022] In this application, after the network device obtains the first key value and the first data, it can directly determine the first seed function based on the first key value through a single calculation. The first seed function is used to calculate the first index, which indicates the storage address of the first data. The network device calculates the first index based on the first seed function. Then, the network device stores the first data in the storage list based on the first index. This simplifies the process of determining the first seed function, reduces the network device's overhead, and improves the efficiency of storing the first data. Attached Figure Description
[0023] Figure 1 A schematic diagram of the structure of a network system provided in this application;
[0024] Figure 2 A schematic diagram illustrating an application of a data storage method provided in this application;
[0025] Figure 3 A schematic diagram illustrating another application of the data storage method provided in this application;
[0026] Figure 4 A schematic diagram of a hash remainder address mapping method provided in this application;
[0027] Figure 5 A schematic diagram of the structure of a hash table provided in this application;
[0028] Figure 6 A schematic diagram of a keyword search process provided for this application;
[0029] Figure 7 A schematic diagram illustrating another application of the data storage method provided in this application;
[0030] Figure 8 A schematic diagram of an embodiment of a data storage method provided in this application;
[0031] Figure 9 A schematic diagram of an embodiment of a data storage method provided in this application;
[0032] Figure 10 A schematic diagram of the structure of a network device provided in this application;
[0033] Figure 11 A schematic diagram of another network device provided in this application. Detailed Implementation
[0034] The examples provided in this application are described below with reference to the accompanying drawings. Obviously, the described examples are only a part of the examples in this application, and not all of them. Those skilled in the art will understand that, with the development of technology and the emergence of new scenarios, the technical solutions provided in this application are also applicable to similar technical problems.
[0035] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the examples described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0036] As the scale of the Internet continues to grow, and the number of network users and content increases, the performance requirements for storing and retrieving massive amounts of data in the field of data communication technology are becoming increasingly stringent.
[0037] Key-value lookup systems have wide applications in current data communication, such as in network forwarding devices where high-speed lookups of MAC address tables and flow tables are required, and in content delivery networks (CDNs) and data center distributed storage systems where large-scale, fast content lookups are needed. In the network device forwarding plane, hash tables are a common implementation method for storing and looking up key-value pairs.
[0038] A basic hash table algorithm for the forwarding plane of network devices typically consists of two parts: a hash function and a table. Given a lookup key, the hash function calculates its corresponding index in the table. The table consists of several hash buckets. Due to collisions in calculating the index, each bucket also contains several entries to tolerate a certain degree of hash collisions. Entries store the key and its corresponding value (i.e., key-value pairs). During key-value pair insertion, the hash function is used to calculate the index of the key for the corresponding hash bucket; then, the key-value pair data is stored in a free entry within that hash bucket. During key-value pair lookup, the hash function is used to calculate the index of the key for the corresponding hash bucket; then, the key in each entry within the corresponding hash bucket is compared one by one. If they match, the lookup is successful, and the corresponding value is returned.
[0039] During key-value pair insertion, hash collisions can cause some key-value pairs to fail to be inserted into the table, and some entries may become empty. In other words, the storage space of a hash table is usually not fully utilized. Therefore, the memory utilization efficiency of a hash table algorithm is typically evaluated using the load rate; a higher load rate indicates more efficient hash table storage.
[0040] Generally, the higher the load rate of a hash table algorithm, the higher the complexity of its key-value pair insertion and lookup algorithms. For example, the d-left hash table algorithm splits a table into d sub-tables. When inserting key-value pairs, it indexes a hash bucket for each sub-table and ultimately selects the bucket with the lightest load for insertion. During lookup, it needs to traverse and search the lookup keyword across all d hash buckets simultaneously to retrieve the corresponding value. In this way, the d-left hash table algorithm can achieve a high load rate. The Cuckoo hash table is another commonly used hash table algorithm for data manipulation. When inserting key-value pairs, it indexes two hash buckets using two independent hash functions. If all entries in both buckets are occupied, a random bucket kick operation is performed. This involves randomly replacing the key-value pair of an existing entry in one bucket with the currently inserted key-value pair, and then replacing the corresponding key-value pair in the other bucket. This process is repeated until the last replaced key-value pair has a corresponding free entry to store it. In this way, the Cuckoo hash algorithm can also achieve a high load rate. However, the insertion and lookup processes of these improved hash table algorithms are more complex than those of the basic hash table algorithm.
[0041] Furthermore, storage and I / O resources on the forwarding chips of network devices are extremely valuable. Therefore, key-value pair storage and lookup algorithms in the forwarding plane often employ trade-offs in storage and throughput design, leveraging on-chip / off-chip differences. For example, to reduce on-chip memory usage, on-chip hash table entries store only short-width key fingerprints and addresses pointing to off-chip data, while off-chip storage allocates space to store the complete key-value pair data. During lookups, the key fingerprint is compared one by one within each hash bucket. If a match is found, an off-chip storage access is performed to retrieve the corresponding value. However, fingerprints contain only a small amount of key information, and collisions between fingerprints of different keys can lead to key-value pair insertion failures. Generally, shorter fingerprint widths result in lower storage overhead, but also a higher probability of collisions and a lower hash table load rate.
[0042] Typically, high-performance network devices have extremely high requirements for the scale and lookup performance of key-value pair storage. However, the storage resources of the forwarding chips in high-performance network devices are limited and cannot support complex operations. Therefore, designing and implementing a hash table that provides efficient storage and simple operation for key-value pairs is crucial for improving the table entry specifications and forwarding performance of network devices. How to improve the efficiency of storing key-value pairs is a question worth considering.
[0043] To address the problems existing in the above-mentioned solutions, this application provides a data storage method, related equipment, and a network system. The process of determining the first seed function by the network device is simple, reducing the overhead of the network device and improving the efficiency of the network device in storing the first data. The network system, data storage method, and network device provided in this application will be described below with reference to the accompanying drawings.
[0044] The network system provided in this application will be introduced below.
[0045] Figure 1 This is a schematic diagram of the structure of a network system provided in this application.
[0046] In this application, the network system includes at least the following: Figure 1 The network device 101 shown.
[0047] In this process, after obtaining the first key value and the first data, network device 101 can directly determine the first seed function based on the first key value through a single calculation. The first seed function is used to calculate the first index, which indicates the storage address of the first data. Network device 101 can then calculate the first index based on the first seed function. Finally, network device 101 stores the first data in the storage list according to the first index. This simplifies the process of determining the first seed function, reduces network device overhead, and improves the efficiency of network device 101 in storing the first data.
[0048] based on Figure 1 The network system described herein introduces the data storage method provided in this application.
[0049] Figure 2 This is a schematic diagram illustrating an application of a data storage method provided in this application.
[0050] Please see Figure 2 An example of the data storage method provided in this application includes steps 201 to 204.
[0051] 201. The network device obtains the first key value and the first data.
[0052] In this application, the first key is used to locate the first data. The first key can exist in various forms. For example, given a search keyword, that search keyword is a key, and a hash function can calculate the position index of that keyword in the data table. The data table can consist of several hash buckets. The data table can store multiple pieces of first data. Due to the collision problem in calculating the position index using hash functions, each bucket also contains several entries to tolerate a certain degree of hash collisions. Each entry stores a keyword (first key) and its corresponding value (first data), forming a key-value pair.
[0053] 202. The network device determines the first seed function based on the first key value.
[0054] In this application, the network device can obtain a first seed function based on a first key value. The first seed function can be used to calculate a first index, which indicates the storage address of the first data.
[0055] 203. The network device calculates the first index according to the first seed function.
[0056] 204. The network device stores the first data in the storage list according to the first index.
[0057] In this application, the data (first data) is typically stored in a hash table. In the data storage method provided in this application, the hash table storing the first data consists of two sub-tables, HT0 and HT1. The hash bucket position where the key-value pair is inserted is calculated using a d-left hash algorithm. Both hash tables have M buckets, and each hash bucket contains a Bitmap of length N, a seed for a perfect hash function, and K entries.
[0058] In this application, the network device can directly determine the first seed function based on the first key value through a single calculation. The first seed function is used to calculate the first index, which indicates the storage address of the first data. The network device calculates the first index based on the first seed function. The network device then stores the first data in the storage list based on the first index. This simplifies the process of determining the first seed function, reduces the network device's overhead, and improves the efficiency of storing the first data.
[0059] In this application, the network device mentioned in the above-described step 202 determines the target seed function based on the target key value in a specific way, which will be described in the following embodiments.
[0060] Figure 3 This is a schematic diagram illustrating another application of the data storage method provided in this application.
[0061] 301. The network device uses the first function to calculate the first key value and obtain the coordinates of the first row.
[0062] First, we will introduce a hash remainder address mapping method.
[0063] Figure 4 A schematic diagram of a hash remainder address mapping method provided in this application.
[0064] like Figure 4 As shown, the logical address space is a one-dimensional address index space containing B address units. The physical address space is a two-dimensional address index space, consisting of M rows * N columns of address units, indexed by row and column coordinates. The parameters satisfy the following relationship:
[0065] B = M * N.
[0066] M and N are coprime.
[0067] In this application, the address index k in the logical address space is calculated as follows:
[0068] k = Hash(key) % B
[0069] The address index (i,j) in the physical address space is calculated as follows:
[0070] i = Hash(key) % M
[0071] j = Hash(key) % N
[0072] Using the hash remainder address mapping method described above, a one-dimensional address space can be mapped to a two-dimensional address space. Therefore, this method can be used to map a Bitmap of length B from the Othello hash into a two-dimensional Bitmap of length M*N, and each row of the resulting two-dimensional Bitmap can be stored in each bucket of the hash table, resulting in, for example... Figure 5 The structure shown.
[0073] In this application, the first coordinate includes the first row coordinate and the first column coordinate. In the formula used in the example above, `key` is the first key value, `i` is the first row coordinate, and `j` is the first column coordinate. Substituting `key` into the hash function yields the values of `i` and `j`, which are the first coordinates.
[0074] 302. The network device obtains the first seed function based on the coordinates of the first row.
[0075] In this application, the network device can obtain the value of the first seed function after obtaining the coordinates of the first row.
[0076] Figure 5 This is a schematic diagram of the structure of a hash table provided in this application.
[0077] exist Figure 5 In the key-value pair storage structure of the present invention, each hash table includes multiple hash buckets. Each hash bucket contains three types of data: a Bitmap of length N, a seed of a perfect hash function (i.e., the first seed function), and the values of several key-value pairs. A hash table of the present invention contains M hash buckets, satisfying M*N = B and M and N being coprime. The data bit width of the Bitmap and seed must satisfy the following conditions:
[0078] The sum of the bit widths of the Bitmap and Seed is less than the bit width of a single data access supported by the hardware.
[0079] The hash bucket index is calculated as follows:
[0080] i = Hash(key) % M
[0081] In this application, using the above storage structure and memory access method, the bits in a keyword-related Bitmap and the seed of the perfect hash function are stored in the same hash bucket, and can be deployed in adjacent locations in physical memory. Therefore, when performing a keyword search, a single memory access is sufficient. That is, after obtaining the coordinates i of the first row, the first seed function can be obtained in one go.
[0082] Figure 6 This is a schematic diagram of a keyword search process provided for this application.
[0083] During the key-value pair insertion process, the bit value at each index position in the original Othello hash's one-dimensional Bitmap is written into the bitmap of each bucket in the hash table according to the result of the hash remainder address mapping method.
[0084] Optionally, when the network device obtains the first seed function based on the first row coordinates, there may be a specific implementation method, which will be described in the following embodiments.
[0085] Figure 7 This is a schematic diagram illustrating another application of the data storage method provided in this application.
[0086] 401. The network device obtains multiple key values that have the same row coordinates as the first row coordinates based on the first row coordinates.
[0087] For example, as shown in example 5, assuming the key value is hashed to a value of 1, the network device will retrieve the original key corresponding to the four values to the right of Seed in the first row. That is, the network device retrieves multiple key-value pairs with the same row coordinates as the first row.
[0088] 402. The network device generates a first seed function based on the first key value and multiple key values.
[0089] For example, such as Figure 5 In this process, once the network device has obtained all the key values, it can calculate a new seed based on the new key and the original key together, thus obtaining a perfect hash seed. That is, the network device generates the first seed function based on the first key value and multiple key values.
[0090] Figure 8 This is a schematic diagram of an embodiment of a data storage method provided in this application.
[0091] In this application, the network device stores first data in a storage list according to a first index. The specific storage process will be described in detail in the following embodiments.
[0092] The network device stores the first data in the first list according to the first index.
[0093] The network device is configured to calculate the target results.
[0094] In this application, the storage list includes a first list and a second list. The target calculation result is used to indicate the calculation result between the value recorded at the address corresponding to the first coordinate and the value recorded at the address corresponding to the second coordinate. The second coordinate is the coordinate of the second address. The second address is located in the second list, and the first address is located in the first list. The target calculation result is used to indicate that the first data is stored in the first list.
[0095] For example, the following is combined with Figure 8 This section describes the key-value pair insertion process. The network device uses the d-left hash algorithm to calculate the sub-table number d and the hash bucket index i (first row coordinate). A perfect hash function (first seed function) is searched for all keys corresponding to the hash bucket HT_d[i] of the sub-table HT_d and the currently inserted key. If a perfect hash function is found, its seed is recorded in the hash bucket. Otherwise, the insertion fails. Based on the table entry index (first index) calculated by the perfect hash function, each value is stored in the hash bucket according to its corresponding table entry position. The mapping relationship between the key and the sub-table number d is inserted into the Othello hash, resulting in a one-dimensional bitmap. Using the hash remainder address mapping method, the logical address index to be modified is mapped to a two-dimensional address space, obtaining the row and column address coordinates (i,j) (first coordinates). The two-dimensional bitmap is then written into the corresponding hash bucket based on the row and column addresses. For example, assuming... Figure 7The data is ultimately stored in hash table HT0. The value of the bit0 and bit1 written in the two-dimensional bitmap can be XORed to get 0 (the target operation result). The value of 0 after XORing means that the first data has been written to hash table HT0.
[0096] In this application, the network device queries the first data in the storage list based on the first key value. The specific storage process will be described in detail in the following embodiments.
[0097] The network device receives a data query command, which includes a first key value;
[0098] The network device obtains the first index and the second index based on the first key value.
[0099] The network device retrieves the third data from the first list based on the first index.
[0100] The network device retrieves the fourth data from the second list based on the second index.
[0101] The network device confirms the third data as the first data based on the target calculation result.
[0102] In this application, the target calculation result is used to indicate the calculation result between the value recorded at the address corresponding to the first coordinate and the value recorded at the address corresponding to the second coordinate. The second coordinate is the coordinate of the second address. The second address is located in the second list, and the first address is located in the first list. The target calculation result is used to indicate that the first data is stored in the first list.
[0103] For example, the following is combined with Figure 8 This describes the key-value pair insertion process. The network device calculates the hash bucket indices i0 = Hash0(key) % M and i1 = Hash1(key) % M in HT0 and HT1, respectively, corresponding to the search key. It then accesses the hash buckets HT0[i0] and HT1[i1] of the two sub-tables to obtain the Bitmap BM[i0] and BM[i1], as well as the perfect hash seed. and Use respectively and Construct a perfect hash function for the corresponding hash bucket, and use the perfect hash function to calculate the table entry indices k0 and k1 (first and second indices) corresponding to the search key. Access the table entries of the two hash buckets corresponding to the key, obtaining Value0 = HT[i0][k0] and Value1 = HT[i1][k1]. Calculate the indices of the bit values in the Bitmap of the two hash buckets corresponding to the key: j0 = Hash0(key) % N, j1 = Hash1(key) % N. If... Returns Value0. Otherwise, returns Value1.
[0104] Optionally, another hash algorithm can be used to store key-value pairs in this application, and this process will be described in detail below.
[0105] Figure 9 This is a schematic diagram of an embodiment of a data storage method provided in this application.
[0106] The technical solution of this application can be as follows: Figure 9 The following describes a practical application. In Example 2, only one hash table HT is used. The hash bucket position for key-value pair insertion is calculated using the Cuckoo hash algorithm. The hash table has M buckets, and each hash bucket contains an array of length N. Each element in the array is a 2-bit wide value, a seed for a perfect hash function, and K entries. The values in the array are generated using the Coloring Embedder algorithm.
[0107] For example, the following is combined with Figure 9 Explain the key-value pair insertion process. The Cuckoo hash algorithm is used to calculate the hash bucket index i and the hash function index d corresponding to the bucket index. Let HT be the hash bucket. d Search for a perfect hash function for all keys corresponding to [i] and the currently inserted key. If a perfect hash function is found, its seed is recorded in the hash bucket; otherwise, the insertion fails. Based on the table entry index calculated using the perfect hash function, store each value in the hash bucket according to the table entry position corresponding to its key. Insert the mapping relationship between the key and the sub-table number d in the Coloring Embedder to obtain a one-dimensional array. Using the hash remainder address mapping method, map the logical address index that needs to be modified to a two-dimensional address space to obtain the row and column address coordinates (i,j). Write the two-dimensional array into the corresponding hash bucket according to the row and column addresses.
[0108] For example, the following is combined with Figure 9Explain the key-value pair insertion process. Calculate the two hash bucket indices i_0 = Hash0(key) % M and i_1 = Hash1(key) % M using hash function 0 and hash function 1 respectively. Access the two hash buckets HT0[i_0] and HT1[i_1] respectively, obtaining the 2-bit arrays BM[i_0] and BM[i_1], and the perfect hash seeds Seed_(i_0) and Seed_(i_1). Construct the perfect hash function for the corresponding hash bucket using Seed_(i_0) and Seed_(i_1) respectively, and calculate the table entry indices k_0 and k_1 corresponding to the search key using the perfect hash function. Access the table entries in the two hash buckets corresponding to the key, obtaining Value_0 = HT[i_0][k_0] and Value_1 = HT[i_1][k_1]. Calculate the indices of the 2-bit arrays in the two hash buckets corresponding to the key: j_0 = Hash0(key) % N and j_1 = Hash1(key) % N. if Returns Value_0; otherwise, returns Value_1.
[0109] The above example provides a different implementation of a data storage method. Below is a network device 50, such as... Figure 10 As shown, the network device 50 is used to perform the steps executed by the network device in the above example. For details on these steps and their corresponding beneficial effects, please refer to the corresponding examples above; they will not be repeated here. The network device 50 includes:
[0110] The acquisition unit 501 is used to acquire a first key value and first data, wherein the first key value is used to look up the first data;
[0111] The determining unit 502 is configured to determine a first seed function based on the first key value, wherein the first seed function is used to calculate a first index, and the first index is used to indicate the storage address of the first data.
[0112] Calculation unit 503 is used to calculate the first index according to the first seed function;
[0113] Storage unit 504 is used to store the first data in a storage list according to the first index.
[0114] In one possible implementation, the first coordinate includes a first row coordinate and a first column coordinate.
[0115] The computing unit
[0116] Used to calculate the first row coordinates by using the first function to calculate the first key value;
[0117] The first seed function is obtained based on the coordinates of the first row.
[0118] In one possible implementation, the acquisition unit is used to acquire multiple key values that have the same row coordinates as the first row coordinates;
[0119] The generation unit is configured to generate the first seed function based on the first key value and the plurality of key values.
[0120] In one possible implementation, the storage list includes a first list and a second list.
[0121] The storage unit is used to store the first data in the first list according to the first index;
[0122] The setting unit is further configured to set a target calculation result, which indicates the calculation result between the value recorded at the address corresponding to the first coordinate and the value recorded at the address corresponding to the second coordinate. The second coordinate is the coordinate of the second address, which is located in the second list, and the first address is located in the first list. The target calculation result indicates that the first data is stored in the first list.
[0123] One possible implementation is characterized by,
[0124] A receiving unit is configured to receive a data query instruction, wherein the data query instruction includes the first key value;
[0125] The query unit is used to query the first data based on the first key value.
[0126] In one possible implementation, the storage list includes a first list and a second list, and the network device queries the first data based on the first key value, including:
[0127] The acquisition unit is used for:
[0128] Retrieve the first index and the second index based on the first key value;
[0129] The third data is retrieved from the first list based on the first index;
[0130] The fourth data is retrieved from the second list based on the second index;
[0131] The confirmation unit is used to confirm that the third data is the first data according to the target calculation result. The target calculation result is used to indicate the calculation result between the value recorded at the address corresponding to the first coordinate and the value recorded at the address corresponding to the second coordinate. The second coordinate is the coordinate of the second address. The second address is located in the second list, and the first address is located in the first list. The target calculation result is used to indicate that the first data is stored in the first list.
[0132] It should be noted that the information interaction and execution process between the modules of the network device 50 mentioned above are based on the same concept as the method example of this application, and the execution steps are consistent with the detailed content of the method steps mentioned above. Please refer to the description in the method example mentioned above.
[0133] See Figure 11 The diagram shown illustrates the structure of a network device 600 provided in this application. The network device 600 includes a processor 602, a communication interface 603, and a memory 601. Optionally, a bus 604 may be included. The communication interface 603, processor 602, and memory 601 can be interconnected via the bus 604. The bus 604 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, Figure 11 The symbol is represented by a single thick line, but this does not indicate that there is only one bus or one type of bus. This network device 600 can achieve... Figure 10 The example illustrates the functionality of any of the network devices. Processor 602 and communication interface 603 can perform the corresponding operations of the network devices in the above method examples.
[0134] The following is combined Figure 11 A detailed introduction to each component of a network device:
[0135] The memory 601 may be volatile memory, such as random-access memory (RAM); or non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); or a combination of the above types of memory, used to store program code, configuration files, or other content that can implement the method of this application.
[0136] The processor 702 is the control center of the controller. It can be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the examples provided in this application, such as one or more digital signal processors (DSPs), or one or more field-programmable gate arrays (FPGAs).
[0137] Communication interface 603 is used for communication with other network devices.
[0138] The processor 602 can perform the aforementioned... Figure 10 The operation performed by any one of the network devices in the example shown will not be described in detail here.
[0139] It should be noted that the information interaction and execution process between the modules of the network device 600 mentioned above are based on the same concept as the method example of this application, and the execution steps are consistent with the detailed content of the method steps mentioned above. Please refer to the description in the method example mentioned above.
[0140] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the aforementioned examples, and will not be repeated here.
[0141] In the examples provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus examples described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, apparatuses, or units, and may be electrical, mechanical, or other forms.
[0142] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this example, depending on actual needs.
[0143] Furthermore, the functional units in the various examples of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0144] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various examples of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0145] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that different examples can be combined, and the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any combination, modification, equivalent substitution, or improvement made within the spirit and principles of the present invention should be included within the scope of protection of the present invention. The above examples are only used to illustrate the technical solutions of this application and are not intended to limit them. Although the present application has been described in detail with reference to the foregoing examples, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing examples, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the examples in this application.
Claims
1. A data storage method, characterized by, The method comprises the following steps: The network device acquires a first key value and first data, wherein the first key value is used to search for the first data; The network device determines a first seed function according to the first key value, wherein the first seed function is used to calculate a first index, and the first index is used to indicate a storage address of the first data; The network device calculates the first index according to the first seed function; The network device stores the first data in a storage list according to the first index; The first coordinate comprises a first row coordinate and a first column coordinate, and the network device determines a first seed function according to the first key value, which comprises the following steps: The network device calculates the first row coordinate by using a first function on the first key value; The network device acquires the first seed function according to the first row coordinate.
2. The data storage method of claim 1, wherein, The network device acquires the first seed function according to the first row coordinate, which comprises the following steps: The network device acquires a plurality of key values with the same row coordinate as the first row coordinate according to the first row coordinate; The network device generates the first seed function according to the first key value and the plurality of key values.
3. The data storage method according to claim 1 or 2, characterized by, The storage list comprises a first list and a second list, and the network device stores the first data in the storage list according to the first index, which comprises the following steps: The network device stores the first data in the first list according to the first index; The method further comprises the following steps: The network device sets a target operation result, wherein the target operation result is used to indicate an operation result between a value recorded in an address corresponding to a first coordinate and a value recorded in an address corresponding to a second coordinate, the second coordinate is a coordinate of a second address, the second address is located in the second list, a first address is located in the first list, and the target operation result is used to indicate that the first data is stored in the first list, the first address is an address corresponding to the first coordinate, and the second address is an address corresponding to the second coordinate.
4. The data storage method according to any one of claims 1 or 2, wherein, The method further comprises the following steps: The network device receives a data query instruction, wherein the data query instruction comprises the first key value; The network device queries the first data according to the first key value.
5. The data storage method of claim 4, wherein, The storage list comprises a first list and a second list, and the network device queries the first data according to the first key value, which comprises the following steps: The network device acquires a first index and a second index according to the first key value; The network device acquires third data from the first list according to the first index; The network device acquires fourth data from the second list according to the second index; The network device confirms that the third data is the first data according to a target operation result, wherein the target operation result is used to indicate an operation result between a value recorded in an address corresponding to a first coordinate and a value recorded in an address corresponding to a second coordinate, the second coordinate is a coordinate of a second address, the second address is located in the second list, a first address is located in the first list, and the target operation result is used to indicate that the first data is stored in the first list.
6. A network device, comprising: The method comprises the following steps: An acquisition unit is configured to acquire a first key value and first data, wherein the first key value is used to search for the first data; determining, according to the first key value, a first seed function, the first seed function being used to calculate a first index, the first index being used to indicate a storage address of the first data; calculating, according to the first seed function, the first index; storing, according to the first index, the first data in a storage list; the first coordinate comprises a first row coordinate and a first column coordinate, the calculating unit, calculating the first row coordinate by using a first function on the first key value; obtaining the first seed function according to the first row coordinate.
7. The network device of claim 6, wherein: the obtaining unit is configured to obtain, according to the first row coordinate, a plurality of key values having the same row coordinate as the first row coordinate; the generating unit is configured to generate the first seed function according to the first key value and the plurality of key values.
8. The network device of claim 6 or 7, wherein, the storage list comprises a first list and a second list, the storing unit is configured to store the first data in the first list according to the first index; the setting unit is further configured to set a target operation result, the target operation result being used to indicate an operation result between a value recorded in an address corresponding to the first coordinate and a value recorded in an address corresponding to a second coordinate, the second coordinate being a coordinate of a second address, the second address being located in the second list, a first address being located in the first list, the target operation result being used to indicate that the first data is stored in the first list, the first address being the address corresponding to the first coordinate, and the second address being the address corresponding to the second coordinate.
9. The network device of any one of claims 6 or 7, wherein: the receiving unit is configured to receive a data query instruction, the data query instruction comprising the first key value; the querying unit is configured to query the first data according to the first key value.
10. The network device of claim 9, wherein, the storage list comprises a first list and a second list, and the network device queries the first data according to the first key value, comprising: the obtaining unit is configured to: obtain a first index and a second index according to the first key value; obtain third data from the first list according to the first index; obtain fourth data from the second list according to the second index; the confirming unit is configured to confirm that the third data is the first data according to a target operation result, the target operation result being used to indicate an operation result between a value recorded in an address corresponding to the first coordinate and a value recorded in an address corresponding to a second coordinate, the second coordinate being a coordinate of a second address, the second address being located in the second list, a first address being located in the first list, the target operation result being used to indicate that the first data is stored in the first list.
11. A network device, comprising: comprising: a processor, a memory, and a communication interface; the processor is connected to the memory and the communication interface; the communication interface is configured to: send first information to a second network device; receive a data packet; the processor is configured to read instructions stored in the memory, so that the network device performs the method of any one of claims 1 to 5.
Citation Information
Patent Citations
Apparatus and method for hash table storage, searching
CN101604337A