Digital circuit implementation method based on binary tree, digital circuit and storage medium
By adopting binary tree-based storage method in digital circuits, the problem of low data processing efficiency of digital circuits is solved, and rapid insertion, deletion and search operations are realized, data processing efficiency is improved, and the tree height is kept small by balancing binary trees, which is improved Overall data operation efficiency.
Patent Information
- Application Number
- CN202311586866.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-24
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2043-11-24
AI Technical Summary
Existing storage methods in digital circuits, such as random memory, linked lists or hash dictionaries, lead to low data processing efficiency and high time complexity, which cannot meet the needs of rapid insertion, deletion and search.
采用基于二叉树的数字电路实现方法,通过进程模块接收机器指令,解码操作符和数据,生成根指针请求,结合内存模块存储二叉树数据,执行插入、删除和查询操作,利用二叉树的平衡性保持树高度小,提高数据处理效率。
Through the binary tree storage method, the processing time of insertion, deletion and search operations is significantly shortened, the data processing efficiency of digital circuits is improved, and by maintaining a balanced binary tree, the tree height is ensured to be relatively small, further improving data operation efficiency.
Smart Images

Figure CN117785282B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a digital circuit implementation method based on a binary tree, a digital circuit and a storage medium. Background Art
[0002] Binary tree is a common and mature data structure. In the source code of the operating system, trees and forests are used to build file systems. Common file management systems such as Windows and Linux use tree structures. In the compilation system, especially in the source code of the C compiler, the in-order traversal form of the binary tree is used to store expressions in the C language. In the database, the binary tree is widely used in the underlying implementation of the database search function in the software. By using the tree structure to store and organize data, it has efficient addition, deletion and search operations. However, in digital circuit hardware, binary tree technology has not been widely used.
[0003] At present, traditional digital circuit storage methods include storing data in random access memory, or using common data structures such as linked lists or hash dictionaries. However, whether storing data in random access memory or using linked lists or hash dictionaries, the time complexity is much higher than the arrangement method using binary trees. Data operations take a long time, resulting in low data processing efficiency in digital circuits. Summary of the invention
[0004] In view of this, the embodiments of the present invention provide a digital circuit implementation method based on a binary tree, a digital circuit and a storage medium to eliminate or improve one or more defects existing in the prior art, and to solve the problem of low data processing efficiency of digital circuits.
[0005] One aspect of the present invention provides a method for implementing a digital circuit based on a binary tree, which is applied to a digital circuit based on a binary tree algorithm, wherein the digital circuit includes a process module, a root node module, and a memory module; the method includes the following steps:
[0006] The process module receives the machine instruction and decodes the machine instruction to obtain the operator, operation data and root pointer index; the operator is used to indicate the operation type, which includes data insertion, data deletion or data query;
[0007] The process module uses the root pointer index as a parameter to generate a root pointer read request and send it to the root node module, so that after receiving the root pointer read request, the root node module obtains the root pointer index, reads the root pointer according to the root pointer index and returns it to the process module; the root pointer is used to indicate the location information of the root node of the binary tree;
[0008] When the process module receives the root pointer, it uses the root pointer as a parameter to generate a root node data read request and sends it to the memory module, so that after receiving the root pointer, the memory module reads the root node data of the root node of the binary tree based on the root pointer and returns it to the process module;
[0009] When receiving the root node data, the process module performs corresponding data operations based on the root node data and the operation data according to the operation type indicated by the operator.
[0010] Optionally, in the case where the operation type indicated by the operator is data insertion, the digital circuit further comprises a storage management module;
[0011] When the process module receives the root node data, based on the root node data and the operation data, according to the operation type indicated by the operator, the corresponding data operation is performed, including:
[0012] Take the root node as the current node and the root node data as the current node data;
[0013] Determine whether the current node data is valid according to the current node data;
[0014] When the current node is valid, the operation data is compared with the current node data to obtain the size relationship between the operation data and the current node data;
[0015] Based on the first size relationship, determine a target child node among the child nodes of the current node;
[0016] In the case where the target child node is invalid, a first signal instruction is sent to the storage management module through the process module, so that after receiving the first signal instruction, the storage management module performs memory allocation through the first function and returns the starting address of the allocated memory space to the process module;
[0017] When the process module receives the starting address, it sends the starting address and the operation data to the memory module, so that the memory module stores the operation data according to the starting address after receiving the starting address and the operation data, thereby storing the operation data in the target child node.
[0018] Optionally, when the target child node is valid, the method further includes:
[0019] Get the child node data of the target child node;
[0020] Set the target child node as the current node and the child node data as the current node data;
[0021] The step of comparing the operation data with the current node data to obtain a size relationship between the operation data and the current node data is performed.
[0022] Optionally, the child nodes of the current node include a right child node and / or a left child node; based on the size relationship, determining the target child node from the child nodes of the current node includes:
[0023] When the operation data is greater than the current node data, the right child node is used as the target child node;
[0024] When the operation data is smaller than the current node data, the left child node is used as the target child node.
[0025] Optionally, in the case where the operation type indicated by the operator is data deletion, the digital circuit further includes a storage management module;
[0026] When the process module receives the root node data, based on the root node data and the operation data, according to the operation type indicated by the operator, the corresponding data operation is performed, including:
[0027] Take the root node as the current node and the root node data as the current node data;
[0028] Determine whether the current node data is valid according to the current node data;
[0029] When the current node is valid, the operation data is compared with the current node data to obtain the size relationship between the operation data and the current node data;
[0030] When the size relationship indicates that the operation data is equal to the current node data, the current node is deleted through the process module, and a second signal instruction is sent to the memory management module, so that the storage management module reclaims memory through a second function after receiving the second signal instruction.
[0031] Optionally, when the operation type indicated by the operator is data query, when the process module receives the root node data, based on the root node data and the operation data, according to the operation type indicated by the operator, a corresponding data operation is performed, including:
[0032] Take the root node as the current node and the root node data as the current node data;
[0033] Determine whether the current node data is valid according to the current node data;
[0034] When the current node is valid, the operation data is compared with the current node data to obtain the size relationship between the operation data and the current node data;
[0035] In the case where the size relationship indicates that the operation data is equal to the current node data, the current node data is determined as the query data, and the query data is returned to the designated device.
[0036] Optionally, when the current node is invalid, the method further includes:
[0037] Generate query error messages;
[0038] Generate a query receipt based on the query error information and return it to the specified device.
[0039] Another aspect of the present invention provides a binary tree-based digital circuit, which is applied to the above-mentioned binary tree-based digital circuit implementation method, comprising:
[0040] The process module is used to: receive machine instructions and decode the machine instructions to obtain operators, operation data and root pointer index; the operator is used to indicate the operation type, and the operation type includes data insertion, data deletion or data query; take the root pointer index as a parameter, generate a root pointer read request and send it to the root node module;
[0041] The root node module is used to: after receiving a root pointer read request, obtain a root pointer index, read the root pointer according to the root pointer index and return it to the process module; the root pointer is used to indicate the location information of the root node of the binary tree;
[0042] The process module is further used for: when receiving the root pointer, using the root pointer as a parameter, generating a root node data read request and sending it to the memory module;
[0043] The memory module is used to: after receiving the root pointer, read the root node data of the root node of the binary tree based on the root pointer and return it to the process module;
[0044] The process module is also used to: when receiving the root node data, based on the root node data and the operation data, perform corresponding data operations according to the operation type indicated by the operator.
[0045] Optionally, the digital circuit further includes a memory management module;
[0046] The process module is further used to: during the data insertion process, after determining the binary tree node for inserting the operation data, generate a first signal instruction and send it to the memory management module;
[0047] The memory management module is used to: after receiving the first signal instruction, perform memory allocation through the first function, and return the starting address of the allocated memory space to the process module;
[0048] or,
[0049] The process module is further used to: after executing the data deletion, send a second signal instruction to the memory management module;
[0050] The storage management module is used to: after receiving the second signal instruction, reclaim the memory through the second function.
[0051] Another aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the program is executed by a processor, the steps of the above-mentioned binary tree-based digital circuit implementation method are implemented.
[0052] The digital circuit implementation method based on binary tree, digital circuit and storage medium of the present invention receive machine instructions through process module, and decode the machine instructions to obtain operators, operation data and root pointer index; the process module uses the root pointer index as a parameter to generate a root pointer read request and send it to the root node module, so that after receiving the root pointer read request, the root node module obtains the root pointer index, reads the root pointer according to the root pointer index and returns it to the process module; when receiving the root pointer, the process module uses the root pointer as a parameter, generates a root node data read request and sends it to the memory module, so that after receiving the root pointer, the memory module reads the root node data of the root node of the binary tree based on the root pointer and returns it to the process module ; When the process module receives the root node data, it performs the corresponding data operation based on the root node data and the operation data according to the operation type indicated by the operator; it can solve the problem of low efficiency of digital circuit data processing; the binary tree operation is performed by the process module, the root node module stores the root node execution, and the memory module stores the binary tree data, so as to realize the storage of data in the digital circuit by the binary tree method, avoid using random access memory to store data, linked list or hash dictionary storage method, in the digital circuit, so that the processing time of insertion, deletion and search operations is shortened, and the efficiency of digital circuit data processing is improved; at the same time, by maintaining the balance of the binary tree, it can ensure that the height of the tree is relatively small, further improving the efficiency of digital circuit data operations.
[0053] Furthermore, in a binary tree, by comparing node values, the subtree where the data is located can be quickly determined, thereby reducing the number of traversals and further improving the efficiency of digital circuit data operations.
[0054] Additional advantages, purposes, and features of the present invention will be described in part in the following description, and will become apparent to those skilled in the art after studying the following, or may be learned from the practice of the present invention. The purposes and other advantages of the present invention may be achieved and obtained by the structures specifically indicated in the specification and the accompanying drawings.
[0055] Those skilled in the art will appreciate that the objectives and advantages that can be achieved with the present invention are not limited to the above specific description, and the above and other objectives that can be achieved by the present invention will be more clearly understood from the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of this application, and do not constitute a limitation of the present invention.
[0057] Figure 1 It is a structural schematic diagram of a binary tree-based digital circuit in one embodiment of the present invention;
[0058] Figure 2 A schematic diagram of a binary tree data structure in one embodiment of the present invention;
[0059] Figure 3 The figure is a flow chart of a method for realizing a digital circuit based on a binary tree in another embodiment of the present invention. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments and the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0061] It should also be noted that, in order to avoid obscuring the present invention due to unnecessary details, only structures and / or processing steps closely related to the solutions according to the present invention are shown in the accompanying drawings, while other details that are not closely related to the present invention are omitted.
[0062] It should be emphasized that the term “include / comprises” when used herein refers to the presence of features, elements, steps or components, but does not exclude the presence or addition of one or more other features, elements, steps or components.
[0063] It should also be noted that, unless otherwise specified, the term “connection” herein may refer not only to a direct connection but also to an indirect connection involving an intermediate.
[0064] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. In the accompanying drawings, the same reference numerals represent the same or similar components, or the same or similar steps.
[0065] The following is an introduction to the binary tree-based digital circuit provided by this application.
[0066] like Figure 1 The figure shows a schematic diagram of a binary tree-based digital circuit structure provided by an embodiment of the present application. Figure 1 It can be seen that the binary tree-based digital circuit at least includes: a process module 110 , a root node module 120 and a memory module 130 .
[0067] Among them, the process module 110 is a processor for performing binary tree operations or a customized digital logic circuit for performing binary tree operations; the process module 110 can also be an integrated circuit chip, including a processor core, an operation unit, a logic unit, etc.
[0068] In this embodiment, the process module 110 is used to perform operations such as instruction decoding, branch execution, and receipt construction.
[0069] Instruction decoding refers to parsing the input operator (opcode) and operation data (data) and determining the specific operation to be performed; among them, the operator is used to indicate the operation type, which includes data insertion, data deletion or data query; the operation data refers to the data required to perform the binary tree operation.
[0070] Branch execution refers to executing different operation branches such as data insertion, data deletion or data query according to the operators and operation data obtained by instruction decoding.
[0071] Receipt construction means that after the operation branch is executed, the process module 110 constructs a receipt for external output according to the execution result, and returns the execution result to the designated device. The designated device includes a pre-designated electronic device, including but not limited to a mobile phone, a tablet computer or a server, etc. This embodiment does not limit the type of the designated device.
[0072] The root node module 120 is a pseudo dual-port random access memory (Pseudo Dual-Port RAM) for storing the root node pointer of the binary tree.
[0073] After parsing the input operator, the process module 110 obtains the index contained in the operator, and uses the index as the access address of the root node access module 120 to read the root node pointer for subsequent binary tree operation execution.
[0074] When the process module 110 uses the root node pointer to perform a binary tree operation (such as data insertion or data deletion) on the root node, the content of the original root node pointer will be changed.
[0075] When the binary tree operation performed by the process module 110 is data insertion, in the case where the inserted operation data needs to become a new root node, the root node pointer needs to be updated so that the updated root node pointer points to the new root node.
[0076] When the binary tree operation performed by the process module 110 is data deletion, in the case where the deleted node is the current root node, after deleting the root node, a new node needs to be selected as the new root node, and the root node pointer needs to be updated so that the updated root node pointer points to the new root node.
[0077] In this embodiment, the amount of data that the root node module 120 can store is determined by the maximum number of binary tree storage structures that can be supported by the binary tree-based digital circuit.
[0078] Among them, the maximum number of binary tree storage structures that can be supported by a binary tree-based digital circuit is determined by multiple factors, including but not limited to memory size, data structure design, and algorithm implementation.
[0079] Specifically, the RAM depth of the root node module 120 can be expressed by the following formula:
[0080]
[0081] In the formula, N is the maximum number of binary tree storage structures supported by the binary tree-based digital circuit, and D is the RAM depth of the root node module 120.
[0082] Specifically, in this embodiment, the process module 110 is used to: receive machine instructions and decode the machine instructions to obtain operators, operation data and root pointer indexes; use the root pointer index as a parameter, generate a root pointer read request and send it to the root node module 120.
[0083] The root node module 120 is used to: after receiving a root pointer read request, obtain a root pointer index, read the root pointer according to the root pointer index and return it to the process module 110; the root pointer is used to indicate the location information of the root node of the binary tree.
[0084] The process module 110 is further used to: upon receiving a root pointer, use the root pointer as a parameter, generate a root node data read request, and send the request to the memory module 130 .
[0085] The memory module 130 is a pseudo dual-port random access memory for storing data inserted into the binary tree engine. The data stored in the memory module 130 has the same structure as the data stored in the binary tree. The data is stored in a linked list manner and is dispersedly stored in the memory module 130 to achieve the purpose of storing multiple different data.
[0086] In this embodiment, the data structure stored in the memory module 130 is similar to a bidirectional linked list data structure and includes two child node pointers.
[0087] like Figure 2 As shown, data is the specific data content stored, and the data width DW (data width) can be directly defined by the macro definition method.
[0088] r_pt represents the right child node pointer, and the data bit width AW (address width) is the maximum number of levels that the digital circuit binary tree engine can support.
[0089] l_pt represents the left child node pointer, and the data bit width AW (address width) is the maximum number of levels that the digital circuit binary tree engine can support.
[0090] c_fg represents the flag bit of the current node, with a bit width of 1 bit. If the current node is valid, the value of this field is 1, and if the current node is invalid, the value of this field is 0.
[0091] r_fg represents the flag bit of the right child node, with a bit width of 1 bit. When the right child node is valid, the value of this field is 1, and when the right child node is invalid, the value of this field is 0.
[0092] l_fg represents the flag bit of the left child node, with a bit width of 1 bit. If the left child node is valid, the value of this field is 1, and if the left child node is invalid, the value of this field is 0.
[0093] In this embodiment, the memory module 130 is used to: after receiving the root pointer, read the root node data of the root node of the binary tree based on the root pointer and return it to the process module 110.
[0094] The process module 110 is further used to: when receiving the root node data, based on the root node data and the operation data, perform a corresponding data operation according to the operation type indicated by the operator.
[0095] In actual implementation, the memory size of the memory module 130 can be adjusted according to actual conditions, and this embodiment does not limit the memory size of the memory module 130.
[0096] In addition, if Figure 1 As shown, in this embodiment, the binary tree-based digital circuit further includes a memory management module 140. The memory management module 140 is a First In First Out (FIFO) module, which is used to manage the address of accessing the memory module 130.
[0097] Optionally, the FIFO depth of the memory management module 140 is the same as the RAM depth of the memory module 130 .
[0098] After being reset, the memory management module 140 generates an initialization signal and writes a group of natural numbers into the FIFO as the initialization address of the memory module 130 .
[0099] In the process of the process module 110 performing a binary tree operation, in the case where the binary tree operation is data insertion, the process module 110 is also used to generate a first signal instruction and send it to the memory management module 140 after determining the binary tree node for inserting the operation data during the data insertion process. The memory management module 140 is used to perform memory allocation through a first function after receiving the first signal instruction, and return the starting address of the allocated memory space to the process module 110. The first function is a memory allocation function, which is used to dynamically allocate a memory space of a specified size when performing a binary tree operation.
[0100] Alternatively, when the binary tree operation is data deletion, the process module 110 is further used to send a second signal instruction to the memory management module 140 after executing the data deletion, so that the storage management module 140 reclaims the memory through the second function after receiving the second signal instruction. The second function is a memory allocation (memory free) function, which is used to reclaim the memory of the memory module 130.
[0101] The following is an introduction to the binary tree-based digital circuit implementation method provided in this application.
[0102] like Figure 3 The flowchart of a method for implementing a digital circuit based on a binary tree according to an embodiment of the present application is shown. Figure 1 Taking the binary tree-based digital circuit shown in FIG. 1 as an example, the method at least includes steps S301 to S304:
[0103] Step S301, receiving a machine instruction through a process module, and decoding the machine instruction to obtain an operator, operation data and a root pointer index.
[0104] The operator is used to indicate the operation type, which includes data insertion, data deletion, or data query.
[0105] Step S302, the process module uses the root pointer index as a parameter to generate a root pointer read request and sends it to the root node module, so that after receiving the root pointer read request, the root node module obtains the root pointer index, reads the root pointer according to the root pointer index and returns it to the process module.
[0106] Among them, the root pointer is used to indicate the location information of the root node of the binary tree.
[0107] Step S303, when the process module receives the root pointer, it uses the root pointer as a parameter to generate a root node data read request and sends it to the memory module, so that after receiving the root pointer, the memory module reads the root node data of the binary tree root node based on the root pointer and returns it to the process module.
[0108] Step S304: upon receiving the root node data, the process module performs corresponding data operations according to the operation type indicated by the operator based on the root node data and the operation data.
[0109] In this embodiment, the process module determines the specific binary tree operation to be performed through the operator. The operator is used to indicate the operation type, and the operation type includes data insertion, data deletion or data query. The following introduces three binary tree operations.
[0110] First, the operation type indicated by the operator is data insertion.
[0111] When the operation type indicated by the operator is data insertion, after completing the instruction decoding, the process module first goes to the root node module to read the root pointer according to the index field in the operator, and then accesses the memory module according to the root pointer, reads the root node data, and determines whether the root node is valid. When the root node is invalid, that is, the flag c_fg of the root node is invalid and is 0, it indicates that there is no data in the root node. Memory is allocated through the memory management module, the operation data is stored in the memory module, and a receipt is constructed to complete the data insertion.
[0112] When the root node is valid, that is, when the flag c_fg of the root node is invalid and is 1, it indicates that there is data in the root node. The process module compares the size of the root node data and the operation data according to the binary tree algorithm. According to the size relationship between the root node data and the operation data, the target child node is selected from the left child node and the right child node of the root node. When the operation data is smaller than the root node data, the left child node is used as the target child node; when the operation data is larger than the root node data, the right child node is used as the target child node.
[0113] Determine whether the target child node is valid. If the target child node is invalid, write the operation data directly to the target child node. If the target child node is valid, compare the size of the target child node data and the operation data until an invalid child node is found and the operation data is written.
[0114] Specifically, based on the root node data and the operation data, the corresponding data operation is performed according to the operation type indicated by the operator, including: taking the root node as the current node and the root node data as the current node data; determining whether the current node data is valid according to the current node data; when the current node is valid, comparing the operation data with the current node data to obtain the size relationship between the operation data and the current node data; determining the target child node among the child nodes of the current node based on the first size relationship; when the target child node is invalid, sending a first signal instruction to the storage management module through the process module, so that the storage management module performs memory allocation through the first function after receiving the first signal instruction, and returns the starting address of the allocated memory space to the process module; when the process module receives the starting address, it sends the starting address and the operation data to the memory module, so that after receiving the starting address and the operation data, the memory module stores the operation data according to the starting address, thereby storing the operation data in the target child node.
[0115] Among them, the child nodes of the current node include a right child node and / or a left child node; based on the size relationship, the target child node is determined among the child nodes of the current node, including: when the operation data is greater than the current node data, the right child node is used as the target child node; when the operation data is less than the current node data, the left child node is used as the target child node.
[0116] When the target child node is valid, the method also includes: obtaining the child node data of the target child node; taking the target child node as the current node and the child node data as the current node data; and executing the step of comparing the operation data with the current node data to obtain the size relationship between the operation data and the current node data.
[0117] When the operation data is equal to the root node data, it is considered that the same value exists in the queue. In order to maintain the uniqueness of the data in the queue, the operation data needs to be discarded and a receipt is constructed to complete the execution.
[0118] Second, the operation type indicated by the operator is data deletion.
[0119] When the operation type indicated by the operator is data deletion, if the root node is valid, the root node data is compared with the operation data, and when the root node data is equal to the operation data, the root node is deleted.
[0120] When the root node is invalid, the target child node is determined in the left child node and the right child node of the root node based on the size relationship between the root node data and the operation data, and the operation data is compared with the data of the target child node until the child node data equal to the operation data is found, and the child node corresponding to the child node data is deleted.
[0121] Specifically, when the process module receives the root node data, it performs corresponding data operations based on the root node data and the operation data and in accordance with the operation type indicated by the operator, including: taking the root node as the current node and the root node data as the current node data; determining whether the current node data is valid based on the current node data; when the current node is valid, comparing the operation data with the current node data to obtain the size relationship between the operation data and the current node data; when the size relationship indicates that the operation data is equal to the current node data, deleting the current node through the process module, and sending a second signal instruction to the memory management module, so that the storage management module reclaims memory through a second function after receiving the second signal instruction.
[0122] When the size relationship indicates that the operation data is greater than or less than the current node data, the method also includes: based on the size relationship, determining the target child node among the child nodes of the current node; when the target child node is valid, obtaining the child node data of the target child node; taking the target child node as the current node and the child node data as the current node data, executing the step of comparing the operation data with the current node data to obtain the size relationship between the operation data and the current node data.
[0123] In the process of executing data deletion, if the node to be deleted does not have a left child node and a right child node, the node to be deleted is directly deleted.
[0124] In the case that the node to be deleted has either a left child node or a right child node, after the node to be deleted is deleted, the child node of the deleted node replaces the deleted node.
[0125] When the node to be deleted has a left child node and a right child node, it is necessary to first find the predecessor node of the node to be deleted. The predecessor node refers to a node without a left child node and a right child node, or a node without a right child node; then, copy the value of the predecessor node to the node to be deleted, and recursively delete the predecessor node.
[0126] The third type of operation indicated by the operator is data query.
[0127] When the operation type indicated by the operator is data query, and the flag bit of the node is valid, the data in the memory module is the same as the operation data, indicating that the data has been queried. In this case, the queried data is returned.
[0128] Specifically, when the process module receives the root node data, based on the root node data and the operation data, and in accordance with the operation type indicated by the operator, the corresponding data operation is performed, including: taking the root node as the current node and the root node data as the current node data; determining whether the current node data is valid based on the current node data; when the current node is valid, comparing the operation data with the current node data to obtain the size relationship between the operation data and the current node data; when the size relationship indicates that the operation data is equal to the current node data, determining the current node data as query data, and returning the query data to the designated device.
[0129] When the size relationship indicates that the operation data is not equal to the current node data, the method also includes: based on the size relationship, determining the target child node among the child nodes of the current node; when the target child node is valid, obtaining the child node data of the target child node; taking the target child node as the current node and the child node data as the current node data, executing the step of comparing the operation data with the current node data to obtain the size relationship between the operation data and the current node data.
[0130] When the flag c_fg of the node is invalid, that is, there is no data for the node, the query is considered to have failed, and an error message needs to be returned when building the receipt.
[0131] Specifically, when the current node is invalid, the method further includes: generating a query error message; generating a query receipt based on the query error message and returning the query receipt to the designated device.
[0132] In summary, the present embodiment provides a digital circuit implementation method based on a binary tree, wherein a process module receives machine instructions, and performs instruction decoding on the machine instructions to obtain an operator, operation data, and a root pointer index; the process module uses the root pointer index as a parameter to generate a root pointer read request and sends it to the root node module, so that after receiving the root pointer read request, the root node module obtains the root pointer index, reads the root pointer according to the root pointer index, and returns it to the process module; when the process module receives the root pointer, the process module uses the root pointer as a parameter, generates a root node data read request and sends it to the memory module, so that after receiving the root pointer, the memory module reads the root node data of the root node of the binary tree based on the root pointer and returns it to the process module; When the process module receives the root node data, it performs the corresponding data operation according to the operation type indicated by the operator based on the root node data and the operation data; it can solve the problem of low efficiency of digital circuit data processing; the binary tree operation is performed by the process module, the root node module stores the root node execution, and the memory module stores the binary tree data, so as to realize the storage of data in the digital circuit by the binary tree method, avoid using random access memory to store data, the storage method of linked list or hash dictionary, in the digital circuit, the processing time of insertion, deletion and search operations is shortened, and the efficiency of digital circuit data processing is improved; at the same time, by keeping the balance of the binary tree, it can ensure that the height of the tree is relatively small, and further improve the efficiency of digital circuit data operation.
[0133] Furthermore, in a binary tree, by comparing node values, the subtree where the data is located can be quickly determined, thereby reducing the number of traversals and further improving the efficiency of digital circuit data operations.
[0134] Corresponding to the above method, the present invention also provides a digital circuit implementation device based on a binary tree, which includes a computer device, the computer device includes a processor and a memory, the memory stores computer instructions, and the processor is used to execute the computer instructions stored in the memory. When the computer instructions are executed by the processor, the device implements the steps of the digital circuit implementation method based on a binary tree as mentioned above.
[0135] The embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the digital circuit implementation method based on a binary tree are implemented. The computer-readable storage medium can be a tangible storage medium, such as a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a floppy disk, a hard disk, a removable storage disk, a CD-ROM, or any other form of storage medium known in the technical field.
[0136] It should be understood by those skilled in the art that the exemplary components, systems and methods described in conjunction with the embodiments disclosed herein can be implemented in hardware, software or a combination of the two. Whether it is performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present invention are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link via a data signal carried in a carrier.
[0137] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.
[0138] In the present invention, features described and / or illustrated for one embodiment may be used in the same or similar manner in one or more other embodiments, and / or combined with features of other embodiments or replace features of other embodiments.
[0139] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for realizing a digital circuit based on a binary tree, characterized in that: Applied to a digital circuit based on a binary tree algorithm, the digital circuit includes a process module, a root node module and a memory module; the method includes the following steps: The process module receives a machine instruction, and decodes the machine instruction to obtain an operator, operation data, and a root pointer index; the operator is used to indicate an operation type, and the operation type includes data insertion, data deletion, or data query; The process module uses the root pointer index as a parameter to generate a root pointer read request and sends it to the root node module, so that after receiving the root pointer read request, the root node module obtains the root pointer index, reads the root pointer according to the root pointer index and returns it to the process module; the root pointer is used to indicate the location information of the root node of the binary tree; When the process module receives the root pointer, the process module uses the root pointer as a parameter to generate a root node data read request and sends it to the memory module, so that after receiving the root pointer, the memory module reads the root node data of the binary tree root node based on the root pointer and returns it to the process module; When receiving the root node data, the process module performs corresponding data operations according to the operation type indicated by the operator based on the root node data and the operation data.
2. The method for realizing a digital circuit based on a binary tree according to claim 1, characterized in that: In the case where the operation type indicated by the operator is data insertion, the digital circuit further includes a storage management module; When the process module receives the root node data, based on the root node data and the operation data, and according to the operation type indicated by the operator, performing a corresponding data operation includes: Taking the root node as the current node and taking the root node data as the current node data; Determine whether the current node data is valid according to the current node data; When the current node is valid, the operation data is compared with the current node data to obtain a size relationship between the operation data and the current node data; Based on the size relationship, determining a target child node among the child nodes of the current node; In the case that the target child node is invalid, sending a first signal instruction to the storage management module through the process module, so that after receiving the first signal instruction, the storage management module performs memory allocation through a first function and returns the starting address of the allocated memory space to the process module; When the process module receives the starting address, the process module sends the starting address and the operation data to the memory module, so that the memory module stores the operation data according to the starting address after receiving the starting address and the operation data, thereby storing the operation data in the target child node.
3. The method for realizing a digital circuit based on a binary tree according to claim 2, characterized in that: When the target child node is valid, the method further includes: Obtaining the child node data of the target child node; Taking the target child node as the current node and taking the child node data as the current node data; The step of comparing the operation data with the current node data to obtain a size relationship between the operation data and the current node data is performed.
4. The method for realizing a digital circuit based on a binary tree according to claim 2, characterized in that: The child nodes of the current node include a right child node and / or a left child node; and determining a target child node from the child nodes of the current node based on the size relationship includes: When the operation data is greater than the current node data, the right child node is used as the target child node; When the operation data is smaller than the current node data, the left child node is used as the target child node.
5. The method for realizing a digital circuit based on a binary tree according to claim 1, characterized in that: In the case where the operation type indicated by the operator is data deletion, the digital circuit further includes a storage management module; When the process module receives the root node data, based on the root node data and the operation data, and according to the operation type indicated by the operator, performing a corresponding data operation includes: Taking the root node as the current node and taking the root node data as the current node data; Determine whether the current node data is valid according to the current node data; When the current node is valid, the operation data is compared with the current node data to obtain a size relationship between the operation data and the current node data; When the size relationship indicates that the operation data is equal to the current node data, the current node is deleted through the process module, and a second signal instruction is sent to the storage management module, so that the storage management module reclaims memory through a second function after receiving the second signal instruction.
6. The method for realizing a digital circuit based on a binary tree according to claim 1, characterized in that: In a case where the operation type indicated by the operator is data query, the process module, upon receiving the root node data, performs a corresponding data operation based on the root node data and the operation data according to the operation type indicated by the operator, including: Taking the root node as the current node and taking the root node data as the current node data; Determine whether the current node data is valid according to the current node data; When the current node is valid, the operation data is compared with the current node data to obtain a size relationship between the operation data and the current node data; In a case where the size relationship indicates that the operation data is equal to the current node data, the current node data is determined as query data, and the query data is returned to a designated device.
7. The method for realizing a digital circuit based on a binary tree according to claim 6, characterized in that: In the case where the current node is invalid, the method further includes: Generate query error messages; A query receipt is generated based on the query error information and returned to the designated device.
8. A digital circuit based on a binary tree, characterized in that: Applicable to the binary tree-based digital circuit implementation method according to claims 1 to 7, the digital circuit comprising: The process module is used to: receive a machine instruction and decode the machine instruction to obtain an operator, operation data and a root pointer index; the operator is used to indicate an operation type, and the operation type includes data insertion, data deletion or data query; take the root pointer index as a parameter, generate a root pointer read request and send it to the root node module; The root node module is used to: after receiving the root pointer read request, obtain the root pointer index, read the root pointer according to the root pointer index and return it to the process module; the root pointer is used to indicate the location information of the root node of the binary tree; The process module is further used to: upon receiving the root pointer, use the root pointer as a parameter to generate a root node data read request and send the request to the memory module; The memory module is used to: after receiving the root pointer, read the root node data of the binary tree root node based on the root pointer and return it to the process module; The process module is further used to: upon receiving the root node data, based on the root node data and the operation data, perform corresponding data operations according to the operation type indicated by the operator.
9. The binary tree-based digital circuit according to claim 8, characterized in that: The digital circuit also includes a storage management module; The process module is further used to: during the data insertion process, after determining the binary tree node for inserting the operation data, generate a first signal instruction and send it to the storage management module; The storage management module is used to: after receiving the first signal instruction, perform memory allocation through the first function, and return the starting address of the allocated memory space to the process module; or, The process module is further used to: after executing the data deletion, send a second signal instruction to the storage management module; The storage management module is further used to: after receiving the second signal instruction, reclaim the memory through the second function.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method for realizing a digital circuit based on a binary tree as claimed in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Key-Value local storage method and system based on solid state disk (SSD)
CN102722449A
Threaded, height-balanced binary tree data structure
US5557786A
