CN107590160B - Method and device for monitoring internal structure of radix tree to realize test - Google Patents
Method and device for monitoring internal structure of radix tree to realize test Download PDFInfo
- Publication number
- CN107590160B CN107590160B CN201610539360.8A CN201610539360A CN107590160B CN 107590160 B CN107590160 B CN 107590160B CN 201610539360 A CN201610539360 A CN 201610539360A CN 107590160 B CN107590160 B CN 107590160B
- Authority
- CN
- China
- Prior art keywords
- node
- layer
- nodes
- radix tree
- identification
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
A method and apparatus for monitoring the internal structure of a radix tree; the method comprises the following steps: acquiring an identification set of nodes in a radix tree before operation as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node; acquiring an identification set of nodes in the radix tree after operation as a second set; and comparing the second set with the expected identification set, and obtaining a monitoring result according to a comparison result. The method and the device can monitor the internal form of the radix tree in real time when operation occurs each time.
Description
Technical Field
The invention relates to the field of computers, in particular to a method and a device for monitoring an internal structure of a radix tree.
Background
Radix trees (radix-trees), also known as PAT bit trees (Patricia Trie or bit tree), are common dictionary-type data structures. The radix tree is a multi-way search tree, with the leaf nodes of the tree being the actual data entries. Each node has a fixed, 2^ n pointer to the child node (each pointer is called a slot) and a pointer to the parent node.
When using radix trees, the most common operations are inserting, deleting, finding nodes. Wherein inserting and deleting nodes changes the internal structure of the radix tree. Under different use scenarios, different data structure definitions and different add-drop node algorithms need to be used for the trade-off of temporal complexity and spatial complexity. For example, in a scenario in which continuous large blocks of data are mainly inserted and deleted, breadth-first traversal may obtain a lower time complexity than depth-first traversal search; under the scene that the storage data volume is small and the dispersion is high (the dispersion is higher, the addressing space is larger), the map or the hash is used for recording the child node pointer, so that more memory is saved than the array. .
When the radix tree is used, under different use scenes, a large amount of tests are needed to ensure the correctness after the data structure is changed or the algorithm is adjusted. However, for the more complex data structure such as the radix tree, the test debugging work is a difficult point, and is reflected in the following aspects:
(a) the radix tree provides simple external interfaces, but the internal data structure is complex, and the common method is to test the algorithm correctness by checking the data correctness after multiple operations (insertion, deletion and the like). This type of debugging is coarse-grained and fails to find problems that occur between multiple operations and that are masked as "negative plus positive" in continuous operation. The quality can be guaranteed only by making a very large number of sufficient tests with very sufficient test cases. The time and the labor are consumed, quick iteration cannot be realized after algorithm adjustment and data structure adjustment, and the project development requirement of quick iteration cannot be met.
(b) If the mode mentioned in (a) is used for debugging and testing, once a problem is found, it is difficult to trace the first time when the problem occurs immediately, and it is likely that the internal structure has made mistakes when the previous inserting and deleting operations are performed, but the test case can not be detected until the whole test case runs out. In such a situation, in many cases, only the reproduction attempt is made, the problem range is gradually reduced, the problem exposure, namely the positioning, cannot be achieved, and the positioning is very difficult.
Disclosure of Invention
The application provides a method and a device for monitoring an internal structure of a radix tree, which can monitor the internal form of the radix tree in real time when operation occurs each time.
The technical scheme is as follows.
A method of monitoring the internal structure of a radix tree, comprising:
acquiring an identification set of nodes in a radix tree before operation as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
acquiring an identification set of nodes in the radix tree after operation as a second set; and comparing the second set with the expected identification set, and obtaining a monitoring result according to a comparison result.
Optionally, the identification of the node is a sequence of layer indices of each node in a shortest path from a root node to the node; different levels of the radix tree correspond to different levels of level indices; and different child nodes of each node in the radix tree are distinguished by using the layer indexes of the level corresponding to the layer where the node is located.
Optionally, the layer index comprises a number and/or a letter; the first set comprises a set of identification intervals of each layer of nodes of the radix tree before operation; the second set comprises an identification interval set of each layer of nodes of the radix tree after operation; the node identification change information comprises an identification interval of each layer of nodes to be changed.
Optionally, the determining the expected identity set of the nodes in the radix tree according to the first set and the node identity change information includes:
when the operation is insertion, respectively solving a union set of the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the union set of all layers as the expected identification set;
and when the operation is deletion, respectively solving a difference set for the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the difference sets of all the layers as the expected identification set.
Optionally, before determining the expected identity set of the node in the radix tree according to the first set and the node identity change information, the method further includes:
and determining the identifier of each layer of father node of the related leaf node according to the identifiers of one or more leaf nodes in the radix tree related to the operation to obtain the identifier interval of each layer of nodes to be changed.
Optionally, the obtaining the identification set of the nodes in the radix tree includes:
finding a first non-empty node of each layer from a root node of the radix tree;
and respectively traversing all the nodes of the layer from the node found in each layer through the pointer which is maintained by each node and points to the right node, recording the identifier of the node of the layer, and obtaining the identifier set of each layer of nodes after the traversal is completed.
An apparatus for monitoring an internal structure of a radix tree, comprising:
the prediction unit is used for acquiring an identification set of nodes in the operation front base tree as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
the comparison unit is used for acquiring the identification set of the nodes in the radix tree after operation as a second set; and comparing the second set with the expected identification set, and obtaining a monitoring result according to a comparison result.
Optionally, the identification of the node is a sequence of layer indices of each node in a shortest path from a root node to the node; different levels of the radix tree correspond to different levels of level indices; and different child nodes of each node in the radix tree are distinguished by using the layer indexes of the level corresponding to the layer where the node is located.
Optionally, the layer index comprises a number and/or a letter; the first set comprises a set of identification intervals of each layer of nodes of the radix tree before operation; the second set comprises an identification interval set of each layer of nodes of the radix tree after operation; the node identification change information comprises an identification interval of each layer of nodes to be changed.
Optionally, the determining, by the prediction unit according to the first set and the node identifier change information, a predicted identifier set of a node in the radix tree includes:
when the operation is insertion, respectively solving a union set of the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the union set of all layers as the expected identification set; and when the operation is deletion, respectively solving a difference set for the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the difference sets of all the layers as the expected identification set.
Optionally, the apparatus further comprises:
and the determining unit is used for determining the identifier of each layer of father node of the related leaf node according to the identifiers of one or more leaf nodes in the radix tree related to the operation to obtain the identifier interval of each layer of nodes to be changed.
Optionally, the obtaining, by the prediction unit and/or the comparison unit, the identification set of the nodes in the radix tree includes:
finding a first non-empty node of each layer from a root node of the radix tree; and respectively traversing all the nodes of the layer from the node found in each layer through the pointer which is maintained by each node and points to the right node, recording the identifier of the node of the layer, and obtaining the identifier set of each layer of nodes after the traversal is completed.
A data processing electronic device for monitoring internal structure of a radix tree, comprising a processor, a memory; the memory is used for storing a program for monitoring the internal structure of the radix tree; the program for monitoring the internal structure of the radix tree, when read and executed by the processor, performs the following operations:
acquiring an identification set of nodes in a radix tree before operation as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
acquiring an identification set of nodes in the radix tree after operation as a second set; and comparing the second set with the expected identification set, and obtaining a monitoring result according to a comparison result.
The application includes the following advantages:
in at least one embodiment of the present application, the identifier of a node includes information describing the shortest path from the root node to the node, and the internal structure of the entire radix tree can be reflected by the set of identifiers of the node; the structure of the radix tree after operation is estimated in each operation, and compared with the result obtained after actual operation to judge whether the internal structure of the radix tree is abnormal after operation, so that errors can be immediately found when problems occur, and real-time monitoring of the radix tree is realized in each operation.
In an alternative of the embodiment of the present application, the identifier of the node may be a layer index sequence of each node in the shortest path from the root node to the node, so that a unique identifier of each layer can be obtained conveniently.
In an alternative of the embodiment of the present application, the set of node identifiers may include one or more interval sets, and the node identifier modification information is also expressed in an interval form, so that a predicted identifier set may be conveniently determined by a simple manner of an interval union set and a difference set; in an optional implementation mode, the node identification and the pointer pointing to the right node are used for collecting the node identification set, and the two fields are not necessary data structures of the radix tree, so that the data structures and algorithms of the radix tree are not influenced when changed, the coupling dependence with the internal data structure definition and algorithms of the radix tree is realized, the monitoring logic is hardly required to be modified when the internal data structure definition and algorithms are changed, the monitoring function is not influenced, and the efficiency of quick iteration and the correctness and stability of the monitoring technology can be ensured.
Of course, it is not necessary for any product to achieve all of the above-described advantages at the same time for the practice of the present application.
Drawings
Fig. 1 is a schematic diagram of a method for monitoring an internal structure of a radix tree according to a first embodiment;
FIG. 2 is a diagram illustrating the division of an index into sub-indexes according to an example of the first embodiment;
FIG. 3 is a diagram illustrating correspondence between layers of a sub-index and a radix tree in an example according to the first embodiment;
FIG. 4 is a schematic illustration of a sub-index in an example of the first embodiment;
FIG. 5 is a diagram illustrating the sub-index of FIG. 4 corresponding to a radix tree;
FIG. 6 is a schematic representation of identifier generation for different nodes;
FIG. 7 is a schematic monitoring flow chart according to an example of the first embodiment;
fig. 8 is a schematic diagram of a method for monitoring an internal structure of a radix tree according to the second embodiment.
Detailed Description
The technical solutions of the present application will be described in more detail below with reference to the accompanying drawings and embodiments.
It should be noted that, if not conflicted, the embodiments and the features of the embodiments can be combined with each other and are within the scope of protection of the present application. Additionally, while a logical order is shown in the flow diagrams, in some cases, the steps shown or described may be performed in an order different than here.
In a typical configuration, the monitoring device may include one or more processors (CPUs), input/output interfaces, network interfaces, and memory (memory).
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium. The memory may include module 1, module 2, … …, and module N (N is an integer greater than 2).
Computer readable media include both permanent and non-permanent, removable and non-removable storage media. A storage medium may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory computer readable media (transient media), such as modulated data signals and carrier waves.
In an embodiment, a method for monitoring an internal structure of a radix tree, as shown in fig. 1, includes steps S110 to S120:
s110, acquiring an identification set of nodes in a radix tree before operation as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
s120, obtaining an identification set of the nodes in the radix tree after operation, and taking the identification set as a second set; and comparing the second set with the expected identification set, and obtaining a monitoring result according to a comparison result.
In this embodiment, the steps S110 to S120 may be performed when performing operations on the radix tree each time, and whether an operation causes a radix tree error may be known through a comparison result; therefore, the radix tree can be checked in time after each operation, the situation that the error is negative or positive is avoided, and the error is favorably positioned.
In this embodiment, since the identifier of each node includes information for describing the shortest path from the root node to the node, that is, the identifier of the node may embody a structure in the radix tree related to the node, the internal structure of the entire radix tree may be reflected by the set of identifiers of the nodes in the radix tree; determining the expected identification set in each operation, which is equivalent to estimating the structure after the operation of the radix tree; and comparing the expected identification set with a second set obtained after actual operation to know whether the internal structure of the radix tree is abnormal after operation, so that errors can be immediately found when problems occur, and real-time monitoring of the radix tree is realized when operation occurs each time. In this embodiment, the obtaining a monitoring result according to the comparison result may include: when the comparison results are the same, judging that the radix tree is normal, namely, no error exists; and when the comparison results are different, judging that the radix tree has errors. After the error is judged, the method further comprises the following steps: terminating testing or other operations and retaining field information of the radix tree. Thus, the positioning is convenient when problems occur.
In this embodiment, the node identifier change information may be determined according to an operation message; the operation message is used for indicating that a certain operation is performed on the radix tree, and may include operations such as insertion and/or deletion. The operation message may include an operation request, an operation instruction, and the like, for indicating a message for operating the radix tree.
In this embodiment, an optional method is to intercept the operation message sent to the radix tree, query the current set of identifiers of the nodes in the radix tree after the interception, obtain the first set, and send the intercepted operation message to the radix tree; the step of determining the set of expected identifications may be performed before, after, or in parallel with the step of sending the intercepted operation message; and acquiring a set (namely a second set) of the identifiers of the nodes of the radix tree after corresponding operation according to the operation message and comparing the identifiers. Another alternative is to save the set of identifiers of the nodes after each operation of the radix tree as the first set in the next operation (when no operation is performed, the saved set is the set of identifiers of the nodes at the beginning of the radix tree); only performing content monitoring on the operation message sent to the radix tree to acquire the node identification change information without intercepting; after the operation message is monitored, a predicted identification set is determined through the stored first set and the node identification change information, and a set (namely a second set) of the identification of the node after the corresponding operation is carried out on the radix tree according to the operation message is obtained and compared.
In an alternative of this embodiment, the identifier of a node may be a sequence of layer indexes of each node in the shortest path from the root node to the node; different levels of the radix tree may correspond to different levels of the level index, and different child nodes of each node in the radix tree may be distinguished using the level index of the level corresponding to the level at which the node is located.
In this alternative, different levels of the radix tree correspond to different levels of level indexes, e.g., the level indexes may include level 0 level indexes, level 1 level indexes, … …. The different child nodes of each node are distinguished by using the layer indexes of the corresponding levels of the layer where the node is located, for example, the different child nodes of the root node are respectively represented by different level-0 layer indexes; different child nodes of each child node of the root node are respectively represented by different level 1 indexes; and so on. Therefore, each level of index needs to contain M different index values, where M is the maximum number of child nodes that a node can possess.
For example, the root node has two child nodes X and Y, with the level 0 layer indices ah and cq, respectively. The child node X also has two child nodes W and V, and the level 1 layer indexes are kl and sq respectively; the identity of the child node W is "ahkl" (the root node is unique and may have no layer index), i.e. a sequence of the layer index of the child node X (level 0 layer index) and the layer index of the child node W (level 1 layer index) on the shortest path. It should be noted that the level 1 indexes for the child node Y and the child node X may be all or partially the same, and if they are the same, the child node Y may also have a child node whose level 1 index is kl, but the identifier of the child node will be "cqkl", that is, a sequence of the level index of the child node Y and the level index of the child node W on the shortest path.
In one embodiment of this alternative, the layer index may comprise numbers and/or letters; the first set comprises a set of identification intervals of each layer of nodes of the radix tree before operation; the second set comprises an identification interval set of each layer of nodes of the radix tree after operation; the node identification change information comprises an identification interval of each layer of nodes to be changed.
In this embodiment, the determining the expected identity set of the node in the radix tree according to the first set and the node identity change information may include:
when the operation is insertion, respectively solving a union set of the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the union set of all layers as the expected identification set;
and when the operation is deletion, respectively solving a difference set for the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the difference sets of all the layers as the expected identification set.
In this embodiment, if the identifiers of the nodes in one layer are consecutive, for example, if the identifiers of the nodes in a certain layer are 0x020001, 0x020002, 0x020003, and … … 0x020010 respectively, the identifier interval set in the layer may only include one interval [0x020001, 0x020010], and if the identifiers are not consecutive, the identifier interval set in the layer may include a plurality of intervals.
In other embodiments, the layer index may be other symbols (single symbol or symbol sequence), and may be any combination of numbers, letters, and symbols.
In this embodiment, before determining the expected identity set of the node in the radix tree according to the first set and the node identity change information, the method may further include:
and determining the identifier of each layer of father node of the related leaf node according to the identifiers of one or more leaf nodes in the radix tree related to the operation to obtain the identifier interval of each layer of nodes to be changed.
For example, the operation involves five leaf nodes of the radix tree, i.e., the involved leaf nodes; since the leaf node operations also involve the parent nodes of the leaf nodes, the parent nodes (excluding the root node) are the nodes to be changed. Respectively determining the identifiers of father nodes of each layer of the five leaf nodes to obtain five batches of identifiers of the father nodes (each batch of identifiers comprises the identifier of each layer of father nodes of one leaf node), and after the five batches of identifiers are integrated and divided according to layers, obtaining the identifier interval of each layer of nodes to be changed; and taking the obtained identification interval of each layer of nodes to be changed as the expected identification set. Because the identifier of the node is a sequence of layer indexes of each node in the shortest path from the root node to the node, the layer to which the node belongs can be determined according to the number of layer indexes or the length of the identifier in the identifier of the node. There is only one layer index in the identifier compared to the children of the root node, and there are two layer indexes in the identifier for the children of these children; and so on. If the length of the layer index is fixed, for example, one layer index is fixed to two 16-ary bits, the layer where the node is located can be distinguished according to the length of the identifier.
In an alternative of this embodiment, the obtaining the identifier set of the node in the radix tree may include:
finding a first non-empty node of each layer from a root node of the radix tree;
and respectively traversing all the nodes of the layer from the node found in each layer through the pointer which is maintained by each node and points to the right node, recording the identifier of the node of the layer, and obtaining the identifier set of each layer of nodes after the traversal is completed.
In this alternative, each node in the radix tree may maintain a pointer to the right node; through the pointer, as long as the first (i.e. the first from the left) non-empty node of each layer is found, the node on the right side of the node can be accessed through the pointer which is maintained by the node and points to the node on the right side, and then the node on the right side is accessed according to the pointer which is maintained by the node on the right side and points to the node on the right side, and so on until the node on the layer is accessed. The embodiment collects the set of the identifiers of the nodes through the identifiers of the nodes and the pointers pointing to the nodes on the right, and because the two fields are not necessary data structures of the radix tree, the data structures and algorithms of the radix tree are not influenced when changed, and the very loose coupling dependence on the internal data structure definition and the algorithms of the radix tree is realized.
In this alternative, when the identifier set is an identifier interval set and the identifier of a node in a layer is recorded, the identifier set is recorded in the form of an identifier interval set.
In other embodiments, other ways may be used to traverse each node of the radix tree to obtain the set of identification intervals for each level of nodes.
The following is explained with an example in which an index (key) is decomposed into four sub-indexes (sub _ keys), and as shown in fig. 2, keys are decomposed into sub _ key0, sub _ key1, sub _ key2, and sub _ key 3. Each sub-index is respectively used as a layer index corresponding to each layer of the radix tree except for leaf nodes; assuming that all leaf nodes are in the same layer, as shown in fig. 3, R is a root node, N is an internal node, L is a leaf node, and keyylist is an index sequence. sub _ key0 corresponds to the root node; sub _ key1 corresponds to a child of the root node itself (a first level child, which may also be referred to as a level 1 internal node); sub _ key2 corresponds to a child node of the first level child node (second level child node, also referred to as level 2 internal node); the sub _ key3 corresponds to a child node of the second-level child node (third-level child node, which may also be referred to as an internal node of level 3), i.e., a parent node of a leaf node.
In this example, assuming that the key is a 32-bit unsigned shaping (uint32_ t) number, the key can be split into 4 sub _ keys, each sub _ key is 8 bits, and the 4 sub _ keys respectively correspond to four bytes of the key from high to low. As shown in FIG. 4, for example, 32 bits of a key are numbered 0-31, the sub _ key0 is the bits numbered 0-7, the sub _ key1 is the bits numbered 8-15, the sub _ key2 is the bits numbered 16-23, and the sub _ key3 is the bits numbered 24-31.
The case of mapping sub _ key to radix tree is shown in fig. 5: sub _ key0 is a level 0 layer index; sub _ key1, sub _ key2, and sub _ key3 are level 1 layer index, level 2 layer index, and level 3 layer index, respectively; wherein the level 0 layer index is the most significant bit in the layer index sequence and the level 3 layer index is the least significant bit. Each of the 8 bits has two values of "0" and "1", and the 8 bits together may contain 2^8 ^ 256 different value sequences. If an 8-bit sub-index is considered as a binary number, then 256 different value sequences, corresponding to decimal values [0,255], may be used to represent the layer indices of the 256 sub-nodes, respectively. For example, 0 to 255 of sub _ key0 respectively represent 256 level 1 internal nodes under the root node, 0 to 255 of sub _ key1 respectively represent 256 level 2 internal nodes under 1 level 1 internal nodes, 0 to 255 of sub _ key2 respectively represent 256 level 3 internal nodes under 1 level 2 internal nodes, and 0 to 255 of sub _ key3 respectively represent 256 leaf nodes under 1 level 3 internal nodes.
The generation process of each layer of node id is shown in fig. 6, where the id of each node is a layer index sequence of each node in the shortest path from the root node to the node, for example, for the internal node 61 at level 3, the layer indexes included in the layer index sequence are: 2(sub _ key0), 0(sub _ key1) and 1(sub _ key2), since the number of child nodes of each node (including) does not exceed 256, the layer index of each node on the path can be represented by a hexadecimal number, and a hexadecimal number includes two hexadecimal bits, for example, the layer index 2 is represented as "02", the layer index 0 is represented as "01", and the id of the node 61 is 0x020001, where 0x represents that the following number sequence is a hexadecimal number. It can be seen that the shortest path from the root node to a node can uniquely determine a node, and this id must be unique in one layer, but is not necessarily unique globally, because there may be a leaf node whose layer indexes of each node in the shortest path from the root node to the leaf node are 0(sub _ key0), 2(sub _ key1), 0(sub _ key2) and 1(sub _ key3) in sequence, and the id of the leaf node is also 0x00020001, although two hexadecimal bits are more than 0x020001, but the corresponding values are the same. Similarly, the leaf node 62 has an id of 0x020100 ff.
In order to facilitate monitoring of the internal morphology of the radix tree, each layer of nodes (including internal nodes and leaf nodes) needs to be maintained: a unique per-layer identity (id); and a pointer to a neighboring node to the right of the present node (hereinafter referred to as a next pointer).
The workflow diagram of radix tree monitoring is shown in fig. 7, in which the monitoring module is used to implement monitoring of radix tree operations, and the radix tree module is responsible for implementing radix tree functions. The monitoring module takes over the operation of the radix tree and monitors the operation which can change the internal structure of the radix tree, and the method comprises the following steps of 501-510:
501. the monitoring module intercepts the operation information (operation request or operation instruction and the like) of the user to the radix tree, and obtains the identifier interval (from, to) of each layer of nodes to be changed corresponding to the operation (insertion or deletion and the like) according to the operation information, namely the node identifier change information.
502. The monitoring module obtains the state of the current radix tree from the radix tree module.
503. The radix tree module returns state information currentStatus of each layer of the radix tree, wherein the state information, namely the first set, represents the state of the radix tree before the radix tree is operated.
504. The monitoring module calculates the predicted state information expectedStatus of each layer of the radix tree after the operation, namely the predicted identification set, by combining the from, to and currentStatus obtained by 501.
505. Forwarding the operation message intercepted in 501 to the radix tree module.
506. And after the radix tree module completes the corresponding operation, returning a response to the monitoring module.
507. The monitoring module again obtains the state of the current radix tree from the radix tree module.
508. And the radix tree module returns state information actualStatus of each layer of the radix tree, wherein the state information, namely the second set, represents the state of the radix tree after the radix tree is operated.
509. And comparing the actualStatus with the expectedStatus, if the actualStatus and the expectedStatus are not consistent, reporting an error, and recording all the information of the operation message and the base tree intercepted by 501.
510. If so, a message is returned to the user indicating that the operation is complete.
The details of calculating expectedStatus in step 504 in combination with [ from, to ] and currentStatus are as follows:
for the insert (insert) operation, [ from, to ] is added to the identification interval set contained in currentStatus, each identification interval s in currentStatus is traversed, and if s and [ from, to ] have intersection, the interval addition operation of s and [ from, to ] is performed. And performing once interval duplicate removal and adjacent interval combination after traversing.
For delete operation, each interval s in currentStatus is traversed, and if s and [ from, to ] have intersection, the interval subtraction operation of s and [ from, to ] is performed.
The addition operation refers to the union of two intersecting intervals, for example, combining [ a, b ], [ b-1, b +10] into [ a, b +10 ]. The subtraction operation refers to the difference between two intersecting intervals [ a, b ], [ c, d ], for example, the result of [ a, b ] - [ c, d ] may be one of the three cases [ a, c ], [ d, b ], [ a, c ] and [ d, b ] according to the magnitude relationship of a, b, c, d.
The process for acquiring the state information of each layer of the current radix tree by the radix tree module comprises the following two steps:
the first step, obtaining the first (leftmost) node of each layer; the step only needs to access the first non-empty node of each layer from the root node, and is very simple.
And secondly, directly traversing all nodes on the right side of the node by using a next pointer of each node, and recording id intervals of nodes on each layer, such as [0,5], [8,10], [49,91] or [ a, d ], [ m, q ], [ x, x ]. The state information returned by each layer is a set of identification intervals. In the step, an id field and a next field of the node are used, the two fields are not necessary data structures of the radix tree and are not influenced when the data structures and algorithms of the radix tree change, so that the monitoring method, the data structures and the algorithms of the radix tree can be loosely coupled.
The monitoring method of the embodiment is suitable for all scenes using numbers, letters or other types of data as index of the radix tree. The above example is described by taking numbers as indexes, and it is not meant that this embodiment is only applicable to radix trees with numbers as indexes.
In a second embodiment, an apparatus for monitoring an internal structure of a radix tree, as shown in fig. 8, includes:
a prediction unit 81, configured to obtain an identification set of nodes in the radix tree before operation as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
a comparing unit 82, configured to obtain an identifier set of a node in the radix tree after operation, as a second set; and comparing the second set with the expected identification set, and obtaining a monitoring result according to a comparison result.
In this embodiment, the prediction unit 81 is the part of the apparatus responsible for generating the expected identity set, and may be software, hardware or a combination of the two.
In this embodiment, the comparing unit 82 is a part of the apparatus responsible for comparing the actually obtained set with the expected tag set, and may be software, hardware or a combination of the two.
In this embodiment, one or more of the prediction unit 81 and the comparison unit 82 may be disposed in the same device or equipment as the module for operating the radix tree, or disposed in different devices or equipment; whether provided in the same device or equipment, the prediction unit 81 and the comparison unit 82 can obtain the identification set of the nodes in the radix tree. The prediction module 81 and the comparison unit 82 may multiplex or obtain the identification set of nodes in the radix tree through the same functional module.
In an alternative of this embodiment, the identifier of the node may be a sequence of layer indexes of each node in the shortest path from the root node to the node; different levels of the radix tree may correspond to different levels of level indices; different child nodes of each node in the radix tree can be distinguished by using the layer index of the level corresponding to the layer where the node is located.
In one embodiment of this alternative, the layer index may comprise numbers and/or letters; the first set may comprise a set of identification intervals for each level of nodes of the radix tree prior to operation; the second set may comprise a set of identification intervals for each level of nodes of the radix tree after operation; the node identifier change information may include an identifier interval of each layer of nodes to be changed;
the determining, by the prediction unit, the expected identity set of the nodes in the radix tree according to the first set and the node identity change information may include:
when the operation is insertion, respectively solving a union set of the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the union set of all layers as the expected identification set; and when the operation is deletion, respectively solving a difference set for the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the difference sets of all the layers as the expected identification set.
In this embodiment, the apparatus may further include:
and the determining unit is used for determining the identifier of each layer of father node of the related leaf node according to the identifiers of one or more leaf nodes in the radix tree related to the operation to obtain the identifier interval of each layer of nodes to be changed.
In this embodiment, the determining unit is a part of the apparatus responsible for determining the node identifier change information, and may be software, hardware, or a combination of the two.
In an alternative of this embodiment, the obtaining, by the prediction unit and/or the comparison unit, the identifier set of the node in the radix tree may include:
finding a first non-empty node of each layer from a root node of the radix tree; and respectively traversing all the nodes of the layer from the node found in each layer through the pointer which is maintained by each node and points to the right node, recording the identifier of the node of the layer, and obtaining the identifier set of each layer of nodes after the traversal is completed.
In this embodiment, the units included in the apparatus may be respectively used to execute the corresponding steps in the first embodiment, and details of implementation of the corresponding operations by these units may be referred to in the first embodiment.
The third embodiment provides a data processing electronic device for monitoring the internal structure of a radix tree, which comprises a processor and a memory; the method is characterized in that:
the memory is used for storing a program for monitoring the internal structure of the radix tree; the program for monitoring the internal structure of the radix tree, when read and executed by the processor, performs the following operations:
acquiring an identification set of nodes in a radix tree before operation as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
acquiring an identification set of nodes in the radix tree after operation as a second set; and comparing the second set with the expected identification set, and obtaining a monitoring result according to a comparison result.
In this embodiment, the above program for monitoring the internal structure of the radix tree is read and executed by the processor, and details of the executed operation can be found in embodiment one.
It will be understood by those skilled in the art that all or part of the steps of the above methods may be implemented by instructing the relevant hardware through a program, and the program may be stored in a computer readable storage medium, such as a read-only memory, a magnetic or optical disk, and the like. Alternatively, all or part of the steps of the above embodiments may be implemented using one or more integrated circuits. Accordingly, each module/unit in the above embodiments may be implemented in the form of hardware, and may also be implemented in the form of a software functional module. The present application is not limited to any specific form of hardware or software combination.
There are, of course, many other embodiments of the invention that can be devised without departing from the spirit and scope thereof, and it will be apparent to those skilled in the art that various changes and modifications can be made herein without departing from the spirit and scope of the invention.
Claims (3)
1. A method of monitoring an internal structure of a radix tree to implement a test, comprising:
acquiring an identification set of nodes in a radix tree before operation as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
acquiring an identification set of nodes in the radix tree after operation as a second set; comparing the second set with the expected identification set, obtaining a monitoring result according to the comparison result, and judging that the radix tree has errors when the comparison result is different;
wherein the obtaining of the identification set of the nodes in the radix tree comprises:
finding a first non-empty node of each layer from a root node of the radix tree;
respectively traversing all nodes of each layer from the found nodes of each layer through a pointer which is maintained by each node and points to the right node, recording the identifiers of the nodes of the layer, and obtaining the identifier set of each layer of nodes after traversing is completed;
the identity of the node is a sequence of layer indices for each node in a shortest path from a root node to the node; different levels of the radix tree correspond to different levels of level indices; different child nodes of each node in the radix tree are distinguished by using the layer indexes of the level corresponding to the layer where the node is located;
the layer index comprises numbers and/or letters; the first set comprises a set of identification intervals of each layer of nodes of the radix tree before operation; the second set comprises an identification interval set of each layer of nodes of the radix tree after operation; the node identification change information comprises an identification interval of each layer of nodes to be changed;
determining the expected identity set of the nodes in the radix tree according to the first set and the node identity change information comprises:
when the operation is insertion, respectively solving a union set of the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the union set of all layers as the expected identification set;
when the operation is deletion, respectively solving difference sets of the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the difference sets of all the layers as the expected identification set;
before determining the expected identification set of the node in the radix tree according to the first set and the node identification change information, the method further comprises the following steps:
and determining the identifier of each layer of father node of the related leaf node according to the identifiers of one or more leaf nodes in the radix tree related to the operation to obtain the identifier interval of each layer of nodes to be changed.
2. An apparatus for monitoring an internal structure of a radix tree to perform a test, comprising:
the prediction unit is used for acquiring an identification set of nodes in the operation front base tree as a first set; determining a predicted identification set of the nodes in the radix tree according to the first set and the node identification change information; the identity of each node in the radix tree includes information describing the shortest path from a root node to that node;
the comparison unit is used for acquiring the identification set of the nodes in the radix tree after operation as a second set; comparing the second set with the expected identification set, obtaining a monitoring result according to the comparison result, and judging that the radix tree has errors when the comparison result is different;
the determining unit is used for determining the identifier of each layer of father node of the related leaf node according to the identifiers of one or more leaf nodes in the radix tree related to the operation to obtain the identifier interval of each layer of nodes to be changed;
wherein the obtaining, by the prediction unit and the comparison unit, the identification set of the nodes in the radix tree includes:
finding a first non-empty node of each layer from a root node of the radix tree; respectively traversing all nodes of each layer from the found nodes of each layer through a pointer which is maintained by each node and points to the right node, recording the identifiers of the nodes of the layer, and obtaining the identifier set of each layer of nodes after traversing is completed;
the identity of the node is a sequence of layer indices for each node in a shortest path from a root node to the node; different levels of the radix tree correspond to different levels of level indices; different child nodes of each node in the radix tree are distinguished by using the layer indexes of the level corresponding to the layer where the node is located;
the layer index comprises numbers and/or letters; the first set comprises a set of identification intervals of each layer of nodes of the radix tree before operation; the second set comprises an identification interval set of each layer of nodes of the radix tree after operation; the node identification change information comprises an identification interval of each layer of nodes to be changed;
the determining, by the prediction unit, the expected identity set of the nodes in the radix tree according to the first set and the node identity change information includes:
when the operation is insertion, respectively solving a union set of the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the union set of all layers as the expected identification set; and when the operation is deletion, respectively solving a difference set for the identification interval of the node to be changed of each layer and the identification interval set of the layer in the first set, and taking the difference sets of all the layers as the expected identification set.
3. A data processing electronic device for monitoring internal structures of a radix tree to implement a test, comprising a processor, a memory; the method is characterized in that:
the memory is used for storing a program for monitoring the internal structure of the radix tree; the program for monitoring the internal structure of a radix tree, when read and executed by the processor, performs the method of claim 1.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610539360.8A CN107590160B (en) | 2016-07-08 | 2016-07-08 | Method and device for monitoring internal structure of radix tree to realize test |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610539360.8A CN107590160B (en) | 2016-07-08 | 2016-07-08 | Method and device for monitoring internal structure of radix tree to realize test |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107590160A CN107590160A (en) | 2018-01-16 |
CN107590160B true CN107590160B (en) | 2021-08-27 |
Family
ID=61045359
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610539360.8A Active CN107590160B (en) | 2016-07-08 | 2016-07-08 | Method and device for monitoring internal structure of radix tree to realize test |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107590160B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110781255B (en) * | 2019-08-29 | 2024-04-05 | 腾讯大地通途(北京)科技有限公司 | Road aggregation method, road aggregation device and electronic equipment |
CN111597185B (en) * | 2020-04-01 | 2023-04-28 | 深圳英飞拓仁用信息有限公司 | Real-time state number rapid statistical method based on tree structure resource distribution |
CN112000847B (en) * | 2020-08-19 | 2021-07-20 | 东北大学 | GPU parallel-based adaptive radix tree dynamic indexing method |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101197734A (en) * | 2007-12-27 | 2008-06-11 | 华为技术有限公司 | Test approach and device for command line interface |
CN104407977A (en) * | 2014-12-08 | 2015-03-11 | 北京航空航天大学 | Model detection based automatic joint debugging test method for staged task system |
CN104750612A (en) * | 2015-03-31 | 2015-07-01 | 腾讯科技(深圳)有限公司 | File operation testing method and device |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9021449B2 (en) * | 2012-08-16 | 2015-04-28 | Fujitsu Limited | Software regression testing using symbolic execution |
-
2016
- 2016-07-08 CN CN201610539360.8A patent/CN107590160B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101197734A (en) * | 2007-12-27 | 2008-06-11 | 华为技术有限公司 | Test approach and device for command line interface |
CN104407977A (en) * | 2014-12-08 | 2015-03-11 | 北京航空航天大学 | Model detection based automatic joint debugging test method for staged task system |
CN104750612A (en) * | 2015-03-31 | 2015-07-01 | 腾讯科技(深圳)有限公司 | File operation testing method and device |
Non-Patent Citations (1)
Title |
---|
重识算法(3)--用458329个测试用例全面测试二叉树和线索二叉树的遍历算法;BIT祝威;《cnblog https://www.cnblogs.com/bitzhuwei/p/algorithm-3-458329-test-cases-4-threaded-binary-tree-traverse.html》;20140722;第4页 * |
Also Published As
Publication number | Publication date |
---|---|
CN107590160A (en) | 2018-01-16 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10649838B2 (en) | Automatic correlation of dynamic system events within computing devices | |
US20210326885A1 (en) | Method and Apparatus of Identifying a Transaction Risk | |
US10628449B2 (en) | Method and apparatus for processing database data in distributed database system | |
CN111600746B (en) | Network fault positioning method, device and equipment | |
CN110855473A (en) | Monitoring method, device, server and storage medium | |
KR20190020105A (en) | Method and device for distributing streaming data | |
CN111475105B (en) | Monitoring data storage method, monitoring data storage device, monitoring data server and storage medium | |
EP3371717A1 (en) | Virtual edge of a graph database | |
CN107590160B (en) | Method and device for monitoring internal structure of radix tree to realize test | |
JP2020057416A (en) | Method and device for processing data blocks in distributed database | |
CN113704790A (en) | Abnormal log information summarizing method and computer equipment | |
CN107515807B (en) | Method and device for storing monitoring data | |
CN113901131A (en) | Index-based on-chain data query method and device | |
CN112131288A (en) | Data source access processing method and device | |
CN115185778A (en) | Database monitoring method and device | |
CN112286966A (en) | Data stream processing method, data stream recovery method, data stream processing device, data stream recovery device and storage medium | |
CN109992701B (en) | Chain table implementation method, device and equipment and readable storage medium | |
CN114666231B (en) | Visual operation and maintenance management method and system under multi-cloud environment and storage medium | |
CN113760845A (en) | Log processing method, system, device, client and storage medium | |
CN118113699A (en) | Data writing method, device, equipment and medium applied to distributed storage | |
CN111723146A (en) | Method for monitoring database, management system and storage medium | |
CN113971160A (en) | Data fusion processing method, device, equipment and storage medium | |
CN117931796A (en) | Data processing method, device, equipment and medium for distributed storage | |
CN117762963A (en) | Paging query method, device, electronic equipment and medium | |
CN117541045A (en) | Resource transfer risk detection method, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |