X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/78d8bc6c001cb877d8c7daf3868835815a97ce21..88f6f1c9a8861bed8d1907001a10c4605e268a5e:/src/btree_data.h?ds=sidebyside diff --git a/src/btree_data.h b/src/btree_data.h index 5b6a9f6..5bbfc27 100644 --- a/src/btree_data.h +++ b/src/btree_data.h @@ -10,23 +10,63 @@ /** Dato a guardar en los nodos */ class BTreeData { public: + 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; } + uint getChild () { return hijo; } + + bool operator < (const BTreeData &data) const; + virtual operator std::string () const { + std::string out = (*clave); + std::stringstream ss; + ss << "(" << out ; + ss << ")" << "[" << hijo << "]"; + ss >> out; + return out; + } protected: Clave *clave; - uint hijo_izquierdo; + uint hijo; }; /** Dato a guardar en las hojas */ -class BTreeLeafData:BTreeData { +class BTreeLeafData:public BTreeData { public: + 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; clave = NULL; } + 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