summaryrefslogtreecommitdiff
path: root/lib/dbindex.h
blob: b6b75818706d957f312448c1e62054811ace82c3 (plain)
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
#ifndef H_DBINDEX
#define H_DBINDEX

#ifdef HAVE_DB1_DB_H
#include <db1/db.h>
#else
#ifdef HAVE_DB_185_H
#include <db_185.h>
#else
#include <db.h>
#endif
#endif

/* this will break if sizeof(int) != 4 */

typedef /*@abstract@*/ struct {
    unsigned int recOffset;
    unsigned int fileNumber;
} dbiIndexRecord;

typedef /*@abstract@*/ struct {
    dbiIndexRecord * recs;
    int count;
} dbiIndexSet;

typedef /*@abstract@*/ struct {
    DB * db;
    char * indexname;
} dbiIndex;

#ifdef __cplusplus
extern "C" {
#endif

dbiIndex * dbiOpenIndex(const char * filename, int flags, int perms, DBTYPE type);
void dbiCloseIndex(dbiIndex * dbi);
void dbiSyncIndex(dbiIndex * dbi);
int dbiSearchIndex(dbiIndex * dbi, const char * str, dbiIndexSet * set);
   /* -1 error, 0 success, 1 not found */
int dbiUpdateIndex(dbiIndex * dbi, const char * str, dbiIndexSet * set);
   /* 0 on success */
int dbiAppendIndexRecord(dbiIndexSet * set, dbiIndexRecord rec);
   /* 0 on success - should never fail */
int dbiRemoveIndexRecord(dbiIndexSet * set, dbiIndexRecord rec);
   /* 0 on success - fails if rec is not found */
dbiIndexSet dbiCreateIndexRecord(void);
void dbiFreeIndexRecord(dbiIndexSet set);
int dbiGetFirstKey(dbiIndex * dbi, const char ** key);

extern int dbiIndexSetCount(dbiIndexSet set);

/* structure return */
extern dbiIndexRecord dbiReturnIndexRecordInstance(unsigned int recOffset, unsigned int fileNumber);

extern unsigned int dbiIndexRecordOffset(dbiIndexSet set, int recno);

extern unsigned int dbiIndexRecordFileNumber(dbiIndexSet set, int recno);

#ifdef __cplusplus
}
#endif

#endif	/* H_DBINDEX */