CN114168591A - Method for searching tree structure data path node - Google Patents

Method for searching tree structure data path node Download PDF

Info

Publication number
CN114168591A
CN114168591A CN202111331767.9A CN202111331767A CN114168591A CN 114168591 A CN114168591 A CN 114168591A CN 202111331767 A CN202111331767 A CN 202111331767A CN 114168591 A CN114168591 A CN 114168591A
Authority
CN
China
Prior art keywords
node
authority
layer
tree
list
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.)
Pending
Application number
CN202111331767.9A
Other languages
Chinese (zh)
Inventor
瞿康宁
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sichuan Qiruike Technology Co Ltd
Original Assignee
Sichuan Qiruike Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Sichuan Qiruike Technology Co Ltd filed Critical Sichuan Qiruike Technology Co Ltd
Priority to CN202111331767.9A priority Critical patent/CN114168591A/en
Publication of CN114168591A publication Critical patent/CN114168591A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/30Authentication, i.e. establishing the identity or authorisation of security principals
    • G06F21/45Structures or tools for the administration of authentication
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Computer Hardware Design (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Storage Device Security (AREA)

Abstract

The invention discloses a method for searching tree structure data path nodes, which comprises the following steps: after receiving a leaf node id list needing to be stored, acquiring tree structure data; converting the tree structure data into hierarchical structure data in a hierarchical list form; recursion cycle tree structure data, a cycle leaf node id list and a layering list are adopted to find out all node ids on a path from a root node to a leaf node; compared with the method that all the node ids on the path from the root node to the leaf node are directly obtained according to the tree structure, the calculation amount is greatly reduced by obtaining after conversion.

Description

Method for searching tree structure data path node
Technical Field
The invention relates to the technical field of tree data searching, in particular to a method for searching tree structure data path nodes.
Background
When the user authority is stored, in order to convert the authority of the user into the authority tree, all node ids from a root node to each leaf node, namely, all node ids of an authority node path are stored in a database, but the structure of the authority tree acquired at the front end extends from the root node to each leaf node, if all node ids on a path from a certain leaf node to the root node need to be inquired, because the leaf nodes do not have father node information, the leaf nodes can only traverse from the root node to all the leaf nodes one by one until the appointed leaf nodes are found, the processing is very complex, and the user experience is influenced.
Disclosure of Invention
Compared with the method for directly acquiring all node ids on the path from the root node to the leaf node according to the tree structure, the method for searching the tree structure data path node has the advantages that the calculation amount is greatly reduced by acquiring all the node ids after conversion.
In order to achieve the purpose, the invention adopts the technical scheme that: a method for searching tree-structured data path nodes comprises the following steps:
step 1, after receiving a leaf node id list needing to be stored, acquiring tree structure data;
step 2, converting the tree structure data into hierarchical structure data in a hierarchical list form;
and 3, recursion and circulation of tree structure data, circulation of a leaf node id list and a layering list, and finding out all node ids on a path from a root node to a leaf node.
As a further improvement of the present invention, in step 1, the tree structure data includes: the first layer is a root node, no upper-level authority exists, the current authority id and the parent authority id are defined as-1, the data format of child node information is a list, if the current node is a leaf node, the child node information is null, and each piece of data of the child node information list also comprises the current authority id, the parent authority id and the child node information.
As a further improvement of the present invention, in step 2, each layer of the hierarchical structure data is composed of a plurality of Map objects, and each Map object only contains the authority id of the current layer and the corresponding parent-level authority id.
As a further improvement of the present invention, in step 3, the recursive loop tree structure data, the loop leaf node id list and the hierarchical list specifically include:
recursion for the first time, circularly taking out unique root node data which comprises authority id and parent authority id, and creating key value pair information as the first layer of the layering result by taking the root node id as key and-1 defined by the parent node as value as the current layer 1 and taking the layering result as null;
and performing secondary recursion, converting the previous root node of the incoming tree structure into child node information of the root node, wherein a plurality of incoming tree menus can be generated due to the fact that the incoming tree structure is not the root node information, circulating the incoming tree menus, establishing a Map object by taking id of the incoming tree menu as key and id of a parent node as value, and taking the Map object as a second layer of a layering result until leaf nodes are recorded.
As a further improvement of the present invention, in step 3, finding out all node ids on the path from the root node to the leaf node specifically includes:
after a layering result is obtained, a leaf node list transmitted by an outer layer cycle, the layering result obtained before an inner layer cycle is that leaf node ids are recorded firstly, a parent node id corresponding to the transmitted leaf node is found from the last layer, namely the leaf node layer cycle, then the parent node id is recorded, the last but one layer is recycled, the parent node id of the next previous layer is found and recorded according to the parent node id of the leaf node until the root node, and all nodes on each leaf node path transmitted from the root node are found by the cycle.
The invention has the beneficial effects that:
according to the invention, tree structure data is converted into a hierarchical structure according to a layer, a root node is placed in a first layer, a secondary node is placed in a second layer, a leaf node is placed in a last layer, a father node id is searched outwards from the last layer according to the leaf node id and recorded until the root node, and the path searching time from the leaf node to the root node is greatly reduced.
Drawings
FIG. 1 is a block flow diagram of an embodiment of the present invention.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
Example 1
As shown in fig. 1, a method for finding a node of a data path of a tree structure includes:
after receiving a leaf node list needing to be stored, acquiring authority tree data of a tree structure according to a general processing method, wherein the authority tree data comprises current authority id and parent id, the first layer is a root node, no superior authority exists, the authority tree data is-1, the data format of child node information is a list, if the current node is a leaf node, the child node information is null, and each piece of data of the child node information list also comprises the current authority id, the parent id and the child node information.
And then, converting the tree structure, wherein the converted data format is a multilayer list, each layer consists of a plurality of Map objects, and each Map only comprises the authority id of the current layer and the corresponding parent-level authority id.
Recursion circulation tree structure data, recursion for the first time, circularly taking out unique root node data including authority id and parent-level authority id, since it is currently level 1, and the layering result is empty, the root node id is taken as the key, using the parent node-1 as value, creating key value pair information as the first layer of the layering result, only one piece of data in the layering result records the root node and the corresponding parent node, then, a second recursion is carried out, the introduced tree structure at the moment is converted into child node information of the root node from the previous root node, and the specific processing method, since there may be more than one tree menu this time, since it is not the root node information, the menus are cycled through, and with the id of the menus as key and the id of the parent node as value, creating a Map object as a second layer of the layering result, and recursing until the leaf nodes are recorded.
After a layering result is obtained, a leaf node list transmitted by an outer layer loop, the layering result obtained before an inner layer loop is obtained, leaf node ids are recorded firstly, a parent node id corresponding to the transmitted leaf node is found out from the last layer, namely the leaf node layer loop, then the parent node id is recorded, the last but one layer is recycled, the parent node id of the next previous layer is found out according to the parent node id of the leaf node and is recorded until the root node, and all nodes starting from the root node and reaching the transmitted leaf node path are found out by the loop.
Example 2
And a certain project needs to be subjected to authority control, and an authority control framework is not used, so that the function of authority verification is determined to be completed by self. Since this embodiment only relates to the preservation of rights and not to the processing of rights, it is only relevant to the preservation of rights here. 2 related data tables for storing the authority are designed, one data table stores all data authorities and one data table stores the authority owned by a user, the data table storing all the data authorities has 2 key fields, authority id which is recorded in a form of a main key, parent authority id which stores the superior authority id of the current authority, and if the current authority is a root authority, the parent authority id is-1; the other table stores the user's rights and has 2 key fields, one being the user id and one being the rights id.
Firstly, reading data from a table of all data authorities, converting the data into data with a tree structure, caching the data, and reading the data with the tree structure formed by all authorities from the cache after receiving a leaf authority id list and a user id of a user, wherein the data is in the form of:
Figure BDA0003349073850000041
Figure BDA0003349073850000051
the root authority id is 1, 2 pieces of authority information are arranged below the root authority id, the id is 2 and 3 respectively, 3 pieces of authority are also arranged below the root authority id, and the id is 4;
then, starting to convert tree structure data into hierarchical structure data, and circulating the first layer, wherein the data is as follows:
Figure BDA0003349073850000052
temporarily ignoring child nodes, with id as key and parentId as value, creating data of a first level hierarchy, i.e. data of a second level hierarchy
Figure BDA0003349073850000061
Creating second-layer Map data, or taking id as key, id of parent node as value, and creating result as
Figure BDA0003349073850000062
Creating the third Map data as the result of
{"4":"3"}
The final tree-form is converted into a hierarchical structure as a result
[{"1":"-1"},{"2":"1","3":"1"},{"4":"3"}]
If the authority 4 needs to be added to the user with the user id of 100 at this time, the method for searching the authority from the root node to the user with the id of 4 is as follows:
and circulating from the last layer of the layering result forward, firstly recording 4 id, recording the data of the last layer as { "4": 3"}, finding out the id of a parent node as 3 according to the id as 4, recording 3, finding out the id of the parent node corresponding to 3 as 1 in the data of the previous layer as {"2": 1", "3": 1"}, recording 1, finding out the id of the parent node as-1 in the first layer, already reaching the root node, and not recording-1, thus finding out all nodes, 4, 3 and 1 on the path from the leaf node to the root node according to the leaf node.
The above-mentioned embodiments only express the specific embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention.

Claims (5)

1. A method for searching tree-structured data path nodes is characterized by comprising the following steps:
step 1, after receiving a leaf node id list needing to be stored, acquiring tree structure data;
step 2, converting the tree structure data into hierarchical structure data in a hierarchical list form;
and 3, recursion and circulation of tree structure data, circulation of a leaf node id list and a layering list, and finding out all node ids on a path from a root node to a leaf node.
2. The method of finding tree structured data path nodes according to claim 1, wherein in step 1, the tree structured data comprises: the first layer is a root node, no upper-level authority exists, the current authority id and the parent authority id are defined as-1, the data format of child node information is a list, if the current node is a leaf node, the child node information is null, and each piece of data of the child node information list also comprises the current authority id, the parent authority id and the child node information.
3. A method of finding tree structured data path nodes according to claim 2, characterized in that in step 2, each layer of said hierarchically structured data is composed of several Map objects, each Map object containing only the authority id of the current layer and the corresponding parent authority id.
4. The method for finding tree-structured data path nodes according to claim 3, wherein in step 3, the recursive loop of the tree-structured data, the list of loop leaf node ids and the hierarchical list specifically include:
recursion for the first time, circularly taking out unique root node data which comprises authority id and parent authority id, and creating key value pair information as the first layer of the layering result by taking the root node id as key and-1 defined by the parent node as value as the current layer 1 and taking the layering result as null;
and performing secondary recursion, converting the previous root node of the incoming tree structure into child node information of the root node, wherein a plurality of incoming tree menus can be generated due to the fact that the incoming tree structure is not the root node information, circulating the incoming tree menus, establishing a Map object by taking id of the incoming tree menu as key and id of a parent node as value, and taking the Map object as a second layer of a layering result until leaf nodes are recorded.
5. The method for searching nodes of tree-structured data paths according to claim 4, wherein in step 3, finding all node ids on the path from the root node to the leaf node specifically comprises:
after a layering result is obtained, a leaf node list transmitted by an outer layer cycle, the layering result obtained before an inner layer cycle is that leaf node ids are recorded firstly, a parent node id corresponding to the transmitted leaf node is found from the last layer, namely the leaf node layer cycle, then the parent node id is recorded, the last but one layer is recycled, the parent node id of the next previous layer is found and recorded according to the parent node id of the leaf node until the root node, and all nodes on each leaf node path transmitted from the root node are found by the cycle.
CN202111331767.9A 2021-11-11 2021-11-11 Method for searching tree structure data path node Pending CN114168591A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111331767.9A CN114168591A (en) 2021-11-11 2021-11-11 Method for searching tree structure data path node

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111331767.9A CN114168591A (en) 2021-11-11 2021-11-11 Method for searching tree structure data path node

Publications (1)

Publication Number Publication Date
CN114168591A true CN114168591A (en) 2022-03-11

Family

ID=80478823

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111331767.9A Pending CN114168591A (en) 2021-11-11 2021-11-11 Method for searching tree structure data path node

Country Status (1)

Country Link
CN (1) CN114168591A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114817316A (en) * 2022-07-04 2022-07-29 苏州万店掌网络科技有限公司 Method, device, equipment and storage medium for querying parent level
CN115291773A (en) * 2022-08-09 2022-11-04 北京商银微芯科技有限公司 Tree structure data display method and device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114817316A (en) * 2022-07-04 2022-07-29 苏州万店掌网络科技有限公司 Method, device, equipment and storage medium for querying parent level
CN115291773A (en) * 2022-08-09 2022-11-04 北京商银微芯科技有限公司 Tree structure data display method and device

Similar Documents

Publication Publication Date Title
US7263525B2 (en) Query processing method for searching XML data
US11030243B2 (en) Structure based storage, query, update and transfer of tree-based documents
CN114168591A (en) Method for searching tree structure data path node
CN103123650A (en) Extensible markup language (XML) data bank full-text indexing method based on integer mapping
CN110928939A (en) Method for converting Sql result set into Json data based on tree structure
CN115329504B (en) BOM construction method based on complex product structure
CN106484815B (en) A kind of automatic identification optimization method based on mass data class SQL retrieval scene
Mpinda et al. Evaluation of graph databases performance through indexing techniques
CN108763536A (en) Data bank access method and device
CN105138674B (en) A kind of data bank access method
CN111475511A (en) Data storage method, data access method, data storage device, data access device and data access equipment based on tree structure
CN109254962B (en) Index optimization method and device based on T-tree and storage medium
CN103294791A (en) Extensible markup language pattern matching method
CN106933844B (en) Construction method of reachability query index facing large-scale RDF data
CN105843809A (en) Data processing method and device
KR20130064160A (en) System of entity-relationship model reformulation of sparql query results on rdf data and the method
CN107291875B (en) Metadata organization management method and system based on metadata graph
CN113111413B (en) BIM (building information modeling) model attribute semi-structured light weight design method
JP5981382B2 (en) Partial tree merging device, partial tree merging method, and partial tree merging program
KR100948659B1 (en) Method for assigning numbers to nodes in dynamic eXtensible Markup Language
CN113190550B (en) Organization structure authority distribution method based on tree structure
KR20080008573A (en) Method for extracting association rule from xml data
CN113139389B (en) Graph model semantic query expansion method and device based on dynamic optimization
JP5374456B2 (en) Method of operating document search apparatus and computer program for causing computer to execute the same
JP2011170460A (en) Information accumulation retrieval method and information accumulation retrieval program

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