From: Ricardo Markiewicz Date: Sun, 30 Oct 2005 05:14:02 +0000 (+0000) Subject: Agrego ToRaw a las claves. X-Git-Tag: 1_0-pre2~28 X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/commitdiff_plain/57dbb7df8973a3e0c0c570c1eae9d84802e02bd9?hp=58f5f2e6ba6f33bc457e98ec883f2834c9a5fe6f Agrego ToRaw a las claves. Este nuevo metodo es parecido a ToArray, solo que muestra la clave tal cual se leyo del disco. Es necesario para mostrar luego las claves abreviadas y esas cosas. --- diff --git a/src/clave.h b/src/clave.h index e609bb0..c0f3a30 100644 --- a/src/clave.h +++ b/src/clave.h @@ -2,23 +2,26 @@ #ifndef _CLAVE_H_ #define _CLAVE_H_ -/* Clave para agregar a un arbol B */ #include "common.h" #include -/** Clave abstracta para manejo de Claves */ +/** Clase abstracta para manejo de Claves */ class Clave { public: virtual ~Clave () {} - /** Retorna el tamaño en bytes que ocupa la clave */ + /** Retorna el tamaño en bytes que ocupa la clave */ virtual uint Size () const = 0; /** Retorna un array de bytes de Size() de longitud. * * El contenido del array es la clave en formato RAW * para guardar en disco. + * + * El array debe ser liberado por el llamador. */ virtual uchar *ToArray () const = 0; + virtual uchar *ToRaw (uint &size) const = 0; + /** Retorna un clon de la clave actual */ virtual Clave *Clone () const = 0; diff --git a/src/clave_fija.cpp b/src/clave_fija.cpp index 155e0e6..ebb08ea 100644 --- a/src/clave_fija.cpp +++ b/src/clave_fija.cpp @@ -40,3 +40,10 @@ bool ClaveFija::operator == (const Clave &c) const { return data == ((ClaveFija&)c).data; } + +uchar *ClaveFija::ToRaw (uint &size) const +{ + size = Size (); + return ToArray (); +} + diff --git a/src/clave_fija.h b/src/clave_fija.h index 7b715a9..e70cd52 100644 --- a/src/clave_fija.h +++ b/src/clave_fija.h @@ -14,6 +14,7 @@ class ClaveFija : public Clave { uint Size () const; uchar *ToArray () const; + uchar *ToRaw (uint &size) const; Clave *Clone () const; virtual bool operator < (const Clave &c) const; diff --git a/src/clave_variable.cpp b/src/clave_variable.cpp index 47d81ba..48a42a6 100644 --- a/src/clave_variable.cpp +++ b/src/clave_variable.cpp @@ -19,11 +19,12 @@ ClaveVariable::ClaveVariable (uchar *n) str[len] = '\0'; data = std::string ((const char *)(str)); delete [] str; + raw_data = data; } uint ClaveVariable::Size () const { - return data.size ()+sizeof (uint); + return data.size ()*sizeof (uchar)+sizeof (uint); } uchar *ClaveVariable::ToArray () const @@ -32,7 +33,7 @@ uchar *ClaveVariable::ToArray () const uint len = data.size (); out = new uchar[Size ()]; memcpy (out, &len, sizeof (uint)); - memcpy (out+sizeof(uint), data.c_str (), data.size ()); + memcpy (out+sizeof(uint), data.c_str (), data.size ()*sizeof (uchar)); return out; } @@ -82,7 +83,6 @@ bool ClaveVariable::DesAbrev (ClaveVariable *c) if (pos <= 0) return false; std::string siguales = data.substr (0, pos); - std::cout << siguales << std::endl; int iguales = atoi (siguales.c_str ()); std::string primera_parte = c->data.substr (0, iguales); @@ -113,3 +113,14 @@ std::string ClaveVariable::abreviar(std::string &p, std::string &a, int &iguales return std::string (actual); } +uchar *ClaveVariable::ToRaw (uint &size) const +{ + uchar *out; + size = raw_data.size ()*sizeof (uchar)+sizeof (uint); + uint len = raw_data.size (); + out = new uchar[size]; + memcpy (out, &len, sizeof (uint)); + memcpy (out+sizeof(uint), raw_data.c_str (), raw_data.size ()*sizeof (uchar)); + return out; +} + diff --git a/src/clave_variable.h b/src/clave_variable.h index e568451..224f4e0 100644 --- a/src/clave_variable.h +++ b/src/clave_variable.h @@ -18,6 +18,7 @@ class ClaveVariable : public Clave { uint Size () const; uchar *ToArray () const; + uchar *ToRaw (uint &size) const; Clave *Clone () const; bool Abrev (ClaveVariable *c); @@ -31,6 +32,7 @@ class ClaveVariable : public Clave { private: std::string abreviar(std::string &primera, std::string &actual, int &iguales); std::string data; + std::string raw_data; }; #endif diff --git a/viewer/view_properties.cpp b/viewer/view_properties.cpp index 8f92d5f..11498ba 100644 --- a/viewer/view_properties.cpp +++ b/viewer/view_properties.cpp @@ -113,8 +113,11 @@ void ViewProperties::ShowItem (BTreeData *data, BTreeNodeHeader &header) std::string ViewProperties::ToRaw (BTreeData *p) { std::stringstream ss; - uint size = p->Size (), i; - uchar *arr = p->ToArray (); + uint size = 0, i; + uchar *arr = NULL; + if (p->GetKey ()) { + arr = p->GetKey ()->ToRaw (size); + } for (i=0; i < size; i++) { if (isalnum (arr[i])) @@ -123,7 +126,14 @@ std::string ViewProperties::ToRaw (BTreeData *p) ss << "."; } - delete [] arr; + if (p->GetChild () != 0) { + ss << "("; + ss << p->GetChild (); + ss << ")"; + } + + if (arr) + delete [] arr; return ss.str (); }