X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/78d8bc6c001cb877d8c7daf3868835815a97ce21..2ab8041933e77875de62bc73e76febc528af258e:/src/btree_data.cpp diff --git a/src/btree_data.cpp b/src/btree_data.cpp index 5e351ce..a5d9b68 100644 --- a/src/btree_data.cpp +++ b/src/btree_data.cpp @@ -1,47 +1,108 @@ #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_izquierdo, node, sizeof (uint)); + memcpy (&hijo, node, sizeof (uint)); +} + +BTreeData::BTreeData (Clave *k, uint child) +{ + clave = k; + hijo = child; } BTreeData::~BTreeData () { } -uint BTreeData::Size () +uint BTreeData::Size () const { uint s = sizeof (uint); if (clave) s += clave->Size (); - + else std::cout << "No tengo clave\n"; return s; } -uchar* BTreeData::ToArray () +uchar* BTreeData::ToArray () const { uchar *out = new uchar[Size()]; - memcpy (out, clave->ToArray (), clave->Size ()); - memcpy (out+clave->Size (), &hijo_izquierdo, sizeof (uint)); + if (clave) { + memcpy (out, clave->ToArray (), clave->Size ()); + memcpy (out+clave->Size (), &hijo, sizeof (uint)); + } else + memcpy (out, &hijo, sizeof (uint)); return out; } +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 () { } -uint BTreeLeafData::Size () +uint BTreeLeafData::Size () const { + if (!clave) { + std::cout << "BTreeLeafData::Size : No tengo clave!" << std::endl; + return 0; + } return clave->Size (); } -uchar* BTreeLeafData::ToArray () +uchar* BTreeLeafData::ToArray () const { return clave->ToArray (); } + +BTreeChildData::BTreeChildData (uchar *node) +{ + memcpy (&hijo, node, sizeof (uint)); +} + +BTreeChildData::~BTreeChildData () +{ +} + +uint BTreeChildData::Size () const +{ + return sizeof (uint); +} + +uchar* BTreeChildData::ToArray () const +{ + uchar *out = new uchar[Size()]; + memcpy (out, &hijo, sizeof (uint)); + return out; +} +