diff --git a/core/core.c b/core/core.c index c2368e35..c1f85a4c 100644 --- a/core/core.c +++ b/core/core.c @@ -3,7 +3,6 @@ */ #include #include -#include #include #include #include @@ -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(); } diff --git a/core/filter.c b/core/filter.c deleted file mode 100644 index 813b2173..00000000 --- a/core/filter.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2013 (c) Anna Schumaker. - */ -#include -#include - -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; -} diff --git a/core/tags/track.c b/core/tags/track.c index 232c9e3b..d85ad668 100644 --- a/core/tags/track.c +++ b/core/tags/track.c @@ -1,7 +1,6 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include #include #include @@ -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++; } diff --git a/gui/queue.c b/gui/queue.c index db822cd8..ad07af8d 100644 --- a/gui/queue.c +++ b/gui/queue.c @@ -1,7 +1,6 @@ /* * Copyright 2016 (c) Anna Schumaker. */ -#include #include #include #include diff --git a/include/core/filter.h b/include/core/filter.h deleted file mode 100644 index 8ccd9abe..00000000 --- a/include/core/filter.h +++ /dev/null @@ -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 - -/* 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 */ diff --git a/tests/core/.gitignore b/tests/core/.gitignore index 95fce546..8835222e 100644 --- a/tests/core/.gitignore +++ b/tests/core/.gitignore @@ -4,7 +4,6 @@ file date idle database -filter tags/artist tags/album tags/genre diff --git a/tests/core/Sconscript b/tests/core/Sconscript index cae9a3ed..ed59e212 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -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") ] diff --git a/tests/core/filter.c b/tests/core/filter.c deleted file mode 100644 index 524519ef..00000000 --- a/tests/core/filter.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2014 (c) Anna Schumaker. - */ -#include -#include - -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), -); diff --git a/tests/core/playlist.c b/tests/core/playlist.c index d34fbf43..e01fd20a 100644 --- a/tests/core/playlist.c +++ b/tests/core/playlist.c @@ -1,7 +1,6 @@ /* * Copyright 2013 (c) Anna Schumaker. */ -#include #include #include #include @@ -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( diff --git a/tests/core/playlists/artist.c b/tests/core/playlists/artist.c index d8d58bae..b8e6d30d 100644 --- a/tests/core/playlists/artist.c +++ b/tests/core/playlists/artist.c @@ -1,7 +1,6 @@ /* * Copyright 2016 (c) Anna Schumaker. */ -#include #include #include #include @@ -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(); } diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index 0dd5d685..9ed6c1ac 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -1,7 +1,6 @@ /* * Copyright 2016 (c) Anna Schumaker. */ -#include #include #include #include @@ -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(); } diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index e12460e8..ffd6ecac 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -1,7 +1,6 @@ /* * Copyright 2016 (c) Anna Schumaker. */ -#include #include #include #include @@ -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( diff --git a/tests/core/queue.c b/tests/core/queue.c index c363ed54..04d879e8 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -1,7 +1,6 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include #include #include #include @@ -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() diff --git a/tests/core/tags/track.c b/tests/core/tags/track.c index 43557b25..e1c9d675 100644 --- a/tests/core/tags/track.c +++ b/tests/core/tags/track.c @@ -1,7 +1,6 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include #include #include #include @@ -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), ); diff --git a/tests/core/tempq.c b/tests/core/tempq.c index 9faa93ad..1b0b7916 100644 --- a/tests/core/tempq.c +++ b/tests/core/tempq.c @@ -1,7 +1,6 @@ /* * Copyright 2013 (c) Anna Schumaker. */ -#include #include #include #include @@ -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(