ocarina/include/core/containers/index.h

39 lines
1.1 KiB
C

/*
* Copyright 2014 (c) Anna Schumaker.
*
* The struct index_entry is used to associate a database key
* with a set of integers, creating an inverted index.
*/
#ifndef OCARINA_CORE_CONTAINERS_INDEX_H
#define OCARINA_CORE_CONTAINERS_INDEX_H
#include <core/containers/database.h>
#include <core/containers/set.h>
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. */
struct 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_CONTAINERS_INDEX_H */