From: Ricardo Markiewicz Date: Tue, 1 Nov 2005 01:36:31 +0000 (+0000) Subject: Agrego dato asociado a la clave. X-Git-Tag: 1_0-pre2~16 X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/commitdiff_plain/031fcd433e233cf31c4ee732883940d9b8c8165a Agrego dato asociado a la clave. No es el mejor lugar para poner algo olvidado. Pero es el menos brain-damage :) --- diff --git a/src/clave.h b/src/clave.h index c0f3a30..27e9487 100644 --- a/src/clave.h +++ b/src/clave.h @@ -28,6 +28,8 @@ class Clave { virtual bool operator < (const Clave &k) const = 0; virtual bool operator == (const Clave &k) const = 0; virtual operator std::string () const = 0; + protected: + uint block_data; }; #endif diff --git a/src/clave_fija.cpp b/src/clave_fija.cpp index ebb08ea..71f6f0d 100644 --- a/src/clave_fija.cpp +++ b/src/clave_fija.cpp @@ -2,26 +2,29 @@ #include #include "clave_fija.h" -ClaveFija::ClaveFija (int n) +ClaveFija::ClaveFija (int n, uint bd) { data = n; + block_data = bd; } ClaveFija::ClaveFija (uchar *n) { memcpy (&data, n, sizeof(int)); + memcpy (&block_data, n+sizeof(int), sizeof(int)); } uint ClaveFija::Size () const { - return sizeof (int); + return sizeof (int)+sizeof(uint); } uchar *ClaveFija::ToArray () const { uchar *out; - out = new uchar[sizeof(int)]; + out = new uchar[Size ()]; memcpy (out, &data, sizeof(int)); + memcpy (out+sizeof (int), &block_data, sizeof(int)); return out; } diff --git a/src/clave_fija.h b/src/clave_fija.h index e70cd52..d04baf9 100644 --- a/src/clave_fija.h +++ b/src/clave_fija.h @@ -9,7 +9,7 @@ class ClaveFija : public Clave { public : ClaveFija (uchar *n); - ClaveFija (int n); + ClaveFija (int n, uint data); virtual ~ClaveFija () {} uint Size () const; diff --git a/src/clave_variable.cpp b/src/clave_variable.cpp index 48a42a6..c97b9d9 100644 --- a/src/clave_variable.cpp +++ b/src/clave_variable.cpp @@ -3,9 +3,10 @@ #include "clave_variable.h" #include -ClaveVariable::ClaveVariable (const std::string &s) +ClaveVariable::ClaveVariable (const std::string &s, uint bd) { data = s; + block_data = bd; } ClaveVariable::ClaveVariable (uchar *n) @@ -19,12 +20,15 @@ ClaveVariable::ClaveVariable (uchar *n) str[len] = '\0'; data = std::string ((const char *)(str)); delete [] str; + n += data.size () * sizeof (uchar); + memcpy (&block_data, n, sizeof (uint)); + raw_data = data; } uint ClaveVariable::Size () const { - return data.size ()*sizeof (uchar)+sizeof (uint); + return data.size ()*sizeof (uchar)+sizeof (uint)*2; } uchar *ClaveVariable::ToArray () const @@ -32,8 +36,13 @@ uchar *ClaveVariable::ToArray () const uchar *out; uint len = data.size (); out = new uchar[Size ()]; + int x = 0; memcpy (out, &len, sizeof (uint)); - memcpy (out+sizeof(uint), data.c_str (), data.size ()*sizeof (uchar)); + x += sizeof (uint); + memcpy (out+x, data.c_str (), data.size ()*sizeof (uchar)); + x += data.size () * sizeof (uchar); + memcpy (out+x, &block_data, sizeof (uint)); + return out; } diff --git a/src/clave_variable.h b/src/clave_variable.h index 224f4e0..b92448b 100644 --- a/src/clave_variable.h +++ b/src/clave_variable.h @@ -13,7 +13,7 @@ class ClaveVariable : public Clave { public : ClaveVariable (uchar *n); - ClaveVariable (const std::string &s); + ClaveVariable (const std::string &s, uint bd); virtual ~ClaveVariable () {} uint Size () const; diff --git a/src/main.cpp b/src/main.cpp index a16a24e..e4f0326 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ int main (int argc, char *argv[]) it = lst.begin (); while (it != lst.end ()) { - ClaveFija c(*it); + ClaveFija c(*it, 0); double l = Random::Double (0.0f, 1.0f); std::cout << l << " >= " << paltas << std::endl; @@ -45,7 +45,7 @@ int main (int argc, char *argv[]) } else { /* Tengo que borrar una clave entre 0 e "i" de la lista * porque son las que ya agregue. */ - ClaveFija c(km.GetRandom ()); + ClaveFija c(km.GetRandom (), 0); try { tree.DelKey (c); @@ -64,7 +64,7 @@ int main (int argc, char *argv[]) int bien = 0; int mal = 0; while (it != l.end ()) { - ClaveFija c(*it); + ClaveFija c(*it, 0); BTreeFindResult *r; r = tree.FindKey (c); diff --git a/src/main_var.cpp b/src/main_var.cpp index c35c392..91359b1 100644 --- a/src/main_var.cpp +++ b/src/main_var.cpp @@ -29,7 +29,7 @@ int main (int argc, char *argv[]) it = lst.begin (); while (it != lst.end ()) { - ClaveVariable c(*it); + ClaveVariable c(*it, 0); double l = Random::Double (0.0f, 1.0f); std::cout << l << " >= " << paltas << std::endl; @@ -47,7 +47,7 @@ int main (int argc, char *argv[]) } else { /* Tengo que borrar una clave entre 0 e "i" de la lista * porque son las que ya agregue. */ - ClaveVariable c(km.GetRandom ()); + ClaveVariable c(km.GetRandom (), 0); try { tree.DelKey (c); @@ -66,7 +66,7 @@ int main (int argc, char *argv[]) int bien = 0; int mal = 0; while (it != l.end ()) { - ClaveVariable c(*it); + ClaveVariable c(*it, 0); BTreeFindResult *r; r = tree.FindKey (c);