core/filter: Remove filter.c
It is unused now that I have a token matching system in place. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
2e753b6f52
commit
aead4939c3
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/core.h>
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
|
@ -17,7 +16,6 @@ void core_init(int *argc, char ***argv, struct core_init_data *init)
|
|||
#else
|
||||
idle_init();
|
||||
#endif /* CONFIG_TESTING */
|
||||
filter_init();
|
||||
tags_init();
|
||||
playlist_init(init->playlist_ops);
|
||||
tempq_init(init->tempq_ops);
|
||||
|
@ -30,6 +28,5 @@ void core_deinit()
|
|||
tempq_deinit();
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
idle_deinit();
|
||||
}
|
||||
|
|
134
core/filter.c
134
core/filter.c
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/string.h>
|
||||
|
||||
static GHashTable *filter_index = NULL;
|
||||
|
||||
|
||||
GHashTable *__filter_copy(GHashTable *set)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
GHashTable *res;
|
||||
gpointer data;
|
||||
|
||||
res = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
g_hash_table_iter_init(&iter, set);
|
||||
|
||||
while (g_hash_table_iter_next(&iter, &data, NULL))
|
||||
g_hash_table_add(res, data);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void __filter_inline_intersect(GHashTable *lhs, GHashTable *rhs)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
gpointer data;
|
||||
|
||||
g_hash_table_iter_init(&iter, rhs);
|
||||
while (g_hash_table_iter_next(&iter, &data, NULL)) {
|
||||
if (!g_hash_table_contains(lhs, data))
|
||||
g_hash_table_iter_remove(&iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void filter_init()
|
||||
{
|
||||
filter_index = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
|
||||
(GDestroyNotify)g_hash_table_destroy);
|
||||
}
|
||||
|
||||
void filter_deinit()
|
||||
{
|
||||
g_hash_table_destroy(filter_index);
|
||||
}
|
||||
|
||||
void filter_add(const gchar *text, void *data)
|
||||
{
|
||||
const gchar *c = g_utf8_next_char(text);
|
||||
glong begin, end;
|
||||
GHashTable *set;
|
||||
gchar *substr;
|
||||
|
||||
for (begin = 0, end = 1; end <= g_utf8_strlen(text, -1); end++) {
|
||||
substr = g_utf8_substring(text, begin, end);
|
||||
set = g_hash_table_lookup(filter_index, substr);
|
||||
|
||||
if (!set) {
|
||||
set = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
g_hash_table_insert(filter_index, substr, set);
|
||||
}
|
||||
|
||||
g_hash_table_add(set, data);
|
||||
|
||||
if (g_unichar_isspace(g_utf8_get_char(c))) {
|
||||
c = g_utf8_next_char(c);
|
||||
begin = ++end;
|
||||
}
|
||||
|
||||
c = g_utf8_next_char(c);
|
||||
}
|
||||
}
|
||||
|
||||
void filter_remove(const gchar *text, void *data)
|
||||
{
|
||||
const gchar *c = g_utf8_next_char(text);
|
||||
glong begin, end;
|
||||
GHashTable *set;
|
||||
gchar *substr;
|
||||
|
||||
for (begin = 0, end = 1; end <= g_utf8_strlen(text, -1); end++) {
|
||||
substr = g_utf8_substring(text, begin, end);
|
||||
set = g_hash_table_lookup(filter_index, substr);
|
||||
|
||||
if (set)
|
||||
g_hash_table_remove(set, data);
|
||||
|
||||
if (g_unichar_isspace(g_utf8_get_char(c))) {
|
||||
c = g_utf8_next_char(c);
|
||||
begin = ++end;
|
||||
}
|
||||
|
||||
c = g_utf8_next_char(c);
|
||||
}
|
||||
}
|
||||
|
||||
GHashTable *filter_search(const gchar *text)
|
||||
{
|
||||
gchar *lower = string_lowercase(text);
|
||||
GHashTable *found, *res = NULL;
|
||||
glong begin, end;
|
||||
gchar *c, *substr;
|
||||
|
||||
c = lower;
|
||||
|
||||
for (begin = 0, end = 1; end <= g_utf8_strlen(lower, -1); end++) {
|
||||
c = g_utf8_next_char(c);
|
||||
if ((*c != '\0') && !g_unichar_isspace(g_utf8_get_char(c)))
|
||||
continue;
|
||||
|
||||
substr = g_utf8_substring(lower, begin, end);
|
||||
found = g_hash_table_lookup(filter_index, substr);
|
||||
g_free(substr);
|
||||
|
||||
if (!found) {
|
||||
g_hash_table_destroy(res);
|
||||
res = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!res)
|
||||
res = __filter_copy(found);
|
||||
else
|
||||
__filter_inline_intersect(found, res);
|
||||
|
||||
c = g_utf8_next_char(c);
|
||||
begin = ++end;
|
||||
}
|
||||
|
||||
g_free(lower);
|
||||
return res;
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/string.h>
|
||||
#include <core/tags/track.h>
|
||||
|
||||
|
@ -96,7 +95,6 @@ out:
|
|||
static void track_free(struct db_entry *dbe)
|
||||
{
|
||||
struct track *track = TRACK(dbe);
|
||||
unsigned int i;
|
||||
|
||||
play_count -= track->tr_count;
|
||||
if (track->tr_count == 0)
|
||||
|
@ -104,21 +102,6 @@ static void track_free(struct db_entry *dbe)
|
|||
if (track->tr_library)
|
||||
track->tr_library->li_size--;
|
||||
|
||||
for (i = 0; track->tr_tokens[i]; i++)
|
||||
filter_remove(track->tr_tokens[i], track);
|
||||
for (i = 0; track->tr_alts[i]; i++)
|
||||
filter_remove(track->tr_alts[i], track);
|
||||
|
||||
for (i = 0; track->tr_artist->ar_tokens[i]; i++)
|
||||
filter_remove(track->tr_artist->ar_tokens[i], track);
|
||||
for (i = 0; track->tr_artist->ar_alts[i]; i++)
|
||||
filter_remove(track->tr_artist->ar_alts[i], track);
|
||||
|
||||
for (i = 0; track->tr_album->al_tokens[i]; i++)
|
||||
filter_remove(track->tr_album->al_tokens[i], track);
|
||||
for (i = 0; track->tr_album->al_alts[i]; i++)
|
||||
filter_remove(track->tr_album->al_alts[i], track);
|
||||
|
||||
g_strfreev(track->tr_tokens);
|
||||
g_strfreev(track->tr_alts);
|
||||
g_free(track->tr_title);
|
||||
|
@ -128,23 +111,6 @@ static void track_free(struct db_entry *dbe)
|
|||
static void track_setup(struct db_entry *dbe)
|
||||
{
|
||||
struct track *track = TRACK(dbe);
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; track->tr_tokens[i]; i++)
|
||||
filter_add(track->tr_tokens[i], track);
|
||||
for (i = 0; track->tr_alts[i]; i++)
|
||||
filter_add(track->tr_alts[i], track);
|
||||
|
||||
for (i = 0; track->tr_artist->ar_tokens[i]; i++)
|
||||
filter_add(track->tr_artist->ar_tokens[i], track);
|
||||
for (i = 0; track->tr_artist->ar_alts[i]; i++)
|
||||
filter_add(track->tr_artist->ar_alts[i], track);
|
||||
|
||||
for (i = 0; track->tr_album->al_tokens[i]; i++)
|
||||
filter_add(track->tr_album->al_tokens[i], track);
|
||||
for (i = 0; track->tr_album->al_alts[i]; i++)
|
||||
filter_add(track->tr_album->al_alts[i], track);
|
||||
|
||||
track->tr_library->li_size++;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/string.h>
|
||||
#include <gui/builder.h>
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*
|
||||
* The filter layer is used to search for a subset of
|
||||
* songs based on an input string.
|
||||
*/
|
||||
#ifndef OCARINA_CORE_FILTER_H
|
||||
#define OCARINA_CORE_FILTER_H
|
||||
#include <glib.h>
|
||||
|
||||
/* Called to initialize the filter index. */
|
||||
void filter_init();
|
||||
|
||||
/* Called to clean up the filter index. */
|
||||
void filter_deinit();
|
||||
|
||||
/* Add the input string to the index. */
|
||||
void filter_add(const gchar *, void *);
|
||||
|
||||
/* Remove the input string from the index. */
|
||||
void filter_remove(const gchar *, void *);
|
||||
|
||||
/* Search for the input string in the index. */
|
||||
GHashTable *filter_search(const gchar *);
|
||||
|
||||
#endif /* OCARINA_CORE_FILTER_H */
|
|
@ -4,7 +4,6 @@ file
|
|||
date
|
||||
idle
|
||||
database
|
||||
filter
|
||||
tags/artist
|
||||
tags/album
|
||||
tags/genre
|
||||
|
|
|
@ -30,7 +30,6 @@ res += [ CoreTest("file") ]
|
|||
res += [ CoreTest("date") ]
|
||||
res += [ CoreTest("idle") ]
|
||||
res += [ CoreTest("database") ]
|
||||
res += [ CoreTest("filter") ]
|
||||
|
||||
res += SConscript("tags/Sconscript")
|
||||
res += [ CoreTest("queue") ]
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
const gchar *test_strings[] = {
|
||||
/* 0 */ "koji kondo",
|
||||
/* 1 */ "hyrule symphony",
|
||||
/* 2 */ "kokiri forest",
|
||||
/* 3 */ "hyrule field",
|
||||
/* 4 */ "hyrule castle",
|
||||
/* 5 */ "lon lon ranch",
|
||||
/* 6 */ "kakariko village",
|
||||
/* 7 */ "death mountain",
|
||||
/* 8 */ "zoras domain",
|
||||
/* 9 */ "gerudo valley",
|
||||
/* 10 */ "ganondorf",
|
||||
/* 11 */ "princess zelda",
|
||||
/* 12 */ "ocarina medley",
|
||||
/* 13 */ "the legend of zelda medley",
|
||||
};
|
||||
|
||||
#define NUM_STRINGS (sizeof(test_strings) / sizeof(gchar *))
|
||||
|
||||
static void test_filter()
|
||||
{
|
||||
GHashTable *res;
|
||||
unsigned int i;
|
||||
|
||||
filter_init();
|
||||
for (i = 0; i < NUM_STRINGS; i++) {
|
||||
filter_add(test_strings[i], GUINT_TO_POINTER(i));
|
||||
} test_loop_passed();
|
||||
|
||||
/* Search for a word! */
|
||||
res = filter_search("hyrule");
|
||||
test_equal(g_hash_table_size(res), 3);
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(1)), true); /* hyrule symphony */
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(3)), true); /* hyrule field */
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(4)), true); /* hyrule castle */
|
||||
g_hash_table_destroy(res);
|
||||
|
||||
/* A second search should clear the set. */
|
||||
res = filter_search("zelda");
|
||||
test_equal(g_hash_table_size(res), 2);
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(11)), true); /* princess zelda */
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(13)), true); /* the legend of zelda medley */
|
||||
g_hash_table_destroy(res);
|
||||
|
||||
/* Partial word search. */
|
||||
res = filter_search("ko");
|
||||
test_equal(g_hash_table_size(res), 2);
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(0)), true); /* koji kondo */
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(2)), true); /* kokiri forest */
|
||||
g_hash_table_destroy(res);
|
||||
|
||||
/* Multiple word search. */
|
||||
res = filter_search("hyrule field");
|
||||
test_equal(g_hash_table_size(res), 1);
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(3)), true); /* hyrule field */
|
||||
g_hash_table_destroy(res);
|
||||
|
||||
/* Search for unknown word. */
|
||||
res = filter_search("field termina");
|
||||
test_equal((void *)res, NULL);
|
||||
|
||||
/* Search for empty string. */
|
||||
res = filter_search("");
|
||||
test_equal((void *)res, NULL);
|
||||
|
||||
/* Remove a string and search again. */
|
||||
filter_remove("hyrule symphony", GUINT_TO_POINTER(1));
|
||||
res = filter_search("hyrule");
|
||||
test_equal(g_hash_table_size(res), 2);
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(3)), true); /* hyrule field */
|
||||
test_equal(g_hash_table_contains(res, GUINT_TO_POINTER(4)), true); /* hyrule castle */
|
||||
g_hash_table_destroy(res);
|
||||
|
||||
filter_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Filter", test_filter),
|
||||
);
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
|
@ -14,7 +13,6 @@ static void test_init()
|
|||
GSList *list;
|
||||
|
||||
idle_init_sync();
|
||||
filter_init();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
|
@ -109,7 +107,6 @@ static void test_deinit()
|
|||
{
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlists/artist.h>
|
||||
#include <core/tags/artist.h>
|
||||
|
@ -17,7 +16,6 @@ void test_artist()
|
|||
struct artist *artist;
|
||||
|
||||
idle_init_sync();
|
||||
filter_init();
|
||||
tags_init();
|
||||
while (idle_run_task()) {};
|
||||
|
||||
|
@ -47,7 +45,6 @@ void test_artist()
|
|||
test_equal(artist->ar_playlist, NULL);
|
||||
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
idle_deinit();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlists/library.h>
|
||||
#include <core/playlists/system.h>
|
||||
|
@ -15,7 +14,6 @@ void test_library()
|
|||
struct library *library;
|
||||
|
||||
idle_init_sync();
|
||||
filter_init();
|
||||
tags_init();
|
||||
pl_system_init(NULL);
|
||||
pl_library_init(NULL);
|
||||
|
@ -101,7 +99,6 @@ void test_library()
|
|||
pl_library_deinit();
|
||||
pl_system_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
idle_deinit();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlists/system.h>
|
||||
#include <core/tags/tags.h>
|
||||
|
@ -61,7 +60,6 @@ static void test_init()
|
|||
struct library *library;
|
||||
|
||||
idle_init_sync();
|
||||
filter_init();
|
||||
tags_init();
|
||||
pl_system_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
|
@ -272,6 +270,8 @@ static void test_least_played()
|
|||
__test_playlist_unhide_track("Least Played", least, 1, true, false);
|
||||
|
||||
pl_system_deinit();
|
||||
tags_deinit();
|
||||
idle_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/queue.h>
|
||||
#include <core/tags/tags.h>
|
||||
#include <tests/test.h>
|
||||
|
@ -82,7 +81,6 @@ static void __test_init_core()
|
|||
{
|
||||
struct library *library;
|
||||
|
||||
filter_init();
|
||||
tags_init();
|
||||
|
||||
library = library_find("tests/Music");
|
||||
|
@ -105,7 +103,6 @@ static void __test_init_core()
|
|||
static void __test_deinit_core()
|
||||
{
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
}
|
||||
|
||||
static void test_init()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/string.h>
|
||||
#include <core/tags/tags.h>
|
||||
|
@ -77,7 +76,6 @@ static void test_track()
|
|||
|
||||
setlocale(LC_TIME, "C");
|
||||
idle_init_sync();
|
||||
filter_init();
|
||||
tags_init();
|
||||
file_init(&f, "track_tag", 0, 0);
|
||||
while (idle_run_task()) {}
|
||||
|
@ -131,38 +129,6 @@ static void test_track()
|
|||
g_free(date);
|
||||
}
|
||||
|
||||
static void test_track_filter()
|
||||
{
|
||||
const struct db_ops *track_ops = test_track_ops();
|
||||
struct track *track;
|
||||
GHashTable *search;
|
||||
|
||||
track = test_alloc("0/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
track->tr_dbe.dbe_index = 0;
|
||||
track_ops->dbe_setup(&track->tr_dbe);
|
||||
|
||||
search = filter_search("Title Theme");
|
||||
test_equal(g_hash_table_size(search), 1);
|
||||
test_equal(g_hash_table_contains(search, track), true);
|
||||
g_hash_table_destroy(search);
|
||||
|
||||
search = filter_search("Koji Kondo");
|
||||
test_equal(g_hash_table_size(search), 1);
|
||||
test_equal(g_hash_table_contains(search, track), true);
|
||||
g_hash_table_destroy(search);
|
||||
|
||||
search = filter_search("Hyrule Symphony");
|
||||
test_equal(g_hash_table_size(search), 1);
|
||||
test_equal(g_hash_table_contains(search, track), true);
|
||||
g_hash_table_destroy(search);
|
||||
|
||||
search = filter_search("No Track");
|
||||
test_equal((void *)search, NULL);
|
||||
|
||||
g_free(track->tr_path);
|
||||
track_ops->dbe_free(&track->tr_dbe);
|
||||
}
|
||||
|
||||
static void test_track_compare()
|
||||
{
|
||||
const struct db_ops *track_ops = test_track_ops();
|
||||
|
@ -322,12 +288,11 @@ static void test_track_db()
|
|||
test_equal(track_db_get()->db_size, 0);
|
||||
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
idle_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Track Tag", test_track),
|
||||
UNIT_TEST("Track Filter", test_track_filter),
|
||||
UNIT_TEST("Track Comparison", test_track_compare),
|
||||
UNIT_TEST("Track Database", test_track_db),
|
||||
);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
|
@ -12,7 +11,6 @@
|
|||
static void test_init()
|
||||
{
|
||||
idle_init_sync();
|
||||
filter_init();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
|
||||
|
@ -159,7 +157,6 @@ static void test_next()
|
|||
tempq_deinit();
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
|
|
Loading…
Reference in New Issue