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
#include <string>
#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;
}
class ClaveFija : public Clave {
public :
ClaveFija (uchar *n);
- ClaveFija (int n);
+ ClaveFija (int n, uint data);
virtual ~ClaveFija () {}
uint Size () const;
#include "clave_variable.h"
#include <iostream>
-ClaveVariable::ClaveVariable (const std::string &s)
+ClaveVariable::ClaveVariable (const std::string &s, uint bd)
{
data = s;
+ block_data = bd;
}
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
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;
}
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;
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;
} 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);
int bien = 0;
int mal = 0;
while (it != l.end ()) {
- ClaveFija c(*it);
+ ClaveFija c(*it, 0);
BTreeFindResult *r;
r = tree.FindKey (c);
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;
} 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);
int bien = 0;
int mal = 0;
while (it != l.end ()) {
- ClaveVariable c(*it);
+ ClaveVariable c(*it, 0);
BTreeFindResult *r;
r = tree.FindKey (c);