/*
 *   Copyright (C) 1988-2006 Lucent Technologies Inc. and others.
 *   All Rights Reserved.
 */

/* inverted index definitions */

/**********************************************************************
 * postings temporary file long number coding into characters
 *
 * Note: with BASE=95 and PRECISION=5, the cscope.out file is limited
 * to about 7.7 gigabytes. For a BASE=223 and PRECISION=4 the database
 * is limited to only 2.4 gigabytes. Someday, we may have to boost the
 * PRECISION up but since the largest (as of this writing) databases
 * are still less than 200 megabytes, this shouldn't be for a while...
 *
 * Look in crossref.c, putposting(), for more details on how this
 * stuff is used.
 **********************************************************************/
#if u3b || u3b2 || u3b5 || u3b15 || uts
#define	BASE		223	/* 255 - ' ' */
#define	PRECISION	4	/* maximum digits after converting a long */
#else	/* assume sign-extension of a char when converted to an int */
#define	BASE		95	/* 127 - ' ' */
#define	PRECISION	5	/* maximum digits after converting a long */
#endif

/* inverted index access parameters */
#define INVAVAIL	0
#define INVBUSY		1
#define INVALONE	2

/* boolean set operations */
#define	OR		3
#define	AND		4
#define	NOT		5
#define	REVERSENOT	6

/* note that the entire first block is for parameters */
typedef	struct	{
	long	version;	/* inverted index format version */
	long	filestat;	/* file status word  */
	long	sizeblk;	/* size of logical block in bytes */
	long	startbyte;	/* first byte of superfinger */
	long	supsize;	/* size of superfinger in bytes */
	long	cntlsize;	/* size of max cntl space (should be a multiple of BUFSIZ) */
	long	share;		/* flag whether to use shared memory */
} PARAM;

typedef	struct {
	FILE	*invfile;	/* the inverted file ptr */
	FILE	*postfile;	/* posting file ptr */
	PARAM	param;		/* control parameters for the file */
	char	*iindex;	/* ptr to space for superindex */
	char	*logblk;	/* ptr to space for a logical block */
	long	numblk;		/* number of block presently at *logblk */
	long	keypnt;		/* number item in present block found */
} INVCONTROL;

typedef	struct	{
	short	offset;		/* offset in this logical block */
	unsigned char size;	/* size of term */
	unsigned char space;	/* number of longs of growth space */
	long	post;		/* number of postings for this entry */
} ENTRY;

typedef	struct {
	long	lineoffset;	/* source line database offset */
	long	fcnoffset;	/* function name database offset */
#if defined(__BORLANDC__) || defined(FOR_WIN32)
	long	fileindex;	/* source file name index */
	long	type;	/* reference type (mark character) */
#else
	long	fileindex : 24;	/* source file name index */
	long	type : 8;	/* reference type (mark character) */
#endif
} POSTING;

extern	long	*srcoffset;	/* source file name database offsets */
extern	int	nsrcoffset;	/* number of file name database offsets */

#if defined( __STDC__ ) || defined( __BORLANDC__ )
void	boolclear(void);
POSTING	*boolfile(INVCONTROL *invcntl, long *num, int bool);
void	invclose(INVCONTROL *invcntl);
long	invfind(INVCONTROL *invcntl, char *searchterm);
int	invforward(INVCONTROL *invcntl);
int	invopen(INVCONTROL *invcntl, char *invname, char *invpost, int stat);
int	invterm(INVCONTROL *invcntl, char *term);
long	invmake(char *invname, char *invpost, FILE *infile);
#else
void	boolclear();
POSTING	*boolfile();
void	invclose();
long	invfind();
long	invmake();
#endif
