ocarina/include/core/index.h

70 lines
1.6 KiB
C++

/**
* Copyright 2014 (c) Anna Schumaker.
*/
#ifndef OCARINA_CORE_INDEX_H
#define OCARINA_CORE_INDEX_H
#include <core/database.h>
extern "C" {
#include <core/set.h>
}
#include <string>
/**
* The index_entry struct is used to associate a specific key with a set of
* integer identifiers. This lets us use a Database as an inverted index.
*/
struct index_entry : public db_entry {
std::string ie_key;
struct set ie_set;
index_entry(); /**< Create an empty IndexEntry. */
/**
* Create an IndexEntry with a specific key.
*
* @param key The key associated with this IndexEntry.
*/
index_entry(const std::string &);
~index_entry();
/**
* Access the key stored by this IndexEntry.
*
* @return IndexEntry::_key.
*/
const std::string primary_key() const;
/**
* Write an IndexEntry to file.
*
* @param file The file to use when writing data.
*/
void write(file &);
/**
* Read an IndexEntry from file.
*
* @param file The file read from.
*/
void read(file &);
};
/* Initialize a database for use as an index. */
void index_init(database<index_entry> *, const gchar *, bool);
/* Add a value to an index item with the specified key. */
index_entry *index_insert(database<index_entry> *, const gchar *, unsigned int);
/* Remove a value from an index item with the specified key. */
void index_remove(database<index_entry> *, const gchar *, unsigned int);
/* Called to check if the index has the specified (key, value) pair. */
bool index_has(database<index_entry> *, const gchar *, unsigned int);
#endif /* OCARINA_CORE_DATABASE_H */