X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/6fcd86dce909f05de818fdd78d76e70aabc3ad22..3981ffa23945f8764b5bc4c790ff0f0947858010:/src/btree.h diff --git a/src/btree.h b/src/btree.h index cacd29b..999d798 100644 --- a/src/btree.h +++ b/src/btree.h @@ -44,18 +44,23 @@ * tomar una idea simimar) */ +#include #include +#include +#include "common.h" +#include "clave.h" +#include "clave_fija.h" +#include "btree_data.h" /* alias para codear menos :) */ -typedef unsigned char uchar; /** Encabezado del archivo BTree */ -typedef struct _btree_file_ { - unsigned int block_size; -} BTreeFileHeader; +struct BTreeFileHeader { + uint block_size; +}; /** Encabezado de un bloque */ -typedef struct _btree_header_ { +struct BTreeNodeHeader { /** Indica a que nivel corresponde un bloque * * nivel == 0 : una hoja @@ -71,7 +76,7 @@ typedef struct _btree_header_ { /** Cantidad de elementos en el nodo */ unsigned int item_count; -} BTreeHeader; +}; /** Crea un nuevo arbol B * @@ -81,15 +86,26 @@ typedef struct _btree_header_ { */ class BTree { public: - BTree (const char *filename, unsigned int block_size, bool create_new_file = false); + BTree (const std::string &filename, unsigned int block_size, bool create_new_file = false); ~BTree (); - void AddKey (); - void DelKey (); + void AddKey (const Clave &k); + void DelKey (const Clave &k); + + protected: + Clave* AddKeyR (const Clave *k, uint node_num, uint &left_child, uint &right_child); + + void WriteFileHeader (); - private: - void write_tree_header (); - void write_block (uchar *block, uint num); + void WriteBlock (uchar *block, uint num); + uchar *ReadBlock (uint num); + uchar *NewBlock (uint &num); + + void ReadNodoHeader (uchar *node, BTreeNodeHeader *header); + void WriteNodoHeader (uchar *node, BTreeNodeHeader *header); + + std::list ReadKeys (uchar *node, BTreeNodeHeader &node_header); + void WriteKeys (uchar *node, BTreeNodeHeader &node_header, std::list &keys); std::string filename; BTreeFileHeader header; @@ -99,6 +115,10 @@ class BTree { * \TODO Ver si vale la pena */ FILE *fp; + + + /* DEBUG */ + void PrintNode (uint num); }; #endif // _B_TREE_H