From 4582a22e254c682b0e91750725401d018c9e93f2 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Thu, 15 Sep 2005 03:40:52 +0000 Subject: [PATCH] Agrego ChildData --- src/btree_data.cpp | 48 ++++++++++++++++++++++++++++++++++++++++------ src/btree_data.h | 46 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/src/btree_data.cpp b/src/btree_data.cpp index dd6f709..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,11 +30,14 @@ 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; } @@ -42,13 +51,40 @@ 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; +} + diff --git a/src/btree_data.h b/src/btree_data.h index 44a3a77..cfe6ef8 100644 --- a/src/btree_data.h +++ b/src/btree_data.h @@ -10,21 +10,24 @@ /** Dato a guardar en los nodos */ class BTreeData { public: - BTreeData () { clave = NULL; } + BTreeData () {} BTreeData (uchar *node); + BTreeData (Clave *k, uint child); virtual ~BTreeData (); - virtual uint Size (); - virtual uchar *ToArray (); + virtual uint Size () const; + virtual uchar *ToArray () const; Clave* getClave () { return clave; } bool operator < (const BTreeData &data) const; virtual operator std::string () const { - if (clave) { - return (*clave); - } - return "NoKey"; + std::string out = (*clave); + std::stringstream ss; + ss << out << " "; + ss << hijo; + ss >> out; + return out; } protected: Clave *clave; @@ -34,12 +37,35 @@ class BTreeData { /** Dato a guardar en las hojas */ class BTreeLeafData:public BTreeData { public: - BTreeLeafData (Clave *k):BTreeData () { clave = k; } + BTreeLeafData (Clave *k) { clave = k; } BTreeLeafData (uchar *node) { clave = new ClaveFija (node); } virtual ~BTreeLeafData (); - virtual uint Size (); - virtual uchar *ToArray (); + virtual uint Size () const; + virtual uchar *ToArray () const; + virtual operator std::string () const { + if (clave) { + return (*clave); + } + return "NoKey"; + } +}; + +class BTreeChildData:public BTreeData { + public: + BTreeChildData (uint child):BTreeData () { hijo = child; } + BTreeChildData (uchar *node); + virtual ~BTreeChildData (); + + virtual uint Size () const; + virtual uchar *ToArray () const; + virtual operator std::string () const { + std::string out; + std::stringstream ss; + ss << hijo; + ss >> out; + return out; + } }; #endif -- 2.43.0