3 #include "clave_variable.h"
6 ClaveVariable::ClaveVariable (const std::string &s)
11 ClaveVariable::ClaveVariable (uchar *n)
15 memcpy (&len, n, sizeof (uint));
16 uchar *str = new uchar[len+1];
18 memcpy (str, n, sizeof (uchar)*len);
20 data = std::string ((const char *)(str));
24 uint ClaveVariable::Size () const
26 return data.size ()+sizeof (uint);
29 uchar *ClaveVariable::ToArray () const
32 uint len = data.size ();
33 out = new uchar[Size ()];
34 memcpy (out, &len, sizeof (uint));
35 memcpy (out+sizeof(uint), data.c_str (), data.size ());
39 Clave *ClaveVariable::Clone () const
41 ClaveVariable *k = new ClaveVariable (*this);
45 bool ClaveVariable::operator < (const Clave &c) const
47 return data < ((ClaveVariable&)c).data;
50 bool ClaveVariable::operator == (const Clave &c) const
52 return data == ((ClaveVariable&)c).data;
55 bool ClaveVariable::Abrev (ClaveVariable *c)
57 if (c == NULL) return false;
61 resto = abreviar (c->data, data, iguales);
63 /* No hago nada si solo machea un caracter */
64 if (iguales < 2) return false;
75 bool ClaveVariable::DesAbrev (ClaveVariable *c)
77 if (c == NULL) return false;
79 int pos = data.find ("|");
81 /* No esta abreviada! */
82 if (pos <= 0) return false;
84 std::string siguales = data.substr (0, pos);
85 std::cout << siguales << std::endl;
86 int iguales = atoi (siguales.c_str ());
88 std::string primera_parte = c->data.substr (0, iguales);
89 std::string segunda_parte = data.substr (pos+1, data.size () - pos - 1);
91 data = primera_parte + segunda_parte;
96 std::string ClaveVariable::abreviar(std::string &p, std::string &a, int &iguales)
98 char *primera = (char *)p.c_str ();
99 char *actual = (char *)a.c_str ();
102 while (((*primera) != '\0') && ((*actual) != '\0')) {
103 if ((*primera) == (*actual)) {
108 /* No coinciden mas! */
113 return std::string (actual);