X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/4582a22e254c682b0e91750725401d018c9e93f2..b192ca855bf9015796ec8f9093d8c872fffbcd5c:/src/btree_data.cpp diff --git a/src/btree_data.cpp b/src/btree_data.cpp index b95b86a..bc0ce93 100644 --- a/src/btree_data.cpp +++ b/src/btree_data.cpp @@ -1,12 +1,16 @@ #include "btree_data.h" +#include "btree.h" -BTreeData::BTreeData (uchar *node) +BTreeData::BTreeData (uchar *node, int tree_type) { /* TODO : Aca deberia detectar el tipo de clave (necesito * info desde el arbol */ - clave = new ClaveFija (node); + if (tree_type == BTree::KEY_FIXED) + clave = new ClaveFija (node); + else + clave = new ClaveVariable (node); node += clave->Size (); memcpy (&hijo, node, sizeof (uint)); @@ -20,13 +24,15 @@ BTreeData::BTreeData (Clave *k, uint child) BTreeData::~BTreeData () { + if (clave) + delete clave; } uint BTreeData::Size () const { uint s = sizeof (uint); if (clave) s += clave->Size (); - + else std::cout << "No tengo clave\n"; return s; } @@ -34,8 +40,10 @@ uchar* BTreeData::ToArray () const { uchar *out = new uchar[Size()]; if (clave) { - memcpy (out, clave->ToArray (), clave->Size ()); + uchar *n = clave->ToArray (); + memcpy (out, n, clave->Size ()); memcpy (out+clave->Size (), &hijo, sizeof (uint)); + delete [] n; } else memcpy (out, &hijo, sizeof (uint)); return out; @@ -43,9 +51,25 @@ uchar* BTreeData::ToArray () const bool BTreeData::operator < (const BTreeData &data) const { + if (!data.clave) return false; + return (*clave) < (*(data.clave)); } +bool BTreeData::operator == (const BTreeData &data) const +{ + if (!data.clave) return false; + + return (*clave) == (*(data.clave)); +} + +BTreeLeafData::BTreeLeafData (uchar *node, int key_type) +{ + if (key_type == BTree::KEY_FIXED) + clave = new ClaveFija (node); + else + clave = new ClaveVariable (node); +} BTreeLeafData::~BTreeLeafData () { @@ -53,7 +77,6 @@ BTreeLeafData::~BTreeLeafData () uint BTreeLeafData::Size () const { - std::cout << "BTreeLeafData::Size()" << std::endl; if (!clave) { std::cout << "BTreeLeafData::Size : No tengo clave!" << std::endl; return 0; @@ -77,7 +100,6 @@ BTreeChildData::~BTreeChildData () uint BTreeChildData::Size () const { - std::cout << "BTreeChildData::Size()" << std::endl; return sizeof (uint); }