ocarina/include/core/index.h

57 lines
1.4 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. */
/**
* 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 &);
};
/* 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);
#ifdef CONFIG_TESTING
const struct db_ops *test_index_ops();
#endif /* CONFIG_TESTING */
#endif /* OCARINA_CORE_DATABASE_H */