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->getClave ()));
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->getClave ()));
84 BTreeLeafData::BTreeLeafData (uchar *node, int key_type)
86 if (key_type == BTree::KEY_FIXED)
87 clave = new ClaveFija (node);
89 clave = new ClaveVariable (node);
92 BTreeLeafData::~BTreeLeafData ()
100 uint BTreeLeafData::Size () const
103 std::cout << "BTreeLeafData::Size : No tengo clave!" << std::endl;
106 return clave->Size ();
109 uchar* BTreeLeafData::ToArray () const
111 return clave->ToArray ();
114 BTreeChildData::BTreeChildData (uchar *node)
116 memcpy (&hijo, node, sizeof (uint));
119 BTreeChildData::~BTreeChildData ()
123 uint BTreeChildData::Size () const
125 return sizeof (uint);
128 uchar* BTreeChildData::ToArray () const
130 uchar *out = new uchar[Size()];
131 memcpy (out, &hijo, sizeof (uint));