83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#ifndef OCARINA_CORE_INDEX_H
|
|
#define OCARINA_CORE_INDEX_H
|
|
|
|
#include <core/database.h>
|
|
|
|
#include <set>
|
|
#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 DatabaseEntry {
|
|
std::string ie_key;
|
|
std::set<unsigned int> ie_set;
|
|
|
|
/** Iterator access for our backing std::set */
|
|
typedef typename std::set<unsigned int>::iterator iterator;
|
|
/** Const iterator access for our backing std::set */
|
|
typedef typename std::set<unsigned int>::const_iterator const_iterator;
|
|
|
|
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 &);
|
|
|
|
|
|
/**
|
|
* Access the key stored by this IndexEntry.
|
|
*
|
|
* @return IndexEntry::_key.
|
|
*/
|
|
const std::string primary_key() const;
|
|
|
|
/**
|
|
* @return An iterator pointing to the first item in IndexEntry::_values
|
|
*/
|
|
iterator begin();
|
|
|
|
/**
|
|
* @return An iterator pointing past the last item in IndexEntry::_vaues
|
|
*/
|
|
iterator end();
|
|
|
|
|
|
/**
|
|
* 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 */
|