#ifndef _INSTSET_
#define _INSTSET_ 
#include "clause.h"
#include "distrn.h"
#include "inst.h"
#include "order.h"
#include "sharing.h"
#include "folsubst.h"
#include "trail.h"
typedef struct INSTSET_FILTER_HELP {
  ARRAY origins;
  BOOL deleteInstances;
} * INSTSET_FILTER;
typedef struct INSTSET_HELP {
  OHASH insts;
  DISTRN positive;
  DISTRN negative;
  ARRAY originClauses;
  ARRAY substmaps;
  INSTSET_FILTER filter;
  unsigned instances;
} * INSTSET;
INSTSET instset_Create(MEMORY, ARRAY, TERMSTATE, TRAIL, ARRAY *);
void instset_Delete(MEMORY, INSTSET, SYMBSTATE);
OHASH instset_GetInsts(INSTSET);
void instset_SetInsts(INSTSET, OHASH);
DISTRN instset_GetPositiveDistr(INSTSET);
DISTRN instset_GetNegativeDistr(INSTSET);
ARRAY instset_GetOriginClauses(INSTSET);
void instset_SetOriginClauses(INSTSET, ARRAY);
ARRAY instset_GetSubstmaps(INSTSET);
void instset_SetSubstmaps(INSTSET, ARRAY);
INSTSET_FILTER instset_GetFilter(INSTSET);
void instset_SetFilter(INSTSET, INSTSET_FILTER);
unsigned instset_GetInstances(INSTSET);
void instset_SetInstances(INSTSET, unsigned);
void instset_IncrementInstances(INSTSET);
void instset_DecrementInstances(INSTSET);
INSTSET_FILTER instset_FilterCreate(MEMORY, ARRAY, BOOL);
void instset_FilterDelete(MEMORY, INSTSET_FILTER);
ARRAY instset_GetFilterOrigins(INSTSET_FILTER);
void instset_SetFilterOrigins(INSTSET_FILTER, ARRAY);
BOOL instset_GetFilterDeleteInstances(INSTSET_FILTER);
void instset_SetFilterDeleteInstances(INSTSET_FILTER, BOOL);
INST instset_NewOriginClause(MEMORY, INSTSET, CLAUSE, TERMSTATE, TRAIL, unsigned);
BOOL instset_IsInClauseSubst(INSTSET, CLAUSE, SUBST);
BOOL instset_IsInInst(INSTSET, INST);
void instset_AddNewInstance(MEMORY, INSTSET, INST, TERMSTATE);
BOOL instset_IfNotInAddInstance(MEMORY, SHARER, TERMSTATE, INSTSET, INST, unsigned, TRAIL, unsigned);
INST instset_IfNotInAddNewInstanceFromSubst(MEMORY, SHARER, TERMSTATE, INSTSET, INST, SUBST, unsigned, TRAIL);
INST instset_IfNotInAddNewInstanceFromContext(MEMORY, SHARER, TERMSTATE, INSTSET, INST, SUBSTSTATE, unsigned, TRAIL, BOOL, unsigned);
void instset_AddWatchedToIndex(MEMORY, INSTSET, INST, TERMSTATE, BOOL);
void instset_RemoveWatchedFromIndex(INSTSET, INST, TERMSTATE, unsigned, BOOL);
ARRAY instset_SearchNewlyFalseWatched(MEMORY, INSTSET, TERMSTATE, TERM, BOOL, ARRAY *, unsigned);
BOOL instset_TryUpdateWatched(MEMORY, INSTSET, TERMSTATE, INST, BOOL, TRAIL);
BOOL instset_TryUpdateWatchedPos(MEMORY, INSTSET, TERMSTATE, INST, BOOL, TRAIL, unsigned);
void instset_RestartAndForget(MEMORY, SYMBSTATE, INSTSET, ARRAY, BOOL);
ARRAY instset_GetAllInstances(MEMORY, INSTSET, ARRAY *);
void instset_DeleteInst(MEMORY, TERMSTATE, INSTSET, INST, BOOL);
void instset_DeleteClause(MEMORY, TERMSTATE, INSTSET, CLAUSE);
void instset_DeleteMarkedInstances(MEMORY, TERMSTATE, INSTSET);
void instset_RefreshInstances(MEMORY, TERMSTATE, INSTSET);
unsigned instset_ComputeNumberOfDuplicates(TERMSTATE, INSTSET);
void instset_Print(TERMSTATE, INSTSET);
void instset_PrintClause(TERMSTATE, INSTSET, CLAUSE);
uint32_t instset_ClauseHash(const OHASH_KEY_TYPE);
BOOL instset_ClauseEqual(const OHASH_KEY_TYPE, const OHASH_KEY_TYPE);
uint32_t instset_SubstHash(const OHASH_KEY_TYPE);
BOOL instset_SubstEqual(const OHASH_KEY_TYPE, const OHASH_KEY_TYPE);
void instset_HashDeleteInst(MEMORY, OHASH_DATA_TYPE);
BOOL instset_HashFilterEmptyTrail(intptr_t, OHASH_KEY_TYPE, OHASH_DATA_TYPE);
BOOL instset_DistrFilterEmptyTrailAndForget(intptr_t, intptr_t);
void instset_CheckOriginForCorrectWatched(MEMORY, INSTSET, TERMSTATE, CLAUSE, TRAIL, BOOL);
void instset_CheckAllInstancesForWatched(MEMORY, INSTSET, TERMSTATE, TRAIL, BOOL);
BOOL instset_CheckIfOriginNotMember(INSTSET, CLAUSE);
void instset_CheckIfInstancesAreGeneratedForClauseInternal(MEMORY, INSTSET, TERMSTATE, SUBSTSTATE, FOLSTATE, KBOSTATE, SHARER, CLAUSE, TRAIL,
                                                           TERM, ARRAY *, ARRAY *, ARRAY *, ARRAY *, ARRAY *, ARRAY *);
void instset_CheckIfInstancesAreGeneratedForClause(MEMORY, INSTSET, TERMSTATE, SUBSTSTATE, FOLSTATE, KBOSTATE, SHARER, CLAUSE, TRAIL, TERM);
void instset_CheckIfInstancesAreGenerated(MEMORY, INSTSET, TERMSTATE, SUBSTSTATE, FOLSTATE, KBOSTATE, SHARER, TRAIL, TERM);
void instset_Test(MEMORY, ARRAY, SHARER, TERMSTATE, SUBSTSTATE, SYMBSTATE, FOLSTATE, SYMBOL);
#endif
