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 ()
31 uint BTreeData::Size () const
33 uint s = sizeof (uint);
34 if (clave) s += clave->Size ();
35 else std::cout << "No tengo clave\n";
39 uchar* BTreeData::ToArray () const
41 uchar *out = new uchar[Size()];
43 uchar *n = clave->ToArray ();
44 memcpy (out, n, clave->Size ());
45 memcpy (out+clave->Size (), &hijo, sizeof (uint));
48 memcpy (out, &hijo, sizeof (uint));
52 bool BTreeData::operator < (const BTreeData &data) const
54 if (!data.clave) return false;
56 return (*clave) < (*(data.clave));
59 bool BTreeData::operator == (const BTreeData &data) const
61 if (!data.clave) return false;
63 return (*clave) == (*(data.clave));
66 bool BTreeData::Abrev (BTreeData *anterior)
68 if (anterior == NULL) return false;
70 ClaveVariable *c = (ClaveVariable *)clave;
71 return c->Abrev (dynamic_cast<ClaveVariable *>(anterior->getClave ()));
74 bool BTreeData::DesAbrev (BTreeData *anterior)
76 if (anterior == NULL) return false;
78 ClaveVariable *c = (ClaveVariable *)clave;
79 return c->DesAbrev (dynamic_cast<ClaveVariable *>(anterior->getClave ()));
82 BTreeLeafData::BTreeLeafData (uchar *node, int key_type)
84 if (key_type == BTree::KEY_FIXED)
85 clave = new ClaveFija (node);
87 clave = new ClaveVariable (node);
90 BTreeLeafData::~BTreeLeafData ()
94 uint BTreeLeafData::Size () const
97 std::cout << "BTreeLeafData::Size : No tengo clave!" << std::endl;
100 return clave->Size ();
103 uchar* BTreeLeafData::ToArray () const
105 return clave->ToArray ();
108 BTreeChildData::BTreeChildData (uchar *node)
110 memcpy (&hijo, node, sizeof (uint));
113 BTreeChildData::~BTreeChildData ()
117 uint BTreeChildData::Size () const
119 return sizeof (uint);
122 uchar* BTreeChildData::ToArray () const
124 uchar *out = new uchar[Size()];
125 memcpy (out, &hijo, sizeof (uint));