xref: /dflybsd-src/contrib/gcc-4.7/gcc/et-forest.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Et-forest data structure implementation.
2*e4b17023SJohn Marino    Copyright (C) 2002, 2003, 2004, 2005, 2007, 2010
3*e4b17023SJohn Marino    Free Software Foundation, Inc.
4*e4b17023SJohn Marino 
5*e4b17023SJohn Marino    This program is free software; you can redistribute it and/or modify
6*e4b17023SJohn Marino    it under the terms of the GNU General Public License as published by
7*e4b17023SJohn Marino    the Free Software Foundation; either version 3 of the License, or
8*e4b17023SJohn Marino    (at your option) any later version.
9*e4b17023SJohn Marino 
10*e4b17023SJohn Marino    This program is distributed in the hope that it will be useful,
11*e4b17023SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*e4b17023SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*e4b17023SJohn Marino    GNU General Public License for more details.
14*e4b17023SJohn Marino 
15*e4b17023SJohn Marino    You should have received a copy of the GNU General Public License
16*e4b17023SJohn Marino    along with this program; see the file COPYING3.  If not see
17*e4b17023SJohn Marino    <http://www.gnu.org/licenses/>.  */
18*e4b17023SJohn Marino 
19*e4b17023SJohn Marino /* This package implements ET forest data structure. Each tree in
20*e4b17023SJohn Marino    the structure maintains a tree structure and offers logarithmic time
21*e4b17023SJohn Marino    for tree operations (insertion and removal of nodes and edges) and
22*e4b17023SJohn Marino    poly-logarithmic time for nearest common ancestor.
23*e4b17023SJohn Marino 
24*e4b17023SJohn Marino    ET tree stores its structure as a sequence of symbols obtained
25*e4b17023SJohn Marino    by dfs(root)
26*e4b17023SJohn Marino 
27*e4b17023SJohn Marino    dfs (node)
28*e4b17023SJohn Marino    {
29*e4b17023SJohn Marino      s = node;
30*e4b17023SJohn Marino      for each child c of node do
31*e4b17023SJohn Marino        s = concat (s, c, node);
32*e4b17023SJohn Marino      return s;
33*e4b17023SJohn Marino    }
34*e4b17023SJohn Marino 
35*e4b17023SJohn Marino    For example for tree
36*e4b17023SJohn Marino 
37*e4b17023SJohn Marino             1
38*e4b17023SJohn Marino           / | \
39*e4b17023SJohn Marino          2  3  4
40*e4b17023SJohn Marino        / |
41*e4b17023SJohn Marino       4  5
42*e4b17023SJohn Marino 
43*e4b17023SJohn Marino    the sequence is 1 2 4 2 5 3 1 3 1 4 1.
44*e4b17023SJohn Marino 
45*e4b17023SJohn Marino    The sequence is stored in a slightly modified splay tree.
46*e4b17023SJohn Marino    In order to support various types of node values, a hashtable
47*e4b17023SJohn Marino    is used to convert node values to the internal representation.  */
48*e4b17023SJohn Marino 
49*e4b17023SJohn Marino #ifndef _ET_TREE_H
50*e4b17023SJohn Marino #define _ET_TREE_H
51*e4b17023SJohn Marino 
52*e4b17023SJohn Marino #ifdef __cplusplus
53*e4b17023SJohn Marino extern "C" {
54*e4b17023SJohn Marino #endif /* __cplusplus */
55*e4b17023SJohn Marino 
56*e4b17023SJohn Marino /* The node representing the node in an et tree.  */
57*e4b17023SJohn Marino struct et_node
58*e4b17023SJohn Marino {
59*e4b17023SJohn Marino   void *data;			/* The data represented by the node.  */
60*e4b17023SJohn Marino 
61*e4b17023SJohn Marino   int dfs_num_in, dfs_num_out;	/* Number of the node in the dfs ordering.  */
62*e4b17023SJohn Marino 
63*e4b17023SJohn Marino   struct et_node *father;	/* Father of the node.  */
64*e4b17023SJohn Marino   struct et_node *son;		/* The first of the sons of the node.  */
65*e4b17023SJohn Marino   struct et_node *left;
66*e4b17023SJohn Marino   struct et_node *right;	/* The brothers of the node.  */
67*e4b17023SJohn Marino 
68*e4b17023SJohn Marino   struct et_occ *rightmost_occ;	/* The rightmost occurrence.  */
69*e4b17023SJohn Marino   struct et_occ *parent_occ;	/* The occurrence of the parent node.  */
70*e4b17023SJohn Marino };
71*e4b17023SJohn Marino 
72*e4b17023SJohn Marino struct et_node *et_new_tree (void *data);
73*e4b17023SJohn Marino void et_free_tree (struct et_node *);
74*e4b17023SJohn Marino void et_free_tree_force (struct et_node *);
75*e4b17023SJohn Marino void et_free_pools (void);
76*e4b17023SJohn Marino void et_set_father (struct et_node *, struct et_node *);
77*e4b17023SJohn Marino void et_split (struct et_node *);
78*e4b17023SJohn Marino struct et_node *et_nca (struct et_node *, struct et_node *);
79*e4b17023SJohn Marino bool et_below (struct et_node *, struct et_node *);
80*e4b17023SJohn Marino struct et_node *et_root (struct et_node *);
81*e4b17023SJohn Marino 
82*e4b17023SJohn Marino #ifdef __cplusplus
83*e4b17023SJohn Marino }
84*e4b17023SJohn Marino #endif /* __cplusplus */
85*e4b17023SJohn Marino 
86*e4b17023SJohn Marino #endif /* _ET_TREE_H */
87