X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/681835993486168a113f7cc81593f738c736f4df..98e331147474997778f92d14b794a94f1dc3bedb:/src/btree.cpp?ds=inline diff --git a/src/btree.cpp b/src/btree.cpp index 9fece76..ddcb14c 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -54,7 +54,13 @@ void BTree::WriteBlock (uchar *block, uint num) void BTree::AddKey (const Clave &k) { uint left, right; - Clave *kout = AddKeyR (&k, 0, left, right); + Clave *kout; + + try { + kout = AddKeyR (k.Clone (), 0, left, right); + } catch (Exception *e) { + throw e; + } if (kout) { unsigned short level; @@ -103,10 +109,19 @@ Clave* BTree::AddKeyR (const Clave *k, uint node_num, uint &left_child, uint &ri ReadNodoHeader (node, &node_header); delete [] node; - if (node_header.level == 0) - return AddKeyLeafR (k, node_num, left_child, right_child); + if (node_header.level == 0) { + try { + return AddKeyLeafR (k, node_num, left_child, right_child); + } catch (Exception *e) { + throw e; + } + } - return AddKeyOtherR (k, node_num, left_child, right_child); + try { + return AddKeyOtherR (k, node_num, left_child, right_child); + } catch (Exception *e) { + throw e; + } } Clave* BTree::AddKeyLeafR (const Clave *k, uint node_num, uint &left_child, uint &right_child) @@ -128,6 +143,14 @@ Clave* BTree::AddKeyLeafR (const Clave *k, uint node_num, uint &left_child, uint while (it != node_keys.end ()) { datait = (*it); + if (tree_type == TYPE_UNIQUE) { + /* Verifico que la clave no existea ya en el arbol */ + if ((*data) == (*datait)) { + throw new AddException (); + return NULL; + } + } + if ((*data) < (*datait)) /* Me pase, lo agrego aca! */ break; @@ -161,6 +184,13 @@ Clave* BTree::AddKeyLeafR (const Clave *k, uint node_num, uint &left_child, uint while (it != node_keys.end ()) { BTreeData *datait; datait = (*it); + if (tree_type == TYPE_UNIQUE) { + /* Verifico que la clave no existea ya en el arbol */ + if ((*data) == (*datait)) { + throw new AddException (); + return NULL; + } + } if ((*data) < (*datait)) /* Me pase, lo agrego aca! */ break; @@ -254,6 +284,13 @@ Clave* BTree::AddKeyOtherR (const Clave *k, uint node_num, uint &left_child, uin posterior = it; while (it != node_keys.end ()) { + if (tree_type == TYPE_UNIQUE) { + /* Verifico que la clave no existea ya en el arbol */ + if ((*data) == (*(*it))) { + throw new AddException (); + return NULL; + } + } if ((*data) < (*(*it))) break; ultima = it; @@ -283,6 +320,13 @@ Clave* BTree::AddKeyOtherR (const Clave *k, uint node_num, uint &left_child, uin while (it != node_keys.end ()) { datait = (*it); + if (tree_type == TYPE_UNIQUE) { + /* Verifico que la clave no existea ya en el arbol */ + if ((*data) == (*datait)) { + throw new AddException (); + return NULL; + } + } if ((*data) < (*datait)) /* Me pase, lo agrego aca! */ break; @@ -318,6 +362,13 @@ Clave* BTree::AddKeyOtherR (const Clave *k, uint node_num, uint &left_child, uin while (it != node_keys.end ()) { BTreeData *datait; datait = (*it); + if (tree_type == TYPE_UNIQUE) { + /* Verifico que la clave no existea ya en el arbol */ + if ((*data) == (*datait)) { + throw new AddException (); + return NULL; + } + } if ((*data) < (*datait)) /* Me pase, lo agrego aca! */ break;