2015-11-07 17:02:06 -05:00
|
|
|
/*
|
2014-03-12 20:23:34 -04:00
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
2015-11-07 17:02:06 -05:00
|
|
|
*
|
|
|
|
* The struct index_entry is used to associate a database key
|
|
|
|
* with a set of integers, creating an inverted index.
|
2014-03-12 20:23:34 -04:00
|
|
|
*/
|
2015-11-30 10:01:39 -05:00
|
|
|
#ifndef OCARINA_CORE_CONTAINERS_INDEX_H
|
|
|
|
#define OCARINA_CORE_CONTAINERS_INDEX_H
|
2014-03-12 20:23:34 -04:00
|
|
|
|
2015-11-30 09:48:19 -05:00
|
|
|
#include <core/containers/database.h>
|
2015-11-30 09:39:53 -05:00
|
|
|
#include <core/containers/set.h>
|
2014-03-12 20:23:34 -04:00
|
|
|
|
|
|
|
|
2015-11-06 09:59:07 -05:00
|
|
|
struct index_entry {
|
|
|
|
gchar *ie_key;
|
|
|
|
struct set ie_set;
|
|
|
|
struct db_entry ie_dbe;
|
2014-03-12 20:23:34 -04:00
|
|
|
};
|
|
|
|
|
2015-11-06 09:59:07 -05:00
|
|
|
#define INDEX_ENTRY(dbe) ((struct index_entry *)DBE_DATA(dbe))
|
2015-11-04 12:23:00 -05:00
|
|
|
|
2014-03-12 20:23:34 -04:00
|
|
|
|
2015-09-29 16:29:51 -04:00
|
|
|
/* Initialize a database for use as an index. */
|
2015-11-04 12:23:00 -05:00
|
|
|
void index_init(struct database *, const gchar *, bool);
|
2015-09-29 16:11:59 -04:00
|
|
|
|
|
|
|
/* Add a value to an index item with the specified key. */
|
2015-11-07 17:02:06 -05:00
|
|
|
struct index_entry *index_insert(struct database *, const gchar *, unsigned int);
|
2015-09-29 16:11:59 -04:00
|
|
|
|
2015-09-29 16:07:34 -04:00
|
|
|
/* Remove a value from an index item with the specified key. */
|
2015-11-04 12:23:00 -05:00
|
|
|
void index_remove(struct database *, const gchar *, unsigned int);
|
2015-09-29 16:07:34 -04:00
|
|
|
|
2015-09-29 16:40:53 -04:00
|
|
|
/* Called to check if the index has the specified (key, value) pair. */
|
2015-11-04 12:23:00 -05:00
|
|
|
bool index_has(struct database *, const gchar *, unsigned int);
|
2015-09-29 16:40:53 -04:00
|
|
|
|
2015-11-03 10:39:06 -05:00
|
|
|
#ifdef CONFIG_TESTING
|
|
|
|
const struct db_ops *test_index_ops();
|
|
|
|
#endif /* CONFIG_TESTING */
|
2015-11-30 10:01:39 -05:00
|
|
|
#endif /* OCARINA_CORE_CONTAINERS_INDEX_H */
|