X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/8699d7e1ccbda4282f8ba693422f337be31d100b..HEAD:/src/btree_data.cpp?ds=inline diff --git a/src/btree_data.cpp b/src/btree_data.cpp index 46917d6..1adeb83 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,6 +24,10 @@ BTreeData::BTreeData (Clave *k, uint child) BTreeData::~BTreeData () { + if (clave) { + delete clave; + clave = NULL; + } } uint BTreeData::Size () const @@ -34,8 +42,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,12 +53,49 @@ 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)); +} + +bool BTreeData::Abrev (BTreeData *anterior) +{ + if (anterior == NULL) return false; + + ClaveVariable *c = (ClaveVariable *)clave; + return c->Abrev (dynamic_cast(anterior->GetKey ())); +} + +bool BTreeData::DesAbrev (BTreeData *anterior) +{ + if (anterior == NULL) return false; + + ClaveVariable *c = (ClaveVariable *)clave; + return c->DesAbrev (dynamic_cast(anterior->GetKey ())); +} + +BTreeLeafData::BTreeLeafData (uchar *node, int key_type) +{ + hijo = 0; + if (key_type == BTree::KEY_FIXED) + clave = new ClaveFija (node); + else + clave = new ClaveVariable (node); +} BTreeLeafData::~BTreeLeafData () { + if (clave) { + delete clave; + clave = NULL; + } } uint BTreeLeafData::Size () const @@ -68,6 +115,7 @@ uchar* BTreeLeafData::ToArray () const BTreeChildData::BTreeChildData (uchar *node) { memcpy (&hijo, node, sizeof (uint)); + clave = NULL; } BTreeChildData::~BTreeChildData () @@ -86,3 +134,7 @@ uchar* BTreeChildData::ToArray () const return out; } +bool BTreeChildData::operator < (const BTreeData &data) const +{ + return false; +}