#ifndef BTREE_H
#define BTREE_H
#include "superblock.h"
#include "inode.h"
#define B_NODE_MAGIC_1 0xDEADBEEF
#define B_NODE_MAGIC_2 0x1900BABE
#define B_MAX_KEYS 4
#define B_MAX_NAME_LENGTH 256
#define B_MAX_CHILD_COUNT 4
typedef struct bNode {
uInt32 magic1 __attribute__ ((packed));
uInt32 used __attribute__ ((packed));
char keys[B_MAX_KEYS][B_MAX_NAME_LENGTH] __attribute__ ((packed));
bool present[B_MAX_KEYS] __attribute__ ((packed));
void * childHead[(B_MAX_KEYS+1)*8/sizeof(void *)] __attribute__ ((packed));
void * childTail[(B_MAX_KEYS+1)*8/sizeof(void *)] __attribute__ ((packed));
uInt32 childCount[B_MAX_KEYS+1] __attribute__ ((packed));
bNode * parent __attribute__ ((packed));
bool leafNode __attribute__ ((packed));
uInt32 magic2 __attribute__ ((packed));
} bNode; // bNode
class bTree {
protected:
bNode * root;
ubixfsInode * treeSearch(bNode *, const char *);
ubixfsInode * inodeSearch(ubixfsInode *, const char *);
void splitNode(bNode *);
bNode * allocEmptyNode(void);
public:
bTree(ubixfsInode *);
bTree(void) : root(NULL) { };
ubixfsInode * Find(const char *);
ubixfsInode * GetFirstNode(void);
bool Delete(const char *);
void Info(void);
bool Insert(ubixfsInode *);
bool Save(const char *);
bool Load(const char *);
void Print(void);
~bTree(void) { };
}; // bTree
#endif // !BTREE_H