1 /***************************************************************** 2 * @LICENSE@ 3 *****************************************************************/ 4 5 #ifndef GSI64H_INCLUDED 6 #define GSI64H_INCLUDED 7 #ifdef USE_GSI64 8 9 /* gsi64.h 10 * Database indexing (GSI64 format support) 11 * CVS $Id: gsi64.h,v 1.2 2000/12/21 23:42:59 eddy Exp) 12 * 13 * A GSI64 (generic sequence index, 64 bit hack) file is composed of 14 * recnum + nfiles + 1 records. Each record contains 15 * three fields; key, file number, and disk offset. 16 * Record 0 contains: 17 * [ "GSI64" ] [ nfiles ] [ recnum ] 18 * Records 1..nfiles map file names to file numbers, and contain: 19 * [ filename ] [ file number, 1..nfiles ] [ 0 (unused) ] 20 * Records nfiles+1 to recnum+nfiles+1 provide disk offset 21 * and file number indices for every key: 22 * [ key ] [ file number ] [ offset] 23 * 24 * Because the file is binary, we take some (but not 25 * complete) care to improve portability amongst platforms. 26 * This means using network order integers (see ntohl()) 27 * and defining types for 16 and 64 bit integers. 28 * 29 * A short test program that verifies the sizes of these 30 * data types would be a good idea... 31 * 32 * Because we use 64-bit offsets, ftell64(), and fseek64(), 33 * we rely on the OS actually providing these. This is 34 * a temporary hack for human genome analysis. 35 */ 36 typedef unsigned long long sqd_uint64; /* 64 bit integer. */ 37 38 #define GSI64_KEYSIZE 32 /* keys are 32 bytes long */ 39 #define GSI64_RECSIZE 42 /* 32 + 2 + 8 bytes */ 40 #define SQD_UINT16_MAX 65535 /* 2^16-1 */ 41 #define SQD_UINT64_MAX 18446744073709551615LU /* 2^64-1 */ 42 43 struct gsi64_s { 44 FILE *gsifp; /* open GSI index file */ 45 sqd_uint16 nfiles; /* number of files = 16 bit int */ 46 sqd_uint64 recnum; /* number of records = 64 bit int */ 47 }; 48 typedef struct gsi64_s GSI64FILE; 49 50 struct gsi64key_s { 51 char key[GSI64_KEYSIZE]; 52 sqd_uint16 filenum; 53 sqd_uint64 offset; 54 }; 55 struct gsi64index_s { 56 char **filenames; 57 int *fmt; 58 sqd_uint16 nfiles; 59 60 struct gsi64key_s *elems; 61 sqd_uint64 nkeys; 62 }; 63 64 65 66 /* if ntohl() and friends are not available, you 67 * can slip replacements in by providing sre_ntohl() 68 * functions. (i.e., there is a possible portability problem here.) 69 */ 70 #if 0 71 #define sre_ntohl(x) ntohl(x); 72 #define sre_ntohs(x) ntohs(x); 73 #define sre_htonl(x) htonl(x); 74 #define sre_htons(x) htons(x); 75 #endif 76 77 /* from gsi64.c 78 */ 79 extern GSI64FILE *GSI64Open(char *gsifile); 80 extern int GSI64GetRecord(GSI64FILE *gsi, char *f1, sqd_uint16 *f2, sqd_uint64 *f3); 81 extern int GSI64GetOffset(GSI64FILE *gsi, char *key, char *sqfile, 82 int *fmt, long long *ret_offset); 83 extern void GSI64Close(GSI64FILE *gsi); 84 extern struct gsi64index_s *GSI64AllocIndex(void); 85 extern void GSI64FreeIndex(struct gsi64index_s *g); 86 extern void GSI64AddFileToIndex(struct gsi64index_s *g, char *filename, int fmt); 87 extern void GSI64AddKeyToIndex(struct gsi64index_s *g, char *key, int filenum, long long offset); 88 extern void GSI64SortIndex(struct gsi64index_s *g); 89 extern void GSI64WriteIndex(FILE *fp, struct gsi64index_s *g); 90 extern void GSI64WriteHeader(FILE *fp, int nfiles, long long nkeys); 91 extern int GSI64WriteFileRecord(FILE *fp, char *fname, int idx, int fmt); 92 extern int GSI64WriteKeyRecord(FILE *fp, char *key, int fileidx, long long offset); 93 94 #endif /* USE_GSI64 */ 95 #endif /*GSIH_INCLUDED*/ 96