# US 2019/0317963 A1 · Index for traversing hierarchical data

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2019/0317963 A1
- Document ID: US20190317963A1
- Status: Published application
- Kind: A1
- Application number: 16/246,171
- Filed: 2019-01-11
- Published: 2019-10-17
- Earliest claimed: 2018-04-11
- Assignees: Sap SE
- Applicants: Sap SE
- Inventors: Bastian Erler; Gerald Franz; Hannes Jakschitsch; Roland Sedler
- Web page: https://patentgrep.com/patent/US20190317963A1

## CPC

- G06F 16/9027: {Trees}
- G06F 16/902: {using more than one table in sequence, i.e. systems with three or more layers}
- G06F 16/9024: {Graphs; Linked lists (G06F16/9027 takes precedence)}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method for traversing hierarchical data is provided. The method may include generating, based on a source table stored in a database, an index for traversing a graph corresponding to the source table. The source table may identify a parent node for each node in the graph. The generating of the index may include iterating over the source table to generate an inner node map. The inner node map may include at least one mapping identifying one or more children nodes descending from an inner node in the graph. The graph may be traversed based at least on the index. The index may enable the graph to be traversed depth first starting from a root node of the graph and continuing to a first child node descending from the root node of the graph. Related systems and articles of manufacture, including computer program products, are also provided.

## Claims

### Claim 1

A system, comprising:
at least one data processor; and
at least one memory storing instructions which, when executed by the at least one data processor, result in operations comprising:
generating, based at least on a source table stored in a database, an index for traversing a graph corresponding to the source table, the source table identifying a parent node for each node in the graph, the generating of the index including iterating over at least a portion of the source table to generate an inner node map, and the inner node map including at least one mapping identifying one or more children nodes descending from an inner node in the graph; and
traversing, based at least on the index, the graph, the index enabling the graph to be traversed depth first starting from a root node of the graph and continuing to a first child node descending from the root node of the graph.

### Claim 2 (depends on 1)

The system of claim 1, wherein the inner node map is generated by at least:
adding, to the inner node map, the at least one mapping in response to determining that the inner node occupies a first row in the source table, the at least one mapping associating the inner node with the first row in the source table, the first row being occupied by the inner node and a first child node of the inner node; and
updating at least one mapping in response to determining that the inner node occupies a second row in the source table, the at least one mapping being updated to associate the inner node with the second row in the source table, the second row being occupied by the inner node and a next child node of the inner node.

### Claim 3 (depends on 2)

The system of claim 2, wherein the generating of the index further includes iterating over at least the portion of the source table to generate a next sibling vector, wherein the next sibling vector indicates a next sibling node for at least one node in the graph, and wherein the next sibling node for the at least one node comprises a sibling node occupying a higher row in the source table than the at least one node.

### Claim 4 (depends on 3)

The system of claim 3, further comprising:
in response to the updating of the at least one mapping, updating the next sibling vector to at least identify the next child node of the inner node as being a next sibling node for a child node of the inner node that is last encountered during the iteration over at least the portion of the source table.

### Claim 5 (depends on 1)

The system of claim 1, wherein the generating of the index further includes iterating over at least the portion of the source table to generate a root node list, wherein a node is added to the root node list based at least on the node not being associated with a parent node in the source table, and wherein the root node list enables an identification of the root node from which to start traversing the graph.

### Claim 6 (depends on 1)

The system of claim 1, further comprising:
assigning, to the inner node, a unique node identifier.

### Claim 7 (depends on 6)

The system of claim 6, wherein the generating of the index further includes generating a node identifier vector, and wherein the node identifier vector is updated to include the unique node identifier assigned to the inner node.

### Claim 8 (depends on 7)

The system of claim 7, wherein the node identifier vector further includes a default node identifier associated with a leaf node in the graph, wherein the leaf node comprises a node without any outgoing edges, and wherein the unique node identifier and/or the default node identifier enable a differentiation between the inner node of the graph and the leaf node of the graph.

### Claim 9 (depends on 1)

The system of claim 1, wherein the traversing of the graph comprises:
popping, onto a stack, the root node followed by the first child node of the root node;
setting a first flag associated with the root node, the first flag being set to indicate the root node as having being traversed along a current path through the graph, the current path starting and terminating at the root node;
setting a second flag associated with the first child node, the second flag being set based at least on the first child node being an inner node and not a leaf node, and the second flag being set to indicate the first child node as having being traversed along the current path;
determining, based at least on a third flag associated with a second child node descending from the first child node, whether the first child node and the second child node form a cycle; and
in response to determining that the first child node and the second child node form the cycle, breaking the cycle by at least avoiding traversing through the second child node.

### Claim 10 (depends on 9)

The system of claim 9, wherein the second child node is avoided by at least popping, onto the stack, a next sibling node of the first child node instead of the second child node.

### Claim 11 (depends on 9)

The system of claim 9, further comprising:
determining, based at least on the index, the root node, the first child node, the second child node, and/or the next sibling node.

### Claim 12 (depends on 9)

The system of claim 9, further comprising:
resetting the first flag, the second flag, and/or the third flag in response to the root node being an only node remaining in the stack.

### Claim 13 (depends on 9)

The system of claim 9, wherein the first flag, the second flag, and/or the third flag are stored as part of the at least one mapping included in the inner node map.

### Claim 14 (depends on 1)

The system of claim 1, wherein the graph includes a plurality of nodes, wherein the graph further includes one or more edges interconnecting the plurality of nodes, and wherein a directionality of each of the one or more edges indicates one or more parent-child relationships amongst the plurality of nodes.

### Claim 15 (depends on 1)

The system of claim 1, wherein the source table includes a first column storing one or more identifiers of parent nodes in the graph, and wherein the source table further includes a second column storing one or more identifiers of the corresponding children nodes.

### Claim 16

A computer-implemented method, comprising:
generating, based at least on a source table stored in a database, an index for traversing a graph corresponding to the source table, the source table identifying a parent node for each node in the graph, the generating of the index including iterating over at least a portion of the source table to generate an inner node map, and the inner node map including at least one mapping identifying one or more children nodes descending from an inner node in the graph; and
traversing, based at least on the index, the graph, the index enabling the graph to be traversed depth first starting from a root node of the graph and continuing to a first child node descending from the root node of the graph.

### Claim 17 (depends on 16)

The method of claim 16, wherein the inner node map is generated by at least:
adding, to the inner node map, the at least one mapping in response to determining that the inner node occupies a first row in the source table, the at least one mapping associating the inner node with the first row in the source table, the first row being occupied by the inner node and a first child node of the inner node; and
updating at least one mapping in response to determining that the inner node occupies a second row in the source table, the at least one mapping being updated to associate the inner node with the second row in the source table, the second row being occupied by the inner node and a next child node of the inner node.

### Claim 18 (depends on 17)

The method of claim 17, wherein the generating of the index further includes iterating over at least the portion of the source table to generate a next sibling vector, wherein the next sibling vector indicates a next sibling node for at least one node in the graph, wherein the next sibling node for the at least one node comprises a sibling node occupying a higher row in the source table than the at least one node, and wherein the next sibling node vector is updated, in response to the updating of the at least one mapping, to at least identify the next child node of the inner node as being a next sibling node for the first child node of the inner node.

### Claim 19 (depends on 16)

The method of claim 16, wherein the generating of the index further includes iterating over at least the portion of the source table to generate a root node list, wherein a node is added to the root node list based at least on the node not being associated with a parent node in the source table, and wherein the root node list enables an identification of the root node from which to start traversing the graph.

### Claim 20

A non-transitory computer readable medium storing instructions, which when executed by at least one data processor, result in operations comprising:
generating, based at least on a source table stored in a database, an index for traversing a graph corresponding to the source table, the source table identifying a parent node for each node in the graph, the generating of the index including iterating over at least a portion of the source table to generate an inner node map, and the inner node map including at least one mapping identifying one or more children nodes descending from an inner node in the graph; and
traversing, based at least on the index, the graph, the index enabling the graph to be traversed depth first starting from a root node of the graph and continuing to a first child node descending from the root node of the graph.
