Encoding method applied to a key tree, decoding method applied to a key tree, and electronic device

By encoding some non-leaf nodes in the key tree, the problem of inefficiency in storage and search in long key value management is solved, and efficient storage and fast search is achieved.

CN112685404BActive Publication Date: 2025-07-11VIA TECH INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011508208.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-18
Publication Date
2025-07-11
Estimated Expiration
2041-01-28

AI Technical Summary

Technical Problem

The prior art requires a large amount of memory capacity and performs a large amount of comparison operations to find the corresponding leaf nodes when managing long key values, resulting in inefficient storage and search.

Method used

Some non-leaf nodes in the key tree are encoded, metadata is generated, and the encoding result is written to the storage device. During decoding, it is determined whether the decoding operation is completed based on the bit value of the input key and the total number of sub-leaf nodes of the non-leaf nodes.

Benefits of technology

It reduces storage requirements and decoding complexity, improves storage and search efficiency, especially when processing long keys, the storage capacity requirement is fixed to (N-1)*(log2M+log2N), and the decoding complexity is O(N).

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112685404B_ABST
    Figure CN112685404B_ABST
Patent Text Reader

Abstract

The present invention discloses a coding method applied to a trie tree. The coding method includes: coding some non-leaf nodes in the trie tree to generate multiple pieces of metadata; and writing a coding result of the trie tree into a storage device, where the coding result includes the multiple pieces of metadata respectively corresponding to the some non-leaf nodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to data management, and more particularly to an encoding method applied to a key tree, a decoding method applied to a key tree, and a related electronic device. Background Art

[0002] With the rapid growth of data volume on the Internet, it has become increasingly common to use combinations of keys (key-value) to organize and manage a large amount of data. Therefore, how to effectively store key values and quickly obtain the corresponding values by inputting keys has become an important issue. Generally speaking, multiple keys can form a tree structure of a key trie according to the typical binary tree architecture of "0" on the left and "1" on the right. When an input key is received, the leaf node corresponding to this input key can be found based on the tree structure of the key trie, and the corresponding value can be obtained according to this leaf node. However, when the lengths of multiple keys that make up the key trie are very long, if a direct search is performed based on the key trie, a large memory capacity is required to completely store the data of the key trie, and a large number of comparison operations are required to find the corresponding leaf node of this input key in this key trie. Summary of the Invention

[0003] Therefore, one of the objectives of the present invention is to provide an encoding method applied to a key tree, a decoding method applied to a key tree, and a related electronic device.

[0004] In an embodiment of the present invention, an encoding method applied to a key tree is disclosed. The encoding method includes: encoding some non-leaf nodes in the key tree to generate multiple pieces of metadata; and writing an encoding result of the key tree into a storage device, where the encoding result includes the multiple pieces of metadata respectively corresponding to the some non-leaf nodes.

[0005] In another embodiment of the present invention, a decoding method applied to a key tree is disclosed. The decoding method includes: reading a piece of metadata from multiple pieces of metadata included in an encoding result of the key tree from a storage device, where the piece of metadata includes a depth value of a corresponding non-leaf node in the key tree; selectively updating a key index value according to a bit value of a bit corresponding to the depth value in an input key; and determining whether a decoding operation of the key index value ends according to a total number of leaf nodes of a unilateral subtree of the corresponding non-leaf node indicated by the bit.

[0006] In another embodiment of the present invention, an electronic device is disclosed. The electronic device includes a storage device and a processing circuit. The processing circuit is used to encode some non-leaf nodes in a key tree to generate multiple pieces of metadata; and write an encoding result of the key tree into a storage device, where the encoding result includes the multiple pieces of metadata respectively corresponding to the some non-leaf nodes.

[0007] In another embodiment of the present invention, an electronic device is disclosed. The electronic device includes a storage device and a processing circuit. The processing circuit is configured to read one piece of metadata included in an encoding result of a key tree from the storage device, where the piece of metadata includes a depth value of a corresponding non-leaf node in the key tree; selectively update a key index value according to a bit value of a bit corresponding to the depth value in an input key; and determine whether a decoding operation of the key index value ends according to a total number of leaf nodes in a unilateral subtree of the corresponding non-leaf node indicated by the bit.

[0008] Regarding the encoding operation, assuming that the number of keys included in a key group is N and the maximum length of a key is M bits, since each non-leaf node with a branching degree of 2 in the key tree is encoded into a piece of metadata (D, NL), where the depth value D needs log2 M bits to store, and the total number of left subtree leaf nodes NL needs log2N bits to store, therefore, the capacity requirement of the decoding method of the present invention for the storage device is (N - 1) * (log2M + log2N). Since the capacity requirement (N - 1) * (log2M + log2N) is fixed, it is convenient to manage. In addition, regarding the decoding operation, at most (N - 1) pieces of metadata stored in the storage device need to be decoded. Therefore, the complexity in the worst case is O(N), and the complexity in the general case is O(logN). Thus, the decoding method of the present invention is very fast and efficient. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] Figure 1 Schematic diagram of an electronic device according to an embodiment of the present invention.

[0010] Figure 2 List of multiple keys belonging to the same key group.

[0011] Figure 3 Schematic diagram of a key tree corresponding to multiple keys.

[0012] Figure 4 Flowchart of an encoding method applied to a key tree according to an embodiment of the present invention.

[0013] Figure 5 For Figure 3 The key tree shown is processed via Figure 4 Schematic diagram of an operation of the encoding process shown.

[0014] Figure 6 For Figure 3 The key tree shown is processed via Figure 4 Schematic diagram of an encoding result generated by processing the encoding process shown.

[0015] Figure 7A flowchart of a decoding method applied to a key tree according to an embodiment of the present invention.

[0016] Figure 8 The encoded result of the key tree is processed through Figure 7 The decoding process shown to generate a key index value of the input key. Detailed implementation

[0017] Figure 1 A schematic diagram of an electronic device according to an embodiment of the present invention. As Figure 1 shown, the electronic device 100 includes (but is not limited to) a processing circuit 102 and a storage device 104. For example, the processing circuit 102 can be a general purpose processor, a field programmable logic gate (FPGA), or any circuit with computing capabilities, and the storage device 104 can be an on-chip memory, an off-chip memory, or any storage component with data caching capabilities. In this embodiment, the electronic device 100 can implement the encoding method and decoding method of the present invention applied to the key tree by loading and executing program code. In addition, the electronic device 100 can be applied to manage the key trees corresponding to multiple keys in a key-value store of a distributed storage system. For example, the distributed storage system can be an object storage system, and the keys of the key-value store can be sorted and divided into multiple key groups, and each key group can contain multiple keys (i.e., a part of the keys in the key-value store) and a key tree can be constructed accordingly. The encoding method and decoding method of the present invention can be applied to the key trees corresponding to each key group.

[0018] Assume that the number of multiple keys included in the key group is N, then the key tree will have N leaf nodes. In addition, assume that the maximum length of the key is M bits, then the depth of the key tree will be M. When the keys to be managed by the electronic device 100 are from a distributed storage system (such as an object storage system), since many objects need to be identified, the length of the key may reach 256 bytes or even longer. To facilitate the description of the technical content of the encoding method and decoding method of the present invention, the following embodiments assume that the key group to be processed contains 9 keys KA, KB, KC, KD, KE, KF, KG, KH, KI (N = 9), and the maximum length of the key is 10 bits (M = 10). Figure 2 A list of 9 keys KA to KI belonging to the same key group, and Figure 3FIG. 0 is a schematic diagram of a key tree 300 corresponding to nine keys KA to KI, where leaf nodes L0 to L8 correspond to keys KA to KI respectively. In addition, in this embodiment, from left to right, the key index values of keys KA to KI are set to 0 to 8 respectively.

[0019] In order to quickly search for the desired key from these keys in the key tree, the encoding method of the present invention performs encoding processing on the key tree and generates metadata as the encoding result of the key tree, where the metadata contains index information related to these keys. Compared with encoding all non-leaf nodes in the key tree 300, the encoding method of the present invention can encode some non-leaf nodes in the key tree 300 (such as nodes with a branching degree greater than 1). In this way, when some non-leaf nodes in the key tree 300 need to be encoded and some non-leaf nodes do not need to be encoded, since the number of non-leaf nodes actually undergoing encoding processing is less than the total number of all non-leaf nodes, the encoding efficiency can be improved and the storage space required for the encoding result can be reduced. As Figure 3 , the key tree 300 is a tree structure formed according to the typical binary tree architecture of "0" on the left and "1" on the right. According to the characteristics of the binary tree itself, assuming the number of leaf nodes is n0 and the number of nodes with a branching degree of 2 is n2, then n0 = n2 + 1. In addition, only nodes with a branching degree of 2 are related to the offset of the key. Based on these observed characteristics, in an embodiment of the present invention, the encoding method can encode some non-leaf nodes in the key tree 300 (such as nodes with a branching degree of 2) to generate multiple metadata, and write the encoding result MD of the key tree 300 into the storage device 104, where the encoding result MD contains multiple metadata respectively corresponding to some non-leaf nodes (such as nodes with a branching degree of 2).

[0020] Figure 4 FIG. 9 is a flowchart of an encoding method applied to a key tree according to an embodiment of the present invention. Note that if the same result can be obtained, the steps do not necessarily have to be exactly followed Figure 4Execute in sequence according to the order shown. The encoding method is executed by the processing circuit 102. For example, the processing circuit 102 can load and execute program code to generate the encoding result MD of the key tree. The encoding method starts from the root node with a depth of 0 and sequentially determines whether each non-leaf node in the key tree needs to be encoded based on the order of depth-first traversal. When it is determined that the current non-leaf node needs to be encoded, a piece of metadata is recorded as the encoding output of this non-leaf node, and the processing of the next non-leaf node is continued according to the order of depth-first traversal. When it is determined that the current non-leaf node does not need to be encoded, the metadata of this non-leaf node does not need to be recorded, and the processing of the next non-leaf node is continued according to the order of depth-first traversal. The encoding method continuously checks the non-leaf nodes in the key tree until all non-leaf nodes with a branching degree of 2 in the key tree are encoded. Further operation instructions are as follows.

[0021] In step 402, the encoding method first processes the root node, whose depth is 0. Therefore, the depth value D of the current non-leaf node to be processed is set to 0 (i.e., D = 0), and the total number of leaf nodes LC associated with the current non-leaf node to be processed is set to N (i.e., LC = N), so that Figure 3 Taking the key tree 300 shown as an example, the total number of leaf nodes associated with the root node is the number of all keys KA to KI included in the key tree 300. Therefore, N = 9.

[0022] In step 404, the encoding method calculates the total number of left sub-Trie leaf nodes NL and the total number of right sub-Trie leaf nodes RL of the current non-leaf node located at the depth value D. Note that the total number of leaf nodes LC set in step 402 is equal to the sum of the total number of left sub-Trie leaf nodes NL and the total number of right sub-Trie leaf nodes RL obtained in step 404, that is, LC = NL + RL.

[0023] In step 406, the encoding method checks whether the total number of left sub-Trie leaf nodes NL is greater than 0 and whether the total number of right sub-Trie leaf nodes RL is greater than 0. If both the total number of left sub-Trie leaf nodes NL and the total number of right sub-Trie leaf nodes RL are greater than 0, it means that the current non-leaf node located at the depth value D is a non-leaf node with a branching degree of 2. Therefore, the encoding method will execute step 408. If only one of the total number of left sub-Trie leaf nodes NL and the total number of right sub-Trie leaf nodes RL is greater than 0, it means that the current non-leaf node located at the depth value D is a non-leaf node with a branching degree of 1. Therefore, the encoding method will execute step 410.

[0024] In step 408, since the current non-leaf node to be processed at depth value D is determined to be a non-leaf node with a branching degree of 2, encoding is performed on this non-leaf node to record a corresponding piece of metadata. The metadata will include the depth value of this non-leaf node in the key tree and the total number of leaf nodes in one of the unilateral subtrees of this non-leaf node. In this embodiment, the metadata records the depth value D and the total number of left subtree leaf nodes NL, that is, (D, NL). Additionally, for the subsequent processing of the left subtree of this non-leaf node, the encoding method updates the depth value D by adding 1 to the depth value D (that is, D = D + 1), and the total number of leaf nodes LC is updated to the total number of left subtree leaf nodes NL (that is, LC = NL); for the subsequent processing of the right subtree of this non-leaf node, the encoding method updates the depth value D by adding 1 to the depth value D (that is, D = D + 1), and the total number of leaf nodes LC is updated to the total number of right subtree leaf nodes RL (that is, LC = LC - NL = RL). Subsequently, the non-leaf nodes in the left subtree of this non-leaf node are recursively processed according to the same encoding operation. However, when the total number of leaf nodes LC in the left subtree of this non-leaf node is not greater than 1, this means that there are no non-leaf nodes with a branching degree of 2 that need to be encoded at a greater depth, so the encoding method will end the subsequent encoding process of this left subtree at this time; similarly, the non-leaf nodes in the right subtree of this non-leaf node are recursively processed according to the same encoding operation. However, when the total number of leaf nodes LC in the right subtree of this non-leaf node is not greater than 1, this means that there are no non-leaf nodes with a branching degree of 2 that need to be encoded at a greater depth, so the encoding method will end the subsequent encoding process of this right subtree at this time.

[0025] At step 410, since the current non-leaf node to be processed at depth value D is determined to be a non-leaf node with a branching degree of 1, no encoding will be performed for this non-leaf node to record the corresponding metadata. The encoding method will determine which of the total number of left sub-tree leaf nodes NL and the total number of right sub-tree leaf nodes RL is greater than 0, and determine whether this value is greater than 1. If the total number of left sub-tree leaf nodes NL is greater than 1, it means that there are still non-leaf nodes with a branching degree of 2 that need to be encoded in the left sub-tree of this non-leaf node at a greater depth. Therefore, the encoding method will execute step 412, increment the depth value D by 1 to update the depth value D (i.e., D = D + 1), and the total number of leaf nodes LC will be updated to the total number of left sub-tree leaf nodes NL (i.e., LC = NL). Subsequently, the non-leaf nodes in the left sub-tree will be recursively processed according to the same encoding operation. If the total number of right sub-tree leaf nodes RL is greater than 1, it means that there are still non-leaf nodes with a branching degree of 2 that need to be encoded in the right sub-tree of this non-leaf node at a greater depth. Therefore, the encoding method will execute step 414, increment the depth value D by 1 to update the depth value D (i.e., D = D + 1), and the total number of leaf nodes LC will be updated to the total number of right sub-tree leaf nodes RL (i.e., LC = LC - NL = RL). Subsequently, the non-leaf nodes in the right sub-tree will be recursively processed according to the same encoding operation. If the total number of left sub-tree leaf nodes NL is not greater than 1, it means that there are no non-leaf nodes with a branching degree of 2 that need to be encoded in the left sub-tree of this non-leaf node at a greater depth. Therefore, the encoding process for the left sub-tree of this non-leaf node can be skipped; similarly, if the total number of right sub-tree leaf nodes RL is not greater than 1, it means that there are no non-leaf nodes with a branching degree of 2 that need to be encoded in the right sub-tree of this non-leaf node at a greater depth. Therefore, the encoding process for the right sub-tree of this non-leaf node can be skipped.

[0026] Through Figure 4 the encoding process shown, each non-leaf node with a branching degree of 2 can be found and encoded to generate a corresponding piece of metadata as the encoding output. Please refer to Figure 5 and Figure 6 , Figure 5 which is Figure 3 the schematic diagram of the operation of processing the key tree 300 shown via Figure 4 the encoding process shown, and Figure 6 which is Figure 3 the schematic diagram of the operation of processing the key tree 300 shown via Figure 4Schematic diagram of the encoded result MD generated by processing according to the shown encoding process. At the beginning, the encoding process starts from the root node N0. In step 402, the depth value D is set to the depth of the root node N0 (D = 0), and the total number of leaf nodes LC is set to the number of all keys KA to KI in the key tree 300 (LC = 9). Then, in step 404, the total number of left sub-tree leaf nodes NL of the root node N0 is obtained as 6 (NL = 6) and the total number of right sub-tree leaf nodes RL is obtained as 3 (RL = 3). Therefore, in step 406, it is judged that both the total number of left sub-tree leaf nodes NL and the total number of right sub-tree leaf nodes RL are greater than 0. So, in step 408, the root node N0 (which is a non-leaf node) is encoded to record a piece of metadata (0, 6), that is, (D, NL) = (0, 6). For the subsequent processing of the left sub-tree of the root node N0, in step 408, the depth value D is updated to 1 (that is, D = D + 1 = 0 + 1 = 1), and the total number of leaf nodes LC is set to NL (that is, LC = NL = 6). Since the total number of leaf nodes LC is greater than 1, the left sub-tree of the root node N0 will continue to be encoded subsequently. For the subsequent processing of the right sub-tree of the root node N0, in step 408, the depth value D is updated to 1 (that is, D = D + 1 = 0 + 1 = 1), and the total number of leaf nodes LC is set to RL (that is, LC = LC - NL = RL = 3). Since the total number of leaf nodes LC is greater than 1, the right sub-tree of the root node N0 will continue to be encoded subsequently.

[0027] Based on the order of depth-first traversal, the encoding method will first process the left sub-tree of the root node N0 subsequently. Since in step 408, the depth value D has been updated to 1 for the left sub-tree of the root node N0, the first node to be processed in the left sub-tree of the root node N0 is N1. In step 404, the total number of left sub-tree leaf nodes NL of the node N1 is obtained as 2 (NL = 2) and the total number of right sub-tree leaf nodes RL is obtained as 4 (RL = 4). Therefore, in step 406, it is judged that both the total number of left sub-tree leaf nodes NL and the total number of right sub-tree leaf nodes RL are greater than 0. So, in step 408, the node N1 (which is a non-leaf node) is encoded to record a piece of metadata (1, 2), that is, (D, NL) = (1, 2). For the subsequent processing of the left sub-tree of the node N1, in step 408, the depth value D is updated to 2 (that is, D = D + 1 = 1 + 1 = 2), and the total number of leaf nodes LC is set to NL (that is, LC = NL = 2). Since the total number of leaf nodes LC is greater than 1, the left sub-tree of the root node N1 will continue to be encoded subsequently. For the subsequent processing of the right sub-tree of the node N1, in step 408, the depth value D is updated to 2 (that is, D = D + 1 = 1 + 1 = 2), and the total number of leaf nodes LC is set to RL (that is, LC = LC - NL = RL = 4). Since the total number of leaf nodes LC is greater than 1, the right sub-tree of the root node N1 will continue to be encoded subsequently.

[0028] Based on the order of depth - first traversal, the encoding method will subsequently process the left subtree of node N1. Since step 408 has updated the depth value D to 2 for the left subtree of node N1, the first node to be processed in the left subtree of node N1 is N2. Step 404 obtains that the total number of left - leaf nodes NL of node N2 is 2 (NL = 2) and the total number of right - leaf nodes RL is 0 (RL = 0). Therefore, step 406 determines that only the total number of left - leaf nodes NL is greater than 0 among the total number of left - leaf nodes NL and the total number of right - leaf nodes RL. Thus, step 410 determines that the subsequent process will process the left subtree of node N2 and does not need to process the right subtree of node N2. Therefore, for the subsequent processing of the left subtree of node N2, step 412 updates the depth value D to 3 (i.e., D = D + 1 = 2+1 = 3), and sets the total number of leaf nodes LC to NL (i.e., LC = NL = 2). Since the total number of leaf nodes LC is greater than 1, the left subtree of the root node N2 will be continuously encoded and processed subsequently.

[0029] Based on the order of depth - first traversal, the encoding method will subsequently process the left subtree of node N2. Since step 408 has updated the depth value D to 3 for the left subtree of node N2, the first node to be processed in the left subtree of node N2 is N3. Step 404 obtains that the total number of left - leaf nodes NL of node N3 is 2 (NL = 2) and the total number of right - leaf nodes RL is 0 (RL = 0). Therefore, step 406 determines that only the total number of left - leaf nodes NL is greater than 0 among the total number of left - leaf nodes NL and the total number of right - leaf nodes RL. Thus, step 410 determines that the subsequent process will process the left subtree of node N3 and does not need to process the right subtree of node N3. Therefore, for the subsequent processing of the left subtree of node N3, step 412 updates the depth value D to 4 (i.e., D = D + 1 = 3+1 = 4), and sets the total number of leaf nodes LC to NL (i.e., LC = NL = 2). Since the total number of leaf nodes LC is greater than 1, the left subtree of the root node N2 will be continuously encoded and processed subsequently.

[0030] Similarly, since nodes N4 - N8 are all nodes with a branching degree of 1 and only have left subtrees, for the subsequent processing of the left subtree of node N4, step 412 updates the depth value D to 5, and sets the total number of leaf nodes LC to 2; for the subsequent processing of the left subtree of node N5, step 412 updates the depth value D to 6, and sets the total number of leaf nodes LC to 2; for the subsequent processing of the left subtree of node N6, step 412 updates the depth value D to 7, and sets the total number of leaf nodes LC to 2; for the subsequent processing of the left subtree of node N7, step 412 updates the depth value D to 8, and sets the total number of leaf nodes LC to 2; and for the subsequent processing of the left subtree of node N8, step 412 updates the depth value D to 9, and sets the total number of leaf nodes LC to 2.

[0031] Based on the order of depth - first traversal, the encoding method will subsequently process the left subtree of node N8. Since the depth value D has been updated to 9 for the left subtree of node N8 in step 408, the first node to be processed in the left subtree of node N8 is N9. In step 404, the total number of left - leaf nodes NL of node N9 is obtained as 1 (NL = 1) and the total number of right - leaf nodes RL of node N9 is obtained as 1 (RL = 1). Therefore, in step 406, it is determined that both the total number of left - leaf nodes NL and the total number of right - leaf nodes RL are greater than 0. Thus, step 408 will encode node N9 (which is a non - leaf node) to record a piece of metadata (9, 1), that is, (D, NL)=(9, 1). For the subsequent processing of the left subtree of node N9, step 408 updates the depth value D to 10 (i.e., D = D + 1=9 + 1 = 10), and sets the total number of leaf nodes LC to NL (i.e., LC = NL = 1). Since the total number of leaf nodes LC is not greater than 1, the processing of the left subtree of node N9 will be directly skipped subsequently. For the subsequent processing of the right subtree of node N9, step 408 updates the depth value D to 9 (i.e., D = D + 1=9 + 1 = 10), and sets the total number of leaf nodes LC to RL (i.e., LC = LC - NL = RL = 1). Since the total number of leaf nodes LC is not greater than 1, the processing of the right subtree of node N9 will be directly skipped subsequently.

[0032] Based on the order of depth - first traversal, the encoding method will subsequently process the right subtree of node N1, the left subtree of node N10, the right subtree of node N10, the right subtree of node N0, and the right subtree of node N13 in sequence. Since those skilled in the art can easily know the subsequent encoding operations based on the content of the above - mentioned specification paragraphs, for the sake of brevity, the description of the subsequent encoding operations will not be elaborated here.

[0033] According to Figure 4 the shown process, the encoding method will encode the non - leaf nodes N0, N1, N9, N10, N11, N12, N13, N14 with a branching degree of 2 in sequence based on the order of depth - first traversal, and generate corresponding metadata D0, D1, D2, D3, D4, D5, D6, D7, as Figure 6As shown, the encoded data MD of the key tree 300 will contain 8 pieces of metadata D0 to D7. Each piece of metadata records the depth value D and the total number of left child leaf nodes NL. Compared with the data volume of multiple keys KA to KI in the key tree 300 (for example, the length of each key may reach 256 bytes or even longer), the data volume of the encoded data MD is relatively small (for example, the depth value D and the total number of left child leaf nodes NL in each piece of metadata can be recorded using fewer bits). In other words, compared with storing multiple keys KA to KI in the storage device 104 to search for the input key, storing the encoded data MD in the storage device 104 to search for the input key only requires a smaller storage space. Additionally, as mentioned before, based on the characteristics of the binary tree itself, assuming the number of leaf nodes is n0 and the number of nodes with a branching degree of 2 is n2, then n0 = n2 + 1. Therefore, when the number of multiple keys KA to KI in the key tree 300 is known, the number of multiple pieces of metadata D0 to D7 contained in the encoded data MD is also known. Thus, the data volume of the encoded data MD can be known in advance to plan the storage space of the storage device 104.

[0034] When the processing circuit 102 receives an input key K_IN from a distributed storage system (such as an object storage system), it can perform a decoding operation based on the input key K_IN and the encoded data MD stored in the storage device 104 to obtain the key index value corresponding to the input key K_IN, in order to Figure 3 Taking the key tree 300 shown as an example, from left to right, the key index values of the keys KA to KI are 0 to 8 respectively. If the key index value finally obtained by the decoding operation is K_IDX, it means that the input key K_IN may be the key among the keys KA to KI that has this key index value K_IDX.

[0035] Figure 7 It is a flowchart of a decoding method applied to a key tree according to an embodiment of the present invention. Note that if the same result can be obtained, the steps do not necessarily have to be exactly followed Figure 7Execute in sequence according to the order shown. The decoding method is executed by the processing circuit 102. For example, the processing circuit 102 can load and execute program code to obtain the decoding result (i.e., the key index value K_IDX corresponding to the input key K_IN). The decoding method reads one piece of metadata from the multiple pieces of metadata included in the encoded result MD of the key tree from the storage device 104, where the piece of metadata includes a depth value of a corresponding non-leaf node in the key tree; according to the bit value of a bit in the input key K_IN corresponding to the depth value, selectively update a key index value; and according to the total number of leaf nodes of a unilateral subtree of the corresponding non-leaf node indicated by the bit, determine whether the decoding operation of the key index value ends. If it is determined that the decoding operation of the key index value has not ended, then another piece of metadata will be read from the storage device 104 to continue decoding. The decoding method continuously reads the metadata in the encoded result MD until the decoding operation of the key index value ends. Further operation descriptions are as follows.

[0036] In step 702, the decoding method first initializes some parameters, sets the key index value K_IDX to the initial value 0 (K_IDX = 0), sets the current decoding node position D_PTR to the initial value 0 (D_PTR = 0), and sets the total number of leaf nodes LC to the initial value N (LC = N). Taking Figure 3 the key tree 300 shown as an example, the total number of leaf nodes associated with the root node is the total number of all keys included in the key tree 300. Therefore, the initial value N of the total number of leaf nodes LC is equal to 9 (N = 9). Additionally, taking Figure 6 the encoded result MD of the key tree 300 shown as an example, the decoding node positions D_PTR corresponding to the multiple pieces of metadata D0 to D7 are 0 to 7 respectively. Therefore, the decoding method starts decoding from the metadata D0 with the decoding node position D_PTR = 0.

[0037] In step 704, the decoding method determines whether the total number of leaf nodes LC is equal to 1. If the total number of leaf nodes LC is equal to 1, it means that the corresponding leaf node has been found in the key tree based on the input key K_IN. Therefore, the decoding operation of the key index value can end. If the total number of leaf nodes LC is greater than 1, this represents that the corresponding leaf node has not been found in the key tree based on the input key K_IN. Therefore, the decoding operation of the key index value still needs to continue.

[0038] In step 706, the decoding method decodes based on the current decoding node position D_PTR to read one piece of metadata from the multiple pieces of metadata included in the encoded result MD of the key tree from the storage device 104. As mentioned above, each piece of metadata records the depth value D and the total number of left child leaf nodes NL. The depth value D obtained by decoding the metadata in step 706 is used in step 708, and the total number of left child leaf nodes NL obtained by decoding the metadata in step 706 is used in step 712 or step 714 based on the judgment result of step 710.

[0039] In step 708, the decoding method reads the bit value of the bit corresponding to the depth value D from the input key K_IN.

[0040] In step 710, the decoding method checks whether the bit value of the bit corresponding to the depth value D in the input key K_IN is 1 or 0. If it is 0, step 712 is executed. If it is 1, step 714 is executed.

[0041] In step 712, the decoding method updates the total number of leaf nodes LC to the total number of left child leaf nodes NL (i.e., LC = NL), and in addition, increments the current decoding node position D_PTR by 1 (i.e., D_PTR = D_PTR + 1). In addition, the current key index value K_IDX remains unchanged. The decoding process then returns to step 704 to determine whether the decoding operation of the key index value K_IDX is complete.

[0042] In step 714, the decoding method updates the total number of leaf nodes LC to the total number of right child leaf nodes (i.e., LC = LC - NL = RL), and in addition, adds the total number of left child leaf nodes NL to the current decoding node position D_PTR (i.e., D_PTR = D_PTR + NL). In addition, the current key index value K_IDX is also incremented by the total number of left child leaf nodes NL (i.e., K_IDX = K_IDX + NL). The decoding process then returns to step 704 to determine whether the decoding operation of the key index value K_IDX is complete.

[0043] When it is determined in step 704 that the decoding operation of the key index value K_IDX has ended, the decoding method then proceeds to step 716 to verify the input key K_IN. Since the data volume of multiple keys KA to KI in the key tree 300 is large, in practice, it will be stored in an external storage device of the electronic device 100, such as a traditional hard disk or a solid-state drive. In step 716, the decoding method will obtain the storage address ADDR of the corresponding key according to the finally decoded key index value K_IDX, and then read the corresponding key recorded at the storage address ADDR from the external storage device, and then compare the input key K_IN with the corresponding key obtained from the external storage device. If the two match, it means that the search for the input key K_IN is correct, so the value paired with the input key K_IN can be read from the external storage device subsequently. If the two do not match, it means that the input key K_IN does not belong to the key tree 300.

[0044] Through Figure 7 the decoding process shown, the key index value K_IDX of the input key K_IN can be determined from the index information provided by the encoded data MD of the key tree 300. Please refer to Figure 5 and Figure 8 , Figure 8 which is a schematic diagram of the encoded result MD of the key tree 300 being processed through Figure 7 the decoding process shown to generate the key index value K_IDX of the input key K_IN. Assume that the input key K_IN to be decoded is the key KF (i.e., K_IN = 0101000110). At the beginning, in step 702, the key index value K_IDX is set to 0 respectively, the current decoding node position D_PTR is set to 0, and the total number of leaf nodes LC is set to the initial value 9. Since the total number of leaf nodes LC is not equal to 1 at this time, in step 706, the metadata D0 is decoded based on the current decoding node position D_PTR to obtain the depth value 0 (D = 0) and the total number of left subtree leaf nodes 6 (NL = 6). In step 708, the bit value of the bit of the input key K_IN at the depth value 0 is obtained as 0. Therefore, in step 710, it is determined that step 712 will be executed subsequently. So in step 712, the key index value K_IDX remains 0, the current decoding node position D_PTR is updated to 1 (D_PTR = D_PTR + 1), and the total number of leaf nodes LC is updated to 6 (LC = NL).

[0045] The decoding process then returns to step 704. Since the total number of leaf nodes LC still does not equal 1 at this time, step 706 decodes the metadata D1 based on the current decoding node position D_PTR to obtain the depth value 1 (D = 1) and the total number of left subtree leaf nodes 2 (NL = 2). Step 708 obtains that the bit value of the input key K_IN at the depth value 1 is 1. Therefore, step 710 determines that step 714 will be executed subsequently. Thus, step 714 will update the key index value K_IDX to 2 (K_IDX = K_IDX + 2), update the current decoding node position D_PTR to 3 (D_PTR = D_PTR + 2), and update the total number of leaf nodes LC to 4 (LC = LC - NL).

[0046] The decoding process then returns to step 704. Since the total number of leaf nodes LC still does not equal 1 at this time, step 706 decodes the metadata D3 based on the current decoding node position D_PTR to obtain the depth value 3 (D = 3) and the total number of left subtree leaf nodes 2 (NL = 2). Step 708 obtains that the bit value of the input key K_IN at the depth value 3 is 1. Therefore, step 710 determines that step 714 will be executed subsequently. Thus, step 714 will update the key index value K_IDX to 4 (K_IDX = K_IDX + 2), update the current decoding node position D_PTR to 5 (D_PTR = D_PTR + 2), and update the total number of leaf nodes LC to 2 (LC = LC - NL).

[0047] The decoding process then returns to step 704. Since the total number of leaf nodes LC still does not equal 1 at this time, step 706 decodes the metadata D5 based on the current decoding node position D_PTR to obtain the depth value 7 (D = 7) and the total number of left subtree leaf nodes 1 (NL = 1). Step 708 obtains that the bit value of the input key K_IN at the depth value 7 is 1. Therefore, step 710 determines that step 714 will be executed subsequently. Thus, step 714 will update the key index value K_IDX to 5 (K_IDX = K_IDX + 1), update the current decoding node position D_PTR to 6 (D_PTR = D_PTR + 1), and update the total number of leaf nodes LC to 1 (LC = LC - NL).

[0048] The decoding process then returns to step 704. Since the total number of leaf nodes LC already equals 1 at this time, the decoding operation of the key index value K_IDX ends. Since the key index value K_IDX is 5 at this time, the final key index value K_IDX of the input key K_IN obtained by the decoding process is 5.

[0049] In the above encoding operation, each piece of metadata records the depth value and the total number of left subtree leaf nodes. However, this is only for illustrative purposes and is not used as a limitation of the present invention. In another embodiment, each piece of metadata can be changed to record the depth value and the total number of right subtree leaf nodes, and the decoding operation is correspondingly modified, and the purpose of determining the key index value of the input key can also be achieved. Such a design change also falls within the scope of the present invention.

[0050] Regarding the encoding operation, assume that the number of keys included in the key group is N and the maximum length of the key is M bits. Since each non-leaf node with a branching degree of 2 in the key tree will encode to generate a piece of metadata (D, NL), where the depth value D requires log2M bits to store, and the total number of left subtree leaf nodes NL requires log2N bits to store. Therefore, the temporary storage capacity requirement of the decoding method of the present invention for the storage device 104 is (N - 1) * (log2M + log2N). Since the temporary storage capacity (N - 1) * (log2M + log2N) is fixed, it is also convenient for management. In addition, regarding the decoding operation, at most (N - 1) pieces of metadata stored in the storage device 104 need to be decoded. Therefore, the complexity in the worst case is O(N), and the complexity in the general case is O(logN). Therefore, the decoding method of the present invention is very fast and efficient.

[0051] The above are only the preferred embodiments of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention shall fall within the scope of the present invention.

[0052]

Symbol Explanation

[0053] 100: Electronic device

[0054] 102: Processing circuit

[0055] 104: Storage device

[0056] 402, 404, 406, 408, 410, 412, 414: Encoding steps

[0057] 702, 704, 706, 708, 710, 712, 714, 716: Decoding steps

[0058] 300: Key tree

[0059] K_IN: Input key

[0060] ADDR: Storage address

[0061] MD: Encoded data

[0062] K_IDX: Key index value

[0063] D_PTR: Decoding node position

[0064] LC: Total number of leaf nodes

[0065] NL: Total number of leaf nodes in the left subtree

[0066] RL: Total number of leaf nodes in the right subtree

Claims

1. An encoding method applied to a trie tree, comprising: The processing circuit reduces the storage space of a storage device required by the encoding result and improves the encoding efficiency through the following steps: In response to including a plurality of first non-leaf nodes with a branch degree equal to 1 and second non-leaf nodes with a branch degree greater than 1, generate multiple metadata by applying encoding only to the plurality of second non-leaf nodes of the key tree; And Writing the encoding result of the trie tree into the storage device, where the encoding result respectively includes the multiple pieces of metadata corresponding to the multiple second non-leaf nodes; Wherein, The step of applying encoding only to the multiple second non-leaf nodes of the trie tree and storing the encoding result of the trie tree into the storage device is executed by the processing circuit; Wherein the storage device is an on-chip memory or an off-chip memory, and the processing circuit is a general-purpose processor or a field programmable gate array.

2. The encoding method according to claim 1, wherein the branching degree of each second non-leaf node among the multiple second non-leaf nodes is equal to 2.

3. The encoding method according to claim 1, wherein each piece of metadata among the multiple pieces of metadata includes a depth value of the corresponding non-leaf node in the trie tree.

4. The encoding method according to claim 1, wherein each piece of metadata among the multiple pieces of metadata includes the total number of leaf nodes of a unilateral subtree of the corresponding non-leaf node.

5. The encoding method according to claim 4, wherein the unilateral subtree is a left subtree.

6. The encoding method according to claim 1, wherein the multiple pieces of metadata are sequentially stored in the storage device in the order of depth-first traversal of the second non-leaf nodes.

7. The encoding method according to claim 1, wherein the trie tree corresponds to multiple keys in a key-value database.

8. A decoding method applied to a trie tree, comprising: The processing circuit reduces the storage space of a storage device required by the encoding result and improves the encoding efficiency through the following steps: Reading, by the processing circuit, one piece of metadata included in an encoding result of the trie tree from the storage device, where the piece of metadata includes a depth value of a corresponding non-leaf node in the trie tree, the trie tree includes multiple first non-leaf nodes with a branching degree equal to 1 and second non-leaf nodes with a branching degree greater than 1, and the encoding result is generated by applying encoding only to the multiple second non-leaf nodes of the trie tree, the storage device is an on-chip memory or an off-chip memory, and the processing circuit is a general-purpose processor or a field programmable gate array; Selectively updating a key index value by the processing circuit according to a bit value of a bit corresponding to the depth value in an input key; And Judging, by the processing circuit, whether the decoding operation of the key index value ends according to the total number of leaf nodes of a unilateral subtree of the corresponding non-leaf node indicated by the bit; After the decoding operation of the key index value ends, reading, by the processing circuit, a corresponding key according to the key index value, and comparing, by the processing circuit, the corresponding key with the input key to determine whether the input key matches the corresponding key; In response to the input key matching the corresponding key, reading, by the processing circuit, a value paired with the input key according to the storage address corresponding to the corresponding key; And In response to the input key not matching the corresponding key, the processing circuit determines that the input key does not belong to the key tree.

9. The decoding method according to claim 8, wherein the piece of metadata further includes the total number of leaf nodes of a unilateral subtree of the corresponding non-leaf node, and the step of selectively updating the key index value includes: When the bit value of the bit is equal to a first bit value, keeping the key index value unchanged; and When the bit value of the bit is equal to a second bit value, updating the key index value by adding the total number of leaf nodes of the unilateral subtree of the corresponding non-leaf node to the key index value.

10. The decoding method according to claim 9, wherein the first bit value is 0, and the second bit value is 1.

11. The decoding method according to claim 8, wherein the multiple pieces of metadata are sequentially stored in the storage device, and the decoding method further includes: After determining that the decoding operation of the key index value has not ended, reading, according to the order of the multiple pieces of metadata, a piece of metadata immediately following the piece of metadata from the storage device.

12. The decoding method according to claim 8, wherein the multiple pieces of metadata are sequentially stored in the storage device, the piece of metadata further includes the total number of leaf nodes of a unilateral subtree of the corresponding non-leaf node, and the decoding method further includes: After determining that the decoding operation of the key index value has not ended, reading another piece of metadata from the multiple pieces of metadata from the storage device according to the order of the piece of metadata in the multiple pieces of metadata and the total number of leaf nodes of the unilateral subtree of the corresponding non-leaf node.

13. The decoding method according to claim 12, wherein the order of the another piece of metadata in the multiple pieces of metadata is equal to the order in the multiple pieces of metadata plus the total number of leaf nodes of the unilateral subtree of the corresponding non-leaf node.

14. The decoding method according to claim 8, wherein the key tree corresponds to multiple keys in a key value database.

15. An electronic device, comprising: A storage device; and A processing circuit arranged to reduce the storage space of a storage device required by an encoding result and improve the encoding efficiency through the following steps: In response to a key tree including a plurality of first non-leaf nodes equal to 1 and second non-leaf nodes greater than 1, generating multiple pieces of metadata by applying encoding only to the plurality of second non-leaf nodes of the key tree; and Writing the encoding result of the key tree into the storage device, wherein the encoding result includes the multiple pieces of metadata respectively corresponding to the plurality of second non-leaf nodes, wherein the storage device is an on-chip memory or an off-chip memory, and the processing circuit is a general-purpose processor or a field programmable gate array.

16. An electronic device, comprising: A storage device; and A processing circuit arranged to reduce the storage space of a storage device required by an encoding result and improve the encoding efficiency through the following steps: Read one piece of metadata from among multiple pieces of metadata included in an encoding result of a key tree, where the piece of metadata includes a depth value of a corresponding non-leaf node in the key tree, the key tree includes multiple first non-leaf nodes with a branching degree equal to 1 and second non-leaf nodes with a branching degree greater than 1, and the encoding result is generated by applying encoding only to the multiple second non-leaf nodes of the key tree; Among them, The processing circuit is further arranged to: Selectively update a key index value according to a bit value of a bit corresponding to the depth value in an input key; Judge whether the decoding operation of the key index value ends according to the total number of leaf nodes of a unilateral subtree of the corresponding non-leaf node indicated by the bit; After the decoding operation of the key index value ends, the processing circuit reads a corresponding key according to the key index value, and the processing circuit compares the corresponding key with the input key to determine whether the input key matches the corresponding key; In response to the input key matching the corresponding key, the processing circuit reads a value paired with the input key according to a storage address corresponding to the corresponding key; And In response to the input key not matching the corresponding key, the processing circuit determines that the input key does not belong to the key tree.

Citation Information

Patent Citations

  • Online radix tree compression with key sequence skip

    US20150248448A1

  • Offline compression for limited sequence length radix tree

    US20150324401A1