00001 /* 00002 * libfid - Full-text Index Data structure library 00003 * Copyright (C) 2006, 2007 Robert Homann 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 * MA 02110-1301 USA 00019 */ 00020 00021 #ifndef SKIPTREE_H 00022 #define SKIPTREE_H 00023 /*!\addtogroup suffixarrays */ 00024 /*@{*/ 00025 /*! 00026 * \brief The inner skip chain loop. 00027 * 00028 * If the last character read from the start suffix was a special character 00029 * and depth is 0, then use SKIPTREE_DEPTH0_LOOP() instead to prevent 00030 * reading invalid memory. 00031 */ 00032 #define fid_SKIPTREE_LOOP(ESA,SKPTAB,NEXT,LCP,DEPTH,MAX,REL)\ 00033 while((NEXT) < (MAX) && (LCP) REL (DEPTH))\ 00034 {\ 00035 NEXT=(SKPTAB)[NEXT]+1;\ 00036 fid_LCP(LCP,ESA,NEXT);\ 00037 } 00038 00039 /*! 00040 * \brief The inner skip chain loop for special character at depth 0. 00041 */ 00042 #define fid_SKIPTREE_DEPTH0_LOOP(ESA,SKPTAB,NEXT,LCP,MAX)\ 00043 while((NEXT) < (MAX))\ 00044 {\ 00045 NEXT=(SKPTAB)[NEXT]+1;\ 00046 if((NEXT) < (MAX))\ 00047 {\ 00048 fid_LCP(LCP,ESA,NEXT);\ 00049 }\ 00050 } 00051 00052 /*! 00053 * \brief Skip tree if the last character read from the start suffix was a common character. 00054 */ 00055 #define fid_SKIPTREE_COMMON(ESA,SKPTAB,NEXT,START,LCP,DEPTH,MAX)\ 00056 if((START) < (MAX))\ 00057 {\ 00058 (NEXT)=(START)+1;\ 00059 fid_LCP(LCP,ESA,NEXT);\ 00060 fid_SKIPTREE_LOOP(ESA,SKPTAB,NEXT,LCP,DEPTH,MAX,>);\ 00061 }\ 00062 else\ 00063 {\ 00064 NEXT=(MAX);\ 00065 fid_LCP(LCP,ESA,NEXT);\ 00066 } 00067 00068 /*! 00069 * \brief Skip tree if the last character read from the start suffix was a special character. 00070 */ 00071 #define fid_SKIPTREE_SPECIAL(ESA,SKPTAB,NEXT,START,LCP,DEPTH,MAX)\ 00072 if((START) < (MAX))\ 00073 {\ 00074 (NEXT)=(START)+1;\ 00075 fid_LCP(LCP,ESA,NEXT);\ 00076 if((DEPTH) > 0)\ 00077 {\ 00078 fid_SKIPTREE_LOOP(ESA,SKPTAB,NEXT,LCP,DEPTH,MAX,>=);\ 00079 }\ 00080 else\ 00081 {\ 00082 fid_SKIPTREE_DEPTH0_LOOP(ESA,SKPTAB,NEXT,LCP,MAX);\ 00083 }\ 00084 }\ 00085 else\ 00086 {\ 00087 NEXT=(MAX);\ 00088 fid_LCP(LCP,ESA,NEXT);\ 00089 } 00090 00091 /*! 00092 * \brief Skip a subtree of a virtual suffix tree via skip table. 00093 * 00094 * The macro will always update \p NEXT and \p LCP, the other arguments are 00095 * used read-only. 00096 * 00097 * \param ESA Pointer to an enhanced suffix array. 00098 * \param SKPTAB Pointer to the skip table (part of \p ESA). This can be 00099 * given separately because you may want to have a pointer around that is 00100 * directly pointing to the skip table instead of referencing it through 00101 * the fid_Suffixarray structure each time. 00102 * \param NEXT An fid_Uint that stores the next index in the suffix table, 00103 * that is the first suffix that does not belong to the skipped subtree. 00104 * \param START The current index into the suffix table, that is the index 00105 * of the suffix whose subtree should be skipped. 00106 * \param LCP An fid_Uint that stores the current index in the LCP table. 00107 * \param DEPTH The current depth in the suffix tree. 00108 * \param MAX The length of the sequence underlaying the suffix array. 00109 * The length could also be read directly from a fid_Suffixarray structure, 00110 * but this may take too much time, so it should have been stored in a 00111 * separate fid_Uint by the caller. 00112 * \param COMMON Boolean indicating if the last character of the start 00113 * suffix is a special (0) or a common (not 0) one as determined by the 00114 * fid_REGULARSYMBOL() and fid_SPECIALSYMBOL() macros. 00115 * 00116 */ 00117 #define fid_SKIPTREE(ESA,SKPTAB,NEXT,START,LCP,DEPTH,MAX,COMMON)\ 00118 if((START) < (MAX))\ 00119 {\ 00120 (NEXT)=(START)+1;\ 00121 fid_LCP(LCP,ESA,NEXT);\ 00122 if(COMMON)\ 00123 {\ 00124 fid_SKIPTREE_LOOP(ESA,SKPTAB,NEXT,LCP,DEPTH,MAX,>);\ 00125 }\ 00126 else if((DEPTH) > 0)\ 00127 {\ 00128 fid_SKIPTREE_LOOP(ESA,SKPTAB,NEXT,LCP,DEPTH,MAX,>=);\ 00129 }\ 00130 else\ 00131 {\ 00132 fid_SKIPTREE_DEPTH0_LOOP(ESA,SKPTAB,NEXT,LCP,MAX);\ 00133 }\ 00134 }\ 00135 else\ 00136 {\ 00137 NEXT=(MAX);\ 00138 fid_LCP(LCP,ESA,NEXT);\ 00139 } 00140 /*@}*/ 00141 00142 #endif /* !SKIPTREE_H */