1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * STRUCTURE SHARING * */
/* * * */
/* * $Module: SHARING * */
/* * * */
/* * Copyright (C) 1996, 1997, 1998, 2000, 2001 * */
/* * MPI fuer Informatik * */
/* * * */
/* * This program is free software; you can redistribute * */
/* * it and/or modify it under the terms of the FreeBSD * */
/* * Licence. * */
/* * * */
/* * This program is distributed in the hope that it will * */
/* * be useful, but WITHOUT ANY WARRANTY; without even * */
/* * the implied warranty of MERCHANTABILITY or FITNESS * */
/* * FOR A PARTICULAR PURPOSE. See the LICENCE file * */
/* * for more details. * */
/* * * */
/* * * */
/* $Revision: 1.2 $ * */
/* $State: Exp $ * */
/* $Date: 2010-02-22 14:09:59 $ * */
/* $Author: weidenb $ * */
/* * * */
/* * Contact: * */
/* * Christoph Weidenbach * */
/* * MPI fuer Informatik * */
/* * Stuhlsatzenhausweg 85 * */
/* * 66123 Saarbruecken * */
/* * Email: spass@mpi-inf.mpg.de * */
/* * Germany * */
/* * * */
/* ********************************************************** */
/**************************************************************/
/* $RCSfile: sharing.h,v $ */
#ifndef _SHARING_
#define _SHARING_
/**************************************************************/
/* Includes */
/**************************************************************/
#include "term.h"
#include "st.h"
/**************************************************************/
/* Data Structures and Constants */
/**************************************************************/
/* Symbol Tables; constants are just positive */
/* integers and variables negative integers. */
/* For constants and vars is a special symbol */
/* table available, containing the sharing */
/* info, i.e. a POINTER to the term structure, if */
/* the symbol is already inserted in the sharing */
/* structure, a NULL Pointer else. */
typedef TERM VARTABLE[symbol__MAXVARIABLES];
typedef TERM CONSTTABLE[symbol__MAXSIGNATURE];
typedef struct {
st_INDEX index;
VARTABLE vartable;
CONSTTABLE consttable;
NAT stampId;
} SHARED_INDEX_NODE, *SHARED_INDEX;
/**************************************************************/
/* Inline Functions */
/**************************************************************/
static __inline__ st_INDEX sharing_Index(SHARED_INDEX ShIndex)
{
return ShIndex->index;
}
static __inline__ void sharing_SetIndex(SHARED_INDEX ShIndex, st_INDEX ST)
{
ShIndex->index = ST;
}
static __inline__ const TERM* sharing_Vartable(SHARED_INDEX ShIndex)
{
return ShIndex->vartable;
}
static __inline__ const TERM* sharing_Consttable(SHARED_INDEX ShIndex)
{
return ShIndex->consttable;
}
static __inline__ NAT sharing_StampID(SHARED_INDEX ShIndex)
{
return ShIndex->stampId;
}
static __inline__ void sharing_SetStampID(SHARED_INDEX ShIndex, NAT Stamp)
{
ShIndex->stampId = Stamp;
}
static __inline__ TERM sharing_VartableEntry(SHARED_INDEX ShIndex, NAT Index)
{
return ShIndex->vartable[Index];
}
static __inline__ void sharing_SetVartableEntry(SHARED_INDEX ShIndex,
NAT Index, TERM Term)
{
ShIndex->vartable[Index] = Term;
}
static __inline__ TERM sharing_ConsttableEntry(SHARED_INDEX ShIndex,
NAT Index)
{
return ShIndex->consttable[Index];
}
static __inline__ void sharing_SetConsttableEntry(SHARED_INDEX ShIndex,
NAT Index, TERM Term)
{
ShIndex->consttable[Index] = Term;
}
static __inline__ TERM sharing_GetVarFromSymbol(SYMBOL S, SHARED_INDEX ShIndex)
{
return sharing_VartableEntry(ShIndex, symbol_VarIndex(S));
}
static __inline__ int sharing_VariableIndex(TERM Term)
{
return symbol_VarIndex(term_TopSymbol(Term));
}
static __inline__ int sharing_ConstantIndex(TERM Term)
{
return symbol_Index(term_TopSymbol(Term));
}
static __inline__ BOOL sharing_IsSharedVar(TERM T, SHARED_INDEX ShIndex)
/* RETURNS: True if there's already an entry for the variable T */
/* in the Vartable of the shared index ShIndex. */
{
return sharing_VartableEntry(ShIndex, sharing_VariableIndex(T)) != NULL;
}
static __inline__ BOOL sharing_IsSharedConst(TERM T, SHARED_INDEX ShIndex)
/* True if there's already an entry for the constant T */
/* in the Consttable of the shared index ShIndex. */
{
return sharing_ConsttableEntry(ShIndex, sharing_ConstantIndex(T)) != NULL;
}
static __inline__ BOOL sharing_IsNotReallyShared(TERM Term)
/* Der einzige Superterm ist der in dem ich loesche */
{
return list_Length(term_SupertermList(Term)) <= 1;
}
static __inline__ void sharing_RememberSharedTermCopy(TERM Term, TERM Copy)
/* The unshared term Term has now a link to its shared copy */
{
term_RplacSuperterm(Term, Copy);
}
static __inline__ TERM sharing_SharedTermCopy(TERM Term)
/* Return the shared copy of the unshared term Term */
{
return term_Superterm(Term);
}
/**************************************************************/
/* Functions for Creation and Deletion of a SHARED_INDEX */
/**************************************************************/
SHARED_INDEX sharing_IndexCreate(void);
void sharing_IndexDelete(SHARED_INDEX);
/**************************************************************/
/* Functions on term insertion and deletion. */
/**************************************************************/
TERM sharing_Insert(POINTER, TERM, SHARED_INDEX);
void sharing_Delete(POINTER, TERM, SHARED_INDEX);
void sharing_PushOnStack(TERM);
void sharing_PushReverseOnStack(TERM);
void sharing_PushOnStackNoStamps(TERM);
void sharing_PushListOnStack(LIST);
void sharing_PushListReverseOnStack(LIST);
void sharing_PushListReverseOnStackExcept(LIST, LIST);
void sharing_PushListOnStackNoStamps(LIST);
/**************************************************************/
/* Functions to access unshared data by the shared terms. */
/**************************************************************/
LIST sharing_GetDataList(TERM, SHARED_INDEX);
void sharing_StartDataIterator(TERM, SHARED_INDEX);
POINTER sharing_GetNextData(void);
void sharing_StopDataIterator(void);
LIST sharing_NAtomDataList(TERM);
LIST sharing_GetAllSuperTerms(SHARED_INDEX);
void sharing_ResetAllTermStamps(SHARED_INDEX);
NAT sharing_GetNumberOfOccurances(TERM);
NAT sharing_GetNumberOfInstances(TERM, SHARED_INDEX);
/**************************************************************/
/* Output functions */
/**************************************************************/
void sharing_PrintVartable(SHARED_INDEX);
void sharing_PrintConsttable(SHARED_INDEX);
void sharing_PrintSharing(SHARED_INDEX);
/**************************************************************/
/* Debugging Functions */
/**************************************************************/
void sharing_PrintStack(void);
void sharing_PrintSharingConstterms1(SHARED_INDEX);
void sharing_PrintSharingVarterms1(SHARED_INDEX);
void sharing_PrintSameLevelTerms(TERM);
#endif
|