#include <sys/types.h>
+#include "tools.h"
-/* C-utils */
-#ifndef offsetof
-#define offsetof(type, field) ((int) &((type *)0)->field)
-#endif /* offsetof */
-
-#define TYPEALIGN(ALIGNVAL,LEN) \
- (((long) (LEN) + (ALIGNVAL-1)) & ~((long) (ALIGNVAL-1)))
-
-#define PTRALIGN(LEN) TYPEALIGN(sizeof(void*), (LEN))
-
-/*#define HASHSIZE(LEN) ( TYPEALIGN(2, (int)((LEN)*2)) + 1 )*/
#define HASHSIZE(LEN) ( (LEN)<<1 )
/* end utils */
#define TBTPOINTERSIZE(db) PTRALIGN( (db->keylen) ? TBTPOINTERHRDSZ + db->keylen : sizeof(TBTPointer) )
#define ISINFPOINTER(db, page, ptr) ( (page)->isleaf==0 && (page)->rightlink == 0 && (char*)(ptr) == (page)->data + ((page)->npointer-1) * TBTPOINTERSIZE(db) )
+/* can changed up to 65536 */
#define TBTREEPAGESIZE 8192
#define TBTPAGEHDRSZ (2*sizeof(u_int32_t))
typedef struct {
u_int32_t rightlink;
u_int32_t
- freespace:13, /* correlate to BTREEPAGESIZE */
- npointer:10,
- isleaf:1,
- unused: 8;
+ freespace:16, /* correlate to TBTREEPAGESIZE */
+ npointer:15,
+ isleaf:1;
char data[TBTREEPAGESIZE-TBTPAGEHDRSZ];
} TBTPage;
void TBTFreeIterator(TBTree *db, TBTIterator *iterator);
+int TBTGetFirst(TBTree *db, TBTValue *key, TBTValue *value);
+int TBTGetLast(TBTree *db, TBTValue *key, TBTValue *value);
+
#endif