et-forest.h revision 169690
140123Sdes/* Et-forest data structure implementation. 266830Sobrien Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 366830Sobrien 466830SobrienThis program is free software; you can redistribute it and/or modify 566830Sobrienit under the terms of the GNU General Public License as published by 666830Sobrienthe Free Software Foundation; either version 2 of the License, or 766830Sobrien(at your option) any later version. 866830Sobrien 966830SobrienThis program is distributed in the hope that it will be useful, 1066830Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of 1166830SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1266830SobrienGNU General Public License for more details. 1366830Sobrien 1466830SobrienYou should have received a copy of the GNU General Public License 1566830Sobrienalong with this program; if not, write to the Free Software 1666830SobrienFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 1766830Sobrien 1866830Sobrien/* This package implements ET forest data structure. Each tree in 1966830Sobrien the structure maintains a tree structure and offers logarithmic time 2066830Sobrien for tree operations (insertion and removal of nodes and edges) and 2166830Sobrien poly-logarithmic time for nearest common ancestor. 2266830Sobrien 2366830Sobrien ET tree stores its structure as a sequence of symbols obtained 2466830Sobrien by dfs(root) 2566830Sobrien 2666830Sobrien dfs (node) 2783871Sobrien { 2850472Speter s = node; 2966830Sobrien for each child c of node do 3037Srgrimes s = concat (s, c, node); 3137Srgrimes return s; 3237Srgrimes } 3337Srgrimes 3437Srgrimes For example for tree 3537Srgrimes 3651231Ssheldonh 1 3751231Ssheldonh / | \ 3851231Ssheldonh 2 3 4 3951231Ssheldonh / | 408460Sjkh 4 5 4137Srgrimes 4237Srgrimes the sequence is 1 2 4 2 5 3 1 3 1 4 1. 4337Srgrimes 4437Srgrimes The sequence is stored in a slightly modified splay tree. 4551231Ssheldonh In order to support various types of node values, a hashtable 4637Srgrimes is used to convert node values to the internal representation. */ 4737Srgrimes 4837Srgrimes#ifndef _ET_TREE_H 4951231Ssheldonh#define _ET_TREE_H 5092441Scjc 5151231Ssheldonh#include <ansidecl.h> 5237Srgrimes#include <stddef.h> 53114492Sdougb 54114492Sdougb#ifdef __cplusplus 55114492Sdougbextern "C" { 56114492Sdougb#endif /* __cplusplus */ 57114492Sdougb 5898189Sgordon/* The node representing the node in an et tree. */ 59114492Sdougbstruct et_node 60114492Sdougb{ 61114492Sdougb void *data; /* The data represented by the node. */ 62114492Sdougb 63108200Sdillon int dfs_num_in, dfs_num_out; /* Number of the node in the dfs ordering. */ 64114492Sdougb 65114492Sdougb struct et_node *father; /* Father of the node. */ 6698189Sgordon struct et_node *son; /* The first of the sons of the node. */ 6798189Sgordon struct et_node *left; 68114492Sdougb struct et_node *right; /* The brothers of the node. */ 69114492Sdougb 7098189Sgordon struct et_occ *rightmost_occ; /* The rightmost occurrence. */ 71114492Sdougb struct et_occ *parent_occ; /* The occurrence of the parent node. */ 72114492Sdougb}; 7388531Ssheldonh 7451231Ssheldonhstruct et_node *et_new_tree (void *data); 7570109Sdougbvoid et_free_tree (struct et_node *); 7637Srgrimesvoid et_free_tree_force (struct et_node *); 7737Srgrimesvoid et_free_pools (void); 78void et_set_father (struct et_node *, struct et_node *); 79void et_split (struct et_node *); 80struct et_node *et_nca (struct et_node *, struct et_node *); 81bool et_below (struct et_node *, struct et_node *); 82 83#ifdef __cplusplus 84} 85#endif /* __cplusplus */ 86 87#endif /* _ET_TREE_H */ 88