X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/1d533a2f726534cd02f1c7ba71f0fd454f70e16f..4582a22e254c682b0e91750725401d018c9e93f2:/src/btree_data.cpp?ds=sidebyside diff --git a/src/btree_data.cpp b/src/btree_data.cpp index 27825d7..b95b86a 100644 --- a/src/btree_data.cpp +++ b/src/btree_data.cpp @@ -12,11 +12,17 @@ BTreeData::BTreeData (uchar *node) 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 (); @@ -24,24 +30,61 @@ uint BTreeData::Size () 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, 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 +{ + return (*clave) < (*(data.clave)); +} + + BTreeLeafData::~BTreeLeafData () { } -uint BTreeLeafData::Size () +uint BTreeLeafData::Size () const { + std::cout << "BTreeLeafData::Size()" << std::endl; + 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 +{ + std::cout << "BTreeChildData::Size()" << std::endl; + return sizeof (uint); +} + +uchar* BTreeChildData::ToArray () const +{ + uchar *out = new uchar[Size()]; + memcpy (out, &hijo, sizeof (uint)); + return out; +} +