A code-dependent retrieval method
By obtaining the code base dependency information, initializing the path public intersection pointer and marking the R node and the B node, the code dependency path retrieval is optimized, the problem of low code dependency retrieval efficiency in the existing technology is solved, and efficient code dependency path retrieval is achieved.
Patent Information
- Application Number
- CN202410169022.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-06
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-02-06
AI Technical Summary
Existing code dependency retrieval methods have high time complexity when processing a large number of code libraries, and it is difficult to quickly and accurately find all dependent or indirectly dependent code libraries, resulting in low efficiency.
By obtaining dependency information between code libraries, initializing the path public intersection pointer, marking R nodes and B nodes, optimizing the retrieval process of code dependency paths, reducing the number of nodes, achieving parallel processing, and improving retrieval efficiency.
It effectively reduces the retrieval time of code dependency paths, improves retrieval efficiency, alleviates the problem that time complexity is affected by the number of nodes, and achieves accurate code dependency path retrieval.
Smart Images

Figure CN117951315B
Abstract
Description
Technical Field
[0001] The invention belongs to the field of software engineering technology and computer software maintenance, and specifically relates to a code dependency retrieval method. Background Art
[0002] In the context of modern software development, by relying on other code bases, developers can reuse and share codes, thus avoiding unnecessary duplication of work and significantly improving development efficiency and code quality. Today's software development projects rely on a large number of code bases, and the calls between them are complex. When a code base has security or defect problems, other code bases that depend on or indirectly depend on the code base will be affected. We need to retrieve all code bases that a code base depends on or indirectly depends on, so as to find problems and maintain them in time. Therefore, after establishing a huge dependency relationship between code bases, code dependency retrieval technology is a key issue. However, existing methods, such as depth-first traversal methods and breadth-first traversal methods, have a time complexity that is affected by the number of nodes, and it takes a lot of time to retrieve code dependencies. Therefore, a method is needed to reduce the impact of the number of nodes on the retrieval time and accurately find all dependent or indirectly dependent code bases. Summary of the invention
[0003] The purpose of the present invention is to propose a code-dependent retrieval method to solve one or more technical problems existing in the prior art and at least provide a beneficial choice or create conditions.
[0004] The present invention provides a code dependency retrieval method, which obtains dependency information between code libraries and obtains an original node; initializes a path common intersection pointer for the original node to obtain an initial node; marks an R node and a B node for the initial node to obtain an initial marked node; initializes a path common intersection pointer for the initial marked node to obtain a path node; specifies a code library, and retrieves all code dependency paths of the specified code library in the path node.
[0005] In order to achieve the above object, according to one aspect of the present invention, a method for retrieving code dependency is provided, the method comprising the following steps:
[0006] S100, obtaining dependency information between code libraries and obtaining original nodes;
[0007] S200, initializing the path common intersection pointer of the original node to obtain the initial node;
[0008] S300, marking the R node and the B node of the initial node to obtain the initial marked node;
[0009] S400, initializing the path common intersection pointer of the initial marked node to obtain the path node;
[0010] S500, specify a code base, and retrieve all code dependency paths of the specified code base in a path node.
[0011] Furthermore, in S100, the dependency information between code libraries is obtained, and the method for obtaining the original node is:
[0012] S101, obtain code libraries and dependency information between code libraries, and record the total number of code libraries obtained as N, wherein a code library is a packaged set of program files, and the dependency information between code libraries is a set of information that any code library depends on a different code library. Code library A depends on code library B, which means that code library A calls code library B inside it, wherein code library A and code library B refer to any code library, but code library A and code library B are not the same code library;
[0013] S102, N code bases are used as N nodes, the nodes retain the identification information of the corresponding code bases and the names of the code bases, and a path public intersection pointer is set for each node, wherein the identification information of a code base can uniquely identify a code base, and the path public intersection pointer is a variable used to store the identification information of the code base. The path public intersection pointer of a node points to a certain node, indicating that the path public intersection pointer of the node is the identification information of a certain node, and the identification information of the node is the identification information of the code base corresponding to the node;
[0014] S103, executing S104 on the N code bases in sequence according to the dependency information between the code bases;
[0015] S104, temporarily record the node corresponding to the code library as ActNode, obtain all code libraries that the code library depends on and temporarily record their corresponding nodes as DepNode, temporarily record the collection of all DepNodes as DepNodes, and execute S105;
[0016] S105, retaining the identification information of all DepNodes in DepNodes in ActNode, and calling the identification information the dependency relationship of ActNode, that is, the nodes having the dependency relationship with ActNode are all DepNodes in DepNodes, and executing S106;
[0017] S106, executing S107 in sequence for all DepNodes in DepNodes;
[0018] S107, retaining the identification information of the ActNode in the node, and calling the identification information the dependency relationship of the node, that is, the node that has a dependency relationship with the node is the ActNode;
[0019] S108, after executing S103, the N nodes corresponding to the obtained N code bases are the original nodes.
[0020] Furthermore, in S200 and S400, the method of initializing the path common intersection pointer is specifically:
[0021] S201, for all nodes that are not B nodes, set their path public intersection pointers to null, where null means that the value stored in the path public intersection pointer is None, and None means that it does not point to any node;
[0022] S202, pointing the path common intersection pointer of the node without dependency relationship to the node itself, and executing S203 for the nodes without dependency relationship in sequence;
[0023] S203, check whether the node is an R node. If it is an R node, for the node that has a dependent relationship with the node and whose path public intersection pointer points to the node, set its path public intersection pointer to be the same as the path public intersection pointer of the node, and execute S204 on it in sequence, and execute S205 on the remaining nodes that have a dependent relationship with the node in sequence. If it is not an R node, execute S205 on the nodes that have a dependent relationship with the node in sequence, wherein the same path public intersection pointer of two nodes indicates that the path public intersection pointers of the two nodes point to the same node;
[0024] S204, executing S205 in sequence on the nodes that have a dependent relationship with the node;
[0025] S205, check whether the path public intersection pointer of the node is empty, if not empty, the node is executed, if empty, execute S206;
[0026] S206, check whether the total number of nodes that have a dependency relationship with the node is equal to 1. If it is equal to 1, set the path common intersection pointer of the node to be the same as the path common intersection pointer of the nodes that have a dependency relationship with the node, and execute S203. If it is not equal to 1, execute S207;
[0027] S207, check whether there is a node with a null path common intersection pointer among the nodes that have a dependency relationship with the node, if so, the execution of the node is completed, if not, execute S208;
[0028] S208, check whether the path public intersection pointers of the nodes that have a dependency relationship with the node are the same. If they are the same, set the path public intersection pointer of the node to be the same as the path public intersection pointer of the nodes that have a dependency relationship with the node, and execute S203. If they are not the same, set the path public intersection pointer of the node to point to the node itself, and execute S203.
[0029] Therefore, by initializing the path common intersection pointer method, a suitable node can be specified for the path common intersection pointer of the node. Through the path common intersection pointer of the node, a node that all code dependency paths that can jump to the node must pass through is retrieved, and the target node to be jumped to has the largest path length from the node, where the path length refers to the number of nodes on a code dependency path.
[0030] Beneficial effect: Through the common intersection pointer of the node path, the retrieval of the code dependency path reduces the number of nodes to be retrieved by the current thread or process (i.e., the main thread or main process, relative to the parallel new thread or new process), and through the common intersection pointer of the node path, some nodes of the code dependency path can be processed in parallel, thereby alleviating the problem of time complexity being affected by the number of nodes and improving the efficiency of retrieving the code dependency path.
[0031] Further, in S300, the method of marking the R node and the B node for the initial node to obtain the initial marked node is:
[0032] S301, grouping the initial nodes using the Linear Deterministic Greedy partitioning algorithm to obtain S groups, where S is a positive integer;
[0033] S302, calculate the bifurcation rate F of S groups, the bifurcation rate of the i-th group is F i =1-P i / Q i , where i is a positive integer and i is less than or equal to S, P i is the total number of nodes in the i-th group of nodes whose path common intersection pointers point to the path common intersection points, Q i is the total number of nodes in the i-th group, and the path common intersection point is defined as the node pointed to by more than one path common intersection pointer;
[0034] S303, for the groups whose bifurcation rate is higher than the average crossover rate among the S groups, they are divided into the SC class, and there are SS groups in the SC class, among which the average bifurcation rate F avg The calculation method is , SS is an integer greater than or equal to 0;
[0035] S304, mark all the common intersection points of the paths in the SC class SS groups as R nodes, and mark the nodes whose common intersection pointers of the paths in each R node group point to the same group of R nodes as B nodes, and finally obtain the N nodes as the initial marked nodes, wherein the N nodes include marked nodes and unmarked nodes.
[0036] In order to further improve the efficiency of calculation and reduce the number of marked nodes without reducing the effectiveness of the method, preferably, in S300, the method of marking the initial nodes with R nodes and B nodes to obtain the initial marked nodes is:
[0037] S301, grouping the initial nodes using the Linear Deterministic Greedy partitioning algorithm to obtain S groups, where S is a positive integer. In order to balance the number of each group, preferably, grouping is performed according to the following steps:
[0038] S301-1, the currently visited node queue is called SL, where the node queue SL is arranged in the order in which the nodes are added, the first position of SL is called the head of the queue, and the last position of SL is called the tail of the queue. When a new node joins SL, the new node is placed at the tail of the queue. The visited nodes represent the nodes that have completed grouping or have joined SL.
[0039] S301-2, execute S301-3 in sequence for nodes that do not have dependencies;
[0040] S301-3, check whether the node has not been visited, if so, add the node to the SL and execute S301-4, if not, the step is completed;
[0041] S301-4, determine whether the number of nodes in SL is greater than or equal to K, if so, execute S301-9, if not, execute S301-5, where K is the number of nodes that can be traversed within 3 seconds or is optionally selected from a value greater than 0 based on device performance and running time;
[0042] S301-5, check whether there are nodes that have a dependency relationship with the SL team head node and are not in the SL. If so, add these existing nodes to the SL in sequence, and place the SL team head node at the end of the team, and finally execute S301-4. If not, execute S301-6, where when the SL team head node is placed at the end of the team, the node in the original second position becomes the new team head node;
[0043] S301-6, record the number of nodes in the current SL as n, record the counting variable as count, set count to 1, and execute S301-7;
[0044] S301-7, determine whether count is equal to n, if yes, execute S301-9, if not, place the SL team head node at the end of the team, add 1 to count, and execute S301-8;
[0045] S301-8, check whether there are nodes that have a dependency relationship with the SL team head node and are not in the SL. If so, add these existing nodes to the SL in sequence, and then place the SL team head node at the end of the team, and finally execute S301-4. If not, execute S301-7;
[0046] S301-9, group the nodes in the current SL into a group, complete a grouping, and execute S301-10;
[0047] S301-10, check whether there are nodes that have a dependency relationship with the nodes in SL and are not in SL. If so, set SL to have no nodes, and execute S301-3 for these existing nodes in sequence. If not, set SL to have no nodes. This step is completed. Setting SL to have no nodes means clearing the nodes in the node queue SL, that is, there are no nodes in SL.
[0048] S302, calculate the bifurcation rate F of S groups, the bifurcation rate of the i-th group is F i =1-P i / Q i , where i is a positive integer and i is less than or equal to S, P i is the total number of nodes in the i-th group of nodes whose path common intersection pointers point to the path common intersection points, Q i is the total number of nodes in the i-th group, and the path common intersection point is defined as the node pointed to by more than one path common intersection pointer;
[0049] S303, for the groups whose bifurcation rate is higher than the average crossover rate among the S groups, they are divided into the SC class, and there are SS groups in the SC class, among which the average bifurcation rate F avg The calculation method is , SS is an integer greater than or equal to 0;
[0050] S304, remember SC i For the i-th group in the SC class, obtain all the common intersection points of the paths in each of the SS groups in the SC class and store them in a corresponding list by group, record SC i The corresponding list is SCL i , if SCL i If the number of nodes is 0, then SC i The front SCK with the largest intersection component D i Nodes are stored in SCL iIn the above example, the intersection component D of a node is defined as the total number of nodes that have a dependent relationship with the node, denoted by SC i The jth node in is snode i,j , remember SCL i The jth node in is node i,j , SCK i The calculation formula is: , where i∈[1,SS], j is a positive integer, F sci For SC i The corresponding fork rate, |SC i |For SC i The total number of nodes in the function, D(node) is the function of calculating the intersection components of the node node, and max(a,b) is the larger value between the values a and b.
[0051] S305, for SCL i For each node in , get SC i The public intersection pointer of the middle path points to node i,j Nodes and store them in a list, record node i,j The corresponding storage list is SCSL i,j , remember SCSL i,j The tth node in is node i,j t , where i∈[1,SS], t is a positive integer;
[0052] S306, for SCL i Node in i,j , according to its corresponding SCSL i,j The fork expansion amount Bif is sorted from high to low, and the calculation formula of the fork expansion amount Bif is: , where i∈[1,SS], |SCSL i,j |For SCSL i,j The total number of nodes in, D(node) is the function of calculating the intersection components of the node node;
[0053] S307, for SCL i SCB before sorting i nodes, marked as R nodes, and for each R node group whose common intersection pointer points to the same group of R nodes, marked as B nodes, and the final N nodes are the initial marked nodes, where i∈[1,SS], SCB i The calculation formula is:
[0054] ,|SCL i |For SCLi The total number of nodes in the, min(a,b) is the smaller value selected between value a and value b, N nodes include marked nodes and unmarked nodes.
[0055] Therefore, for the group with a bifurcation rate lower than the average bifurcation rate, the nodes selected by the common intersection points or node intersection components of the current group are used as candidate R nodes, and the bifurcation expansion amount Bif of the candidate R node and its corresponding candidate B node is further calculated to mark the final R node, and finally the corresponding B node is marked according to the final R node. Among them, the node intersection component is selected according to SCK i The formula selects the appropriate number of nodes. Further, according to SCB i The formula selects the appropriate number of R nodes, and the path common intersection points mark the path common intersection pointers that actually play a role. The node intersection component reflects the role played by the node after it is marked as an R node. Furthermore, the fork expansion amount Bif measures the role played by a certain node among multiple nodes after it is marked as an R node according to the intersection components of multiple nodes. Finally, the path common intersection points are created on the appropriate nodes by marking R nodes and B nodes. Furthermore, for the code dependency paths that are not suitable for the initialization path common intersection pointer method, the code dependency paths are optimized by marking R nodes and B nodes, so that the initialization path common intersection pointer method can create a more effective path common intersection point.
[0056] Beneficial effects: By marking R nodes and B nodes, a path common intersection point is created on a suitable node. For code-dependent paths that are not suitable for the method of initializing the path common intersection pointer, the R nodes and B nodes are marked to optimize the code-dependent paths, so that the method of initializing the path common intersection pointer can create a more effective path common intersection point. This improves the effectiveness of the method of initializing the path common intersection pointer, and ultimately improves the efficiency of retrieving code-dependent paths.
[0057] Further, in S500, the code dependency path is a line formed by connecting nodes that have a dependency relationship with the node, and the line is continuous and directional, that is, the nodes that have a dependency relationship with the nodes outside the line are in the line, or the nodes in the line have a dependency relationship with the nodes outside the line, and the nodes outside the line can be connected to the line.
[0058] Further, in S500, the method of retrieving all code dependency paths of the specified code library in the path node is specifically as follows:
[0059] S501, obtaining identification information of a specified code library, obtaining a node with the same identification information in the path node according to the identification information, taking the node as the starting node of the code dependency path, and executing S502 on the node;
[0060] S502, marking the node as visited and storing it in the code dependency path, and executing S503;
[0061] S503, temporarily record the node as S node, check whether the path public intersection pointer of the S node points to itself, if so, execute S502 in sequence for the nodes that have a dependency relationship with the S node and are not marked as visited, if not, temporarily record the node pointed to by the path public intersection pointer of the S node as E node, and execute S504;
[0062] S504, check whether the S node is a B node. If it is a B node, the current thread or process executes S507 on the E node. In a new thread or process, execute S502 in sequence for nodes that have a dependency relationship with the S node and are not marked as visited. If it is not a B node, the current thread or process executes S507 on the E node. In a new thread or process, execute S505 in sequence for nodes that have a dependency relationship with the S node and are not marked as visited.
[0063] S505, marking the node as visited and storing it in the code dependency path, and executing S506;
[0064] S506, check whether there is a node that has a dependency relationship with the node and is not marked as visited. If not, the node is executed. If so, S505 is executed in sequence for the nodes that have a dependency relationship with the node and are not marked as visited.
[0065] S507, check whether the node is marked as visited, if it is marked as visited, the execution of the node is completed, if it is not marked as visited, execute S502.
[0066] The present invention also provides a code-dependent retrieval system, the code-dependent retrieval system comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, the processor implementing the steps in the code-dependent retrieval method when executing the computer program, the code-dependent retrieval system can be run in computing devices such as desktop computers, laptop computers, PDAs, and cloud data centers, and the executable system may include, but is not limited to, a processor, a memory, and a server cluster, and the processor executes the computer program to run in the following system units:
[0067] The original node acquisition unit is used to acquire the dependency information between code bases and obtain the original node therefrom;
[0068] A path common intersection pointer initialization unit, used for initializing a path common intersection pointer for an original node or an initial marked node;
[0069] The initial node marking unit is used to mark the R node and the B node of the initial node;
[0070] A code dependency path retrieval unit is used to retrieve all code dependency paths of a specified code base for a path node;
[0071] The beneficial effects of the present invention are as follows: the present invention provides a code dependency retrieval method and system, which uses only a small amount of storage while accurately retrieving all code dependency paths of a specified node. The number of nodes to be retrieved in the code dependency path is reduced through the common intersection pointer of the node path, and the common intersection pointer of the node path enables some nodes of the code dependency path to be processed in parallel. Furthermore, the R node and the B node are adapted to different code dependency paths, thereby improving the effectiveness of the method, and ultimately alleviating the problem of time complexity being affected by the number of nodes, thereby improving the efficiency of retrieving code dependency paths. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] The above and other features of the present invention will become more obvious by describing in detail the embodiments shown in the accompanying drawings. The same reference numerals in the drawings of the present disclosure represent the same or similar elements. Obviously, the drawings described below are only some embodiments of the present disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0073] Figure 1 Shown is a flow chart of a code-dependent retrieval method;
[0074] Figure 2 Shown is a system structure diagram of a code-dependent retrieval system. DETAILED DESCRIPTION
[0075] The following will be combined with the embodiments and drawings to clearly and completely describe the concept, specific structure and technical effects of the present disclosure, so as to fully understand the purpose, scheme and effect of the present invention. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.
[0076] like Figure 1 The flowchart of a code-dependent retrieval method according to the present invention is shown below. Figure 1 A code-dependent retrieval method according to an embodiment of the present invention is described below.
[0077] The present invention proposes a code dependency retrieval method, which specifically comprises the following steps:
[0078] S100, obtaining dependency information between code libraries and obtaining original nodes;
[0079] S200, initializing the path common intersection pointer of the original node to obtain the initial node;
[0080] S300, marking the R node and the B node of the initial node to obtain the initial marked node;
[0081] S400, initializing the path common intersection pointer of the initial marked node to obtain the path node;
[0082] S500, specify a code base, and retrieve all code dependency paths of the specified code base in a path node.
[0083] Furthermore, in S100, the dependency information between code libraries is obtained, and the method for obtaining the original node is:
[0084] S101, obtain code libraries and dependency information between code libraries, and record the total number of code libraries obtained as N, wherein a code library is a packaged set of program files, and the dependency information between code libraries is a set of information that any code library depends on a different code library. Code library A depends on code library B, which means that code library A calls code library B inside it, wherein code library A and code library B refer to any code library, but code library A and code library B are not the same code library;
[0085] S102, N code bases are used as N nodes, the nodes retain the identification information of the corresponding code bases and the names of the code bases, and a path public intersection pointer is set for each node, wherein the identification information of a code base can uniquely identify a code base, and the path public intersection pointer is a variable used to store the identification information of the code base. The path public intersection pointer of a node points to a certain node, indicating that the path public intersection pointer of the node is the identification information of a certain node, and the identification information of the node is the identification information of the code base corresponding to the node;
[0086] S103, executing S104 on the N code bases in sequence according to the dependency information between the code bases;
[0087] S104, temporarily record the node corresponding to the code library as ActNode, obtain all code libraries that the code library depends on and temporarily record their corresponding nodes as DepNode, temporarily record the collection of all DepNodes as DepNodes, and execute S105;
[0088] S105, retaining the identification information of all DepNodes in DepNodes in ActNode, and calling the identification information the dependency relationship of ActNode, that is, the nodes having the dependency relationship with ActNode are all DepNodes in DepNodes, and executing S106;
[0089] S106, executing S107 in sequence for all DepNodes in DepNodes;
[0090] S107, retaining the identification information of the ActNode in the node, and calling the identification information the dependency relationship of the node, that is, the node that has a dependency relationship with the node is the ActNode;
[0091] S108, after executing S103, the N nodes corresponding to the obtained N code bases are the original nodes.
[0092] Furthermore, in S200 and S400, the method of initializing the path common intersection pointer is specifically:
[0093] S201, for all nodes that are not B nodes, set their path public intersection pointers to null, where null means that the value stored in the path public intersection pointer is None, and None means that it does not point to any node;
[0094] S202, point the path common intersection pointer of the node without dependency relationship to the node itself,
[0095] The nodes execute S203 in sequence;
[0096] S203, check whether the node is an R node. If it is an R node, for the node that has a dependent relationship with the node and whose path public intersection pointer points to the node, set its path public intersection pointer to be the same as the path public intersection pointer of the node, and execute S204 on it in sequence, and execute S205 on the remaining nodes that have a dependent relationship with the node in sequence. If it is not an R node, execute S205 on the nodes that have a dependent relationship with the node in sequence, wherein the same path public intersection pointer of two nodes indicates that the path public intersection pointers of the two nodes point to the same node;
[0097] S204, executing S205 in sequence on the nodes that have a dependent relationship with the node;
[0098] S205, check whether the path public intersection pointer of the node is empty, if not empty, the node is executed, if empty, execute S206;
[0099] S206, check whether the total number of nodes that have a dependency relationship with the node is equal to 1. If it is equal to 1, set the path common intersection pointer of the node to be the same as the path common intersection pointer of the nodes that have a dependency relationship with the node, and execute S203. If it is not equal to 1, execute S207;
[0100] S207, check whether there is a node with a null path common intersection pointer among the nodes that have a dependency relationship with the node, if so, the execution of the node is completed, if not, execute S208;
[0101] S208, check whether the path public intersection pointers of the nodes that have a dependency relationship with the node are the same. If they are the same, set the path public intersection pointer of the node to be the same as the path public intersection pointer of the nodes that have a dependency relationship with the node, and execute S203. If they are not the same, set the path public intersection pointer of the node to point to the node itself, and execute S203.
[0102] Therefore, by initializing the path common intersection pointer method, a suitable node can be specified for the path common intersection pointer of the node. Through the path common intersection pointer of the node, a node that all code dependency paths that can jump to the node must pass through is retrieved, and the target node to be jumped to has the largest path length from the node, where the path length refers to the number of nodes on a code dependency path.
[0103] Further, in S300, the method of marking the R node and the B node for the initial node to obtain the initial marked node is:
[0104] S301, grouping the initial nodes using the Linear Deterministic Greedy partitioning algorithm to obtain S groups, where S is a positive integer;
[0105] S302, calculate the bifurcation rate F of S groups, the bifurcation rate of the i-th group is F i =1-P i / Q i , where i is a positive integer and i is less than or equal to S, P i is the total number of nodes in the i-th group of nodes whose path common intersection pointers point to the path common intersection points, Q i is the total number of nodes in the i-th group, and the path common intersection point is defined as the node pointed to by more than one path common intersection pointer;
[0106] S303, for the groups whose bifurcation rate is higher than the average crossover rate among the S groups, they are divided into the SC class, and there are SS groups in the SC class, among which the average bifurcation rate F avg The calculation method is , SS is an integer greater than or equal to 0;
[0107] S304, mark all the common intersection points of the paths in the SC class SS groups as R nodes, and mark the nodes whose common intersection pointers of the paths in each R node group point to the same group of R nodes as B nodes, and finally obtain the N nodes as the initial marked nodes, wherein the N nodes include marked nodes and unmarked nodes.
[0108] In order to further improve the efficiency of calculation and reduce the number of marked nodes without reducing the effectiveness of the method, preferably, in S300, the method of marking the initial nodes with R nodes and B nodes to obtain the initial marked nodes is:
[0109] S301, grouping the initial nodes using the Linear Deterministic Greedy partitioning algorithm to obtain S groups, where S is a positive integer. In order to balance the number of each group, preferably, grouping is performed according to the following steps:
[0110] S301-1, the currently visited node queue is called SL, where the node queue SL is arranged in the order in which the nodes are added, the first position of SL is called the head of the queue, and the last position of SL is called the tail of the queue. When a new node joins SL, the new node is placed at the tail of the queue. The visited nodes represent the nodes that have completed grouping or have joined SL.
[0111] S301-2, execute S301-3 in sequence for nodes that do not have dependencies;
[0112] S301-3, check whether the node has not been visited, if so, add the node to the SL and execute S301-4, if not, the step is completed;
[0113] S301-4, determine whether the number of nodes in SL is greater than or equal to K, if so, execute S301-9, if not, execute S301-5, where K is the number of nodes that can be traversed within 3 seconds or is optionally selected from a value greater than 0 based on device performance and running time;
[0114] S301-5, check whether there are nodes that have a dependency relationship with the SL team head node and are not in the SL. If so, add these existing nodes to the SL in sequence, and place the SL team head node at the end of the team, and finally execute S301-4. If not, execute S301-6, where when the SL team head node is placed at the end of the team, the node in the original second position becomes the new team head node;
[0115] S301-6, record the number of nodes in the current SL as n, record the counting variable as count, set count to 1, and execute S301-7;
[0116] S301-7, determine whether count is equal to n, if yes, execute S301-9, if not, place the SL team head node at the end of the team, add 1 to count, and execute S301-8;
[0117] S301-8, check whether there are nodes that have a dependency relationship with the SL team head node and are not in the SL. If so, add these existing nodes to the SL in sequence, and then place the SL team head node at the end of the team, and finally execute S301-4. If not, execute S301-7;
[0118] S301-9, group the nodes in the current SL into a group, complete a grouping, and execute S301-10;
[0119] S301-10, check whether there are nodes that have a dependency relationship with the nodes in SL and are not in SL. If so, set SL to have no nodes, and execute S301-3 for these existing nodes in sequence. If not, set SL to have no nodes. This step is completed. Setting SL to have no nodes means clearing the nodes in the node queue SL, that is, there are no nodes in SL.
[0120] S302, calculate the bifurcation rate F of S groups, the bifurcation rate of the i-th group is F i =1-P i / Q i , where i is a positive integer and i is less than or equal to S, P i is the total number of nodes in the i-th group of nodes whose path common intersection pointers point to the path common intersection points, Q i is the total number of nodes in the i-th group, and the path common intersection point is defined as the node pointed to by more than one path common intersection pointer;
[0121] S303, for the groups whose bifurcation rate is higher than the average crossover rate among the S groups, they are divided into the SC class, and there are SS groups in the SC class, among which the average bifurcation rate F avg The calculation method is , SS is an integer greater than or equal to 0;
[0122] S304, remember SC i For the i-th group in the SC class, obtain all the common intersection points of the paths in each of the SS groups in the SC class and store them in a corresponding list by group, record SC i The corresponding list is SCL i , if SCL i If the number of nodes is 0, then SC i The front SCK with the largest intersection component D i Nodes are stored in SCLi In the above example, the intersection component D of a node is defined as the total number of nodes that have a dependent relationship with the node, denoted by SC i The jth node in is snode i,j , remember SCL i The jth node in is node i,j , SCK i The calculation formula is: , where i∈[1,SS], j is a positive integer, F sci For SC i The corresponding fork rate, |SC i |For SC i The total number of nodes in the function, D(node) is the function of calculating the intersection components of the node node, and max(a,b) is the larger value between the values a and b.
[0123] S305, for SCL i For each node in , get SC i The public intersection pointer of the middle path points to node i,j Nodes and store them in a list, record node i,j The corresponding storage list is SCSL i,j , remember SCSL i,j The tth node in is node i,j t , where i∈[1,SS], t is a positive integer;
[0124] S306, for SCL i Node in i,j , according to its corresponding SCSL i,j The fork expansion amount Bif is sorted from high to low, and the calculation formula of the fork expansion amount Bif is: , where i∈[1,SS], |SCSL i,j |For SCSL i,j The total number of nodes in, D(node) is the function of calculating the intersection components of the node node;
[0125] S307, for SCL i SCB before sorting i nodes, marked as R nodes, and for each R node group whose common intersection pointer points to the same group of R nodes, marked as B nodes, and the final N nodes are the initial marked nodes, where i∈[1,SS], SCB i The calculation formula is:
[0126] ,|SCL i|For SCL i The total number of nodes in the, min(a,b) is the smaller value selected between value a and value b, N nodes include marked nodes and unmarked nodes.
[0127] Therefore, for the group with a bifurcation rate lower than the average bifurcation rate, the nodes selected by the common intersection points or node intersection components of the current group are used as candidate R nodes, and the bifurcation expansion amount Bif of the candidate R node and its corresponding candidate B node is further calculated to mark the final R node, and finally the corresponding B node is marked according to the final R node. Among them, the node intersection component is selected according to SCK i The formula selects the appropriate number of nodes. Further, according to SCB i The formula selects the appropriate number of R nodes, and the path common intersection points mark the path common intersection pointers that actually play a role. The node intersection component reflects the role played by the node after it is marked as an R node. Furthermore, the fork expansion amount Bif measures the role played by a certain node among multiple nodes after it is marked as an R node according to the intersection components of multiple nodes. Finally, the path common intersection points are created on the appropriate nodes by marking R nodes and B nodes. Furthermore, for the code dependency paths that are not suitable for the initialization path common intersection pointer method, the code dependency paths are optimized by marking R nodes and B nodes, so that the initialization path common intersection pointer method can create a more effective path common intersection point.
[0128] Further, in S500, the code dependency path is a line formed by connecting nodes that have a dependency relationship with the node, and the line is continuous and directional, that is, the nodes that have a dependency relationship with the nodes outside the line are in the line, or the nodes in the line have a dependency relationship with the nodes outside the line, and the nodes outside the line can be connected to the line.
[0129] Further, in S500, the method of retrieving all code dependency paths of the specified code library in the path node is specifically as follows:
[0130] S501, obtaining identification information of a specified code library, obtaining a node with the same identification information in the path node according to the identification information, taking the node as the starting node of the code dependency path, and executing S502 on the node;
[0131] S502, marking the node as visited and storing it in the code dependency path, and executing S503;
[0132] S503, temporarily record the node as S node, check whether the path public intersection pointer of the S node points to itself, if so, execute S502 in sequence for the nodes that have a dependency relationship with the S node and are not marked as visited, if not, temporarily record the node pointed to by the path public intersection pointer of the S node as E node, and execute S504;
[0133] S504, check whether the S node is a B node. If it is a B node, the current thread or process executes S507 on the E node. In a new thread or process, execute S502 in sequence for nodes that have a dependency relationship with the S node and are not marked as visited. If it is not a B node, the current thread or process executes S507 on the E node. In a new thread or process, execute S505 in sequence for nodes that have a dependency relationship with the S node and are not marked as visited.
[0134] S505, marking the node as visited and storing it in the code dependency path, and executing S506;
[0135] S506, check whether there is a node that has a dependency relationship with the node and is not marked as visited. If not, the node is executed. If so, S505 is executed in sequence for the nodes that have a dependency relationship with the node and are not marked as visited.
[0136] S507, check whether the node is marked as visited, if it is marked as visited, the execution of the node is completed, if it is not marked as visited, execute S502.
[0137] The present invention also includes a code-dependent retrieval system, which runs in any computing device such as a desktop computer, a laptop computer, a PDA or a cloud data center. The computing device includes: a processor, a memory and a computer program stored in the memory and running on the processor. When the processor executes the computer program, the steps in the code-dependent retrieval method are implemented. The executable system may include, but is not limited to, a processor, a memory, and a server cluster.
[0138] The embodiment of the present disclosure provides a code-dependent retrieval system, such as Figure 2 As shown, a code-dependent retrieval system of this embodiment includes: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps in the above-mentioned code-dependent method embodiment are implemented. The processor executes the computer program to run in the following system units:
[0139] The original node acquisition unit is used to acquire the dependency information between code bases and obtain the original node therefrom;
[0140] A path common intersection pointer initialization unit, used for initializing a path common intersection pointer for an original node or an initial marked node;
[0141] The initial node marking unit is used to mark the R node and the B node of the initial node;
[0142] A code dependency path retrieval unit is used to retrieve all code dependency paths of a specified code base for a path node;
[0143] Among them, preferably, all undefined variables in the present invention, if not clearly defined, can be manually set thresholds.
[0144] The code-dependent retrieval system can be run on computing devices such as desktop computers, laptops, PDAs, and cloud data centers. The code-dependent retrieval system includes, but is not limited to, processors and memories. Those skilled in the art will appreciate that the example is merely an example of a code-dependent retrieval method and system, and does not constitute a limitation on a code-dependent retrieval method and system, and may include more or fewer components than the example, or a combination of certain components, or different components. For example, the code-dependent retrieval system may also include input and output devices, network access devices, buses, and the like.
[0145] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete component gate circuits or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the code-dependent retrieval system, and uses various interfaces and lines to connect the various sub-areas of the entire code-dependent retrieval system.
[0146] The memory can be used to store the computer program and / or module, and the processor implements the various functions of the code-dependent retrieval method and system by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0147] The present disclosure provides a code dependency retrieval method and system, which obtains dependency information between code libraries and obtains original nodes; initializes the path common intersection pointer of the original node to obtain an initial node; marks the initial node with an R node and a B node to obtain an initial marked node; initializes the path common intersection pointer of the initial marked node to obtain a path node; specifies the code library, and retrieves all code dependency paths of the specified code library in the path node, so that all code dependency paths of the specified node can be accurately retrieved while only a small amount of storage is used, and the number of nodes to be retrieved in the code dependency path is reduced through the path common intersection pointer of the node, and the path common intersection pointer of the node can make some nodes of the code dependency path processed in parallel, and further, the R node and the B node are adapted to different code dependency paths, so as to improve the effectiveness of the method, and finally alleviate the problem that the time complexity is affected by the number of nodes, and improve the efficiency of retrieving code dependency paths.
[0148] Although the description of the present disclosure has been quite detailed and specifically describes several described embodiments, it is not intended to be limited to any of these details or embodiments or any particular embodiment, so as to effectively cover the intended scope of the present disclosure. In addition, the above description of the present disclosure is based on the embodiments foreseeable by the inventors, and its purpose is to provide a useful description, and those non-substantial changes to the present disclosure that have not yet been foreseen may still represent equivalent changes to the present disclosure.
Claims
1. A code-dependent retrieval method, characterized in that: The method comprises the following steps: S100, obtaining dependency information between code libraries and obtaining original nodes; S200, initializing the path common intersection pointer of the original node to obtain the initial node; S300, marking the R node and the B node of the initial node to obtain the initial marked node; S400, initializing the path common intersection pointer of the initial marked node to obtain the path node; S500, specifying a code base, and retrieving all code dependency paths of the specified code base in a path node; In S100, the dependency information between code libraries is obtained, and the method for obtaining the original node is: S101, obtain code libraries and dependency information between code libraries, and record the total number of code libraries obtained as N, wherein a code library is a packaged set of program files, and the dependency information between code libraries is a set of information that any code library depends on a different code library. Code library A depends on code library B, which means that code library A calls code library B inside it, wherein code library A and code library B refer to any code library, but code library A and code library B are not the same code library; S102, N code bases are used as N nodes, the nodes retain the identification information of the corresponding code bases and the names of the code bases, and a path public intersection pointer is set for each node, wherein the identification information of a code base can uniquely identify a code base, and the path public intersection pointer is a variable used to store the identification information of the code base. The path public intersection pointer of a node points to a certain node, indicating that the path public intersection pointer of the node is the identification information of a certain node, and the identification information of the node is the identification information of the code base corresponding to the node; S103, executing S104 on the N code bases in sequence according to the dependency information between the code bases; S104, temporarily record the node corresponding to the code library as ActNode, obtain all code libraries that the code library depends on and temporarily record their corresponding nodes as DepNode, temporarily record the collection of all DepNodes as DepNodes, and execute S105; S105, retaining the identification information of all DepNodes in DepNodes in ActNode, and calling the identification information the dependency relationship of ActNode, that is, the nodes having the dependency relationship with ActNode are all DepNodes in DepNodes, and executing S106; S106, executing S107 in sequence for all DepNodes in DepNodes; S107, retaining the identification information of the ActNode in the node, and calling the identification information the dependency relationship of the node, that is, the node that has a dependency relationship with the node is the ActNode; S108, after executing S103, the N nodes corresponding to the obtained N code bases are the original nodes; In S200 and S400, the method of initializing the path common intersection pointer is specifically: S201, for all nodes that are not B nodes, set their path public intersection pointers to null, where null means that the value stored in the path public intersection pointer is None, and None means that it does not point to any node; S202, point the path common intersection pointer of the node without dependency relationship to the node itself, The nodes execute S203 in sequence; S203, check whether the node is an R node. If it is an R node, for the node that has a dependent relationship with the node and whose path public intersection pointer points to the node, set its path public intersection pointer to be the same as the path public intersection pointer of the node, and execute S204 on it in sequence, and execute S205 on the remaining nodes that have a dependent relationship with the node in sequence. If it is not an R node, execute S205 on the nodes that have a dependent relationship with the node in sequence, wherein the same path public intersection pointer of two nodes indicates that the path public intersection pointers of the two nodes point to the same node; S204, executing S205 in sequence on the nodes that have a dependent relationship with the node; S205, check whether the path public intersection pointer of the node is empty, if not empty, the node is executed, if empty, execute S206; S206, check whether the total number of nodes that have a dependency relationship with the node is equal to 1. If it is equal to 1, set the path common intersection pointer of the node to be the same as the path common intersection pointer of the nodes that have a dependency relationship with the node, and execute S203. If it is not equal to 1, execute S207; S207, check whether there is a node with a null path common intersection pointer among the nodes that have a dependency relationship with the node, if so, the execution of the node is completed, if not, execute S208; S208, check whether the path public intersection pointers of the nodes that have a dependency relationship with the node are all the same. If they are the same, set the path public intersection pointer of the node to be the same as the path public intersection pointer of the nodes that have a dependency relationship with the node, and execute S203. If they are not the same, set the path public intersection pointer of the node to point to the node itself, and execute S203. In S300, the method of marking the initial node R node and the initial node B node to obtain the initial marked node is: S301, grouping the initial nodes using the Linear Deterministic Greedy partitioning algorithm to obtain S groups, where S is a positive integer; S302, calculate the bifurcation rate F of S groups, the bifurcation rate of the i-th group is F i =1-P i / Q i , where i is a positive integer and i is less than or equal to S, P i is the total number of nodes in the i-th group of nodes whose path common intersection pointers point to the path common intersection points, Q i is the total number of nodes in the i-th group, and the path common intersection point is defined as the node pointed to by more than one path common intersection pointer; S303, for the groups whose bifurcation rate is higher than the average crossover rate among the S groups, they are divided into the SC class, and there are SS groups in the SC class, among which the average bifurcation rate F avg The calculation method is , SS is an integer greater than or equal to 0; S304, mark all the common intersection points of the paths in the SC class SS groups as R nodes, and mark the nodes whose common intersection pointers of the paths in each R node group point to the same group of R nodes as B nodes, and finally obtain the N nodes as the initial marked nodes, wherein the N nodes include marked nodes and unmarked nodes.
2. A code-dependent retrieval method according to claim 1, characterized in that: In S500, the code dependency path is a line formed by connecting nodes that have a dependency relationship with the node, and the line is continuous and directional, that is, the nodes that have a dependency relationship with the nodes outside the line are in the line, or the nodes in the line have a dependency relationship with the nodes outside the line, and the nodes outside the line can be connected to the line.
3. A code-dependent retrieval method according to claim 1, characterized in that: In S500, the method of retrieving all code dependency paths of the specified code library in the path node of the specified code library is specifically as follows: S501, obtaining identification information of a specified code library, obtaining a node with the same identification information in the path node according to the identification information, taking the node as the starting node of the code dependency path, and executing S502 on the node; S502, marking the node as visited and storing it in the code dependency path, and executing S503; S503, temporarily record the node as S node, check whether the path public intersection pointer of the S node points to itself, if so, execute S502 in sequence for the nodes that have a dependency relationship with the S node and are not marked as visited, if not, temporarily record the node pointed to by the path public intersection pointer of the S node as E node, and execute S504; S504, check whether the S node is a B node. If it is a B node, the current thread or process executes S507 on the E node. In a new thread or process, execute S502 in sequence for nodes that have a dependency relationship with the S node and are not marked as visited. If it is not a B node, the current thread or process executes S507 on the E node. In a new thread or process, execute S505 in sequence for nodes that have a dependency relationship with the S node and are not marked as visited. S505, marking the node as visited and storing it in the code dependency path, and executing S506; S506, check whether there is a node that has a dependency relationship with the node and is not marked as visited. If not, the node is executed. If so, S505 is executed in sequence for the nodes that have a dependency relationship with the node and are not marked as visited. S507, check whether the node is marked as visited, if it is marked as visited, the execution of the node is completed, if it is not marked as visited, execute S502.
4. A code-dependent retrieval system, characterized in that: The code-dependent retrieval system runs in any computing device such as a desktop computer, a laptop computer or a cloud data center. The computing device includes: a processor, a memory and a computer program stored in the memory and running on the processor. When the processor executes the computer program, the steps in the code-dependent retrieval method as described in any one of claims 1 to 3 are implemented.
