core/filter: Implement copy and intersect directly

I intend to remove the set class, so we still need a way to handle
filter results.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-04-29 10:17:54 -04:00 committed by Anna Schumaker
parent 29b2b6f6f4
commit 63b46b6161
1 changed files with 25 additions and 2 deletions

View File

@ -7,6 +7,29 @@
static GHashTable *filter_index = NULL;
void __filter_copy(const struct set *lhs, struct set *rhs)
{
GHashTableIter iter;
gpointer data;
g_hash_table_iter_init(&iter, lhs->s_set);
while (g_hash_table_iter_next(&iter, &data, NULL))
set_insert(rhs, GPOINTER_TO_UINT(data));
}
void __filter_inline_intersect(const struct set *lhs, struct set *rhs)
{
GHashTableIter iter;
gpointer data;
g_hash_table_iter_init(&iter, rhs->s_set);
while (g_hash_table_iter_next(&iter, &data, NULL)) {
if (!set_has(lhs, GPOINTER_TO_UINT(data)))
g_hash_table_iter_remove(&iter);
}
}
void filter_init()
{
filter_index = g_hash_table_new_full(g_str_hash, g_str_equal,
@ -93,9 +116,9 @@ void filter_search(const gchar *text, struct set *res)
}
if (begin == 0)
set_copy(found, res);
__filter_copy(found, res);
else
set_inline_intersect(found, res);
__filter_inline_intersect(found, res);
c = g_utf8_next_char(c);
begin = ++end;