ocarina/include/core/index.h

44 lines
1.1 KiB
C++

/**
* Copyright 2014 (c) Anna Schumaker.
*/
#ifndef OCARINA_CORE_INDEX_H
#define OCARINA_CORE_INDEX_H
extern "C" {
#include <core/database.h>
#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 {
gchar *ie_key;
struct set ie_set;
struct db_entry ie_dbe;
};
#define INDEX_ENTRY(dbe) ((struct index_entry *)DBE_DATA(dbe))
/* Initialize a database for use as an index. */
void index_init(struct database *, const gchar *, bool);
/* Add a value to an index item with the specified key. */
index_entry *index_insert(struct database *, const gchar *, unsigned int);
/* Remove a value from an index item with the specified key. */
void index_remove(struct database *, const gchar *, unsigned int);
/* Called to check if the index has the specified (key, value) pair. */
bool index_has(struct database *, const gchar *, unsigned int);
#ifdef CONFIG_TESTING
const struct db_ops *test_index_ops();
#endif /* CONFIG_TESTING */
#endif /* OCARINA_CORE_DATABASE_H */