2013-08-10 23:38:57 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <database.h>
|
|
|
|
|
2013-12-01 22:31:35 -05:00
|
|
|
IndexEntry :: IndexEntry()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexEntry :: IndexEntry(const std::string &k, unsigned int v)
|
|
|
|
: key(k)
|
|
|
|
{
|
|
|
|
insert(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexEntry :: ~IndexEntry()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &IndexEntry :: primary_key()
|
|
|
|
{
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexEntry :: write(File &f)
|
|
|
|
{
|
|
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
f << key << std::endl << values.size() << " ";
|
|
|
|
for (it = values.begin(); it != values.end(); it++)
|
|
|
|
f << *it << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexEntry :: read(File &f)
|
|
|
|
{
|
|
|
|
unsigned int num, val;
|
|
|
|
|
|
|
|
f >> key >> num;
|
|
|
|
for (unsigned int i = 0; i < num; i++) {
|
|
|
|
f >> val;
|
|
|
|
values.insert(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexEntry :: print()
|
|
|
|
{
|
|
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
:: print("{");
|
|
|
|
for (it = values.begin(); it != values.end(); it++) {
|
|
|
|
if (it != values.begin())
|
|
|
|
:: print(" ");
|
|
|
|
:: print("%d", *it);
|
|
|
|
}
|
|
|
|
:: print("}");
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexEntry :: insert(unsigned int val)
|
|
|
|
{
|
|
|
|
values.insert(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexEntry :: remove(unsigned int val)
|
|
|
|
{
|
|
|
|
values.erase(val);
|
|
|
|
}
|