e89941af31
In addition to documentation updates, I also solve a few warnings that Doxygen gives me. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
73 lines
1.2 KiB
C++
73 lines
1.2 KiB
C++
/**
|
|
* @file
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/index.h>
|
|
|
|
|
|
IndexEntry :: IndexEntry() {}
|
|
IndexEntry :: IndexEntry(const std::string &key)
|
|
: _key(key)
|
|
{}
|
|
|
|
const std::string IndexEntry :: primary_key() const
|
|
{
|
|
return _key;
|
|
}
|
|
|
|
void IndexEntry :: insert(unsigned int value)
|
|
{
|
|
_values.insert(value);
|
|
}
|
|
|
|
void IndexEntry :: remove(unsigned int value)
|
|
{
|
|
_values.erase(value);
|
|
}
|
|
|
|
void IndexEntry :: write(File &file)
|
|
{
|
|
std::set<unsigned int>::iterator it;
|
|
file << _key << std::endl << _values.size() << " ";
|
|
for (it = _values.begin(); it != _values.end(); it++)
|
|
file << *it << " ";
|
|
}
|
|
|
|
void IndexEntry :: read(File &file)
|
|
{
|
|
unsigned int num, val;
|
|
|
|
file >> _key >> num;
|
|
for (unsigned int i = 0; i < num; i++) {
|
|
file >> val;
|
|
insert(val);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Index :: Index(const std::string &filepath, bool autosave)
|
|
: Database(filepath, autosave)
|
|
{}
|
|
|
|
void Index :: insert(const std::string &key, unsigned int val)
|
|
{
|
|
IndexEntry *it = find(key);
|
|
if (it == NULL)
|
|
it = Database :: insert(IndexEntry(key));
|
|
|
|
it->insert(val);
|
|
autosave();
|
|
}
|
|
|
|
void Index :: remove(const std::string &key, unsigned int val)
|
|
{
|
|
IndexEntry *it = find(key);
|
|
|
|
if (it == NULL)
|
|
return;
|
|
|
|
it->remove(val);
|
|
autosave();
|
|
}
|