2 #include "btree_data.h"
5 BTreeData::BTreeData (uchar *node, int tree_type)
7 /* TODO : Aca deberia detectar el tipo de clave (necesito
10 if (tree_type == BTree::KEY_FIXED)
11 clave = new ClaveFija (node);
13 clave = new ClaveVariable (node);
14 node += clave->Size ();
16 memcpy (&hijo, node, sizeof (uint));
19 BTreeData::BTreeData (Clave *k, uint child)
25 BTreeData::~BTreeData ()
33 uint BTreeData::Size () const
35 uint s = sizeof (uint);
36 if (clave) s += clave->Size ();
37 else std::cout << "No tengo clave\n";
41 uchar* BTreeData::ToArray () const
43 uchar *out = new uchar[Size()];
45 uchar *n = clave->ToArray ();
46 memcpy (out, n, clave->Size ());
47 memcpy (out+clave->Size (), &hijo, sizeof (uint));
50 memcpy (out, &hijo, sizeof (uint));
54 bool BTreeData::operator < (const BTreeData &data) const
56 if (!data.clave) return false;
58 return (*clave) < (*(data.clave));
61 bool BTreeData::operator == (const BTreeData &data) const
63 if (!data.clave) return false;
65 return (*clave) == (*(data.clave));
68 bool BTreeData::Abrev (BTreeData *anterior)
70 if (anterior == NULL) return false;
72 ClaveVariable *c = (ClaveVariable *)clave;
73 return c->Abrev (dynamic_cast<ClaveVariable *>(anterior->GetKey ()));
76 bool BTreeData::DesAbrev (BTreeData *anterior)
78 if (anterior == NULL) return false;
80 ClaveVariable *c = (ClaveVariable *)clave;
81 return c->DesAbrev (dynamic_cast<ClaveVariable *>(anterior->GetKey ()));
84 BTreeLeafData::BTreeLeafData (uchar *node, int key_type)
87 if (key_type == BTree::KEY_FIXED)
88 clave = new ClaveFija (node);
90 clave = new ClaveVariable (node);
93 BTreeLeafData::~BTreeLeafData ()
101 uint BTreeLeafData::Size () const
104 std::cout << "BTreeLeafData::Size : No tengo clave!" << std::endl;
107 return clave->Size ();
110 uchar* BTreeLeafData::ToArray () const
112 return clave->ToArray ();
115 BTreeChildData::BTreeChildData (uchar *node)
117 memcpy (&hijo, node, sizeof (uint));
121 BTreeChildData::~BTreeChildData ()
125 uint BTreeChildData::Size () const
127 return sizeof (uint);
130 uchar* BTreeChildData::ToArray () const
132 uchar *out = new uchar[Size()];
133 memcpy (out, &hijo, sizeof (uint));
137 bool BTreeChildData::operator < (const BTreeData &data) const