core/filter: Store track pointers directly

I was storing database indexes, but this assumes that database indexes
are constant.  I intend to change this with database defragmentation.

Implements #46: Filter stores a track pointer
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-04-29 09:03:20 -04:00 committed by Anna Schumaker
parent 415bd9731a
commit 29b2b6f6f4
6 changed files with 18 additions and 18 deletions

View File

@ -18,7 +18,7 @@ void filter_deinit()
g_hash_table_destroy(filter_index); g_hash_table_destroy(filter_index);
} }
void filter_add(const gchar *text, unsigned int index) void filter_add(const gchar *text, void *data)
{ {
const gchar *c = g_utf8_next_char(text); const gchar *c = g_utf8_next_char(text);
glong begin, end; glong begin, end;
@ -34,7 +34,7 @@ void filter_add(const gchar *text, unsigned int index)
g_hash_table_insert(filter_index, substr, set); g_hash_table_insert(filter_index, substr, set);
} }
set_insert(set, index); set_insert(set, GPOINTER_TO_UINT(data));
if (g_unichar_isspace(g_utf8_get_char(c))) { if (g_unichar_isspace(g_utf8_get_char(c))) {
c = g_utf8_next_char(c); c = g_utf8_next_char(c);
@ -45,7 +45,7 @@ void filter_add(const gchar *text, unsigned int index)
} }
} }
void filter_remove(const gchar *text, unsigned int index) void filter_remove(const gchar *text, void *data)
{ {
const gchar *c = g_utf8_next_char(text); const gchar *c = g_utf8_next_char(text);
glong begin, end; glong begin, end;
@ -57,7 +57,7 @@ void filter_remove(const gchar *text, unsigned int index)
set = g_hash_table_lookup(filter_index, substr); set = g_hash_table_lookup(filter_index, substr);
if (set) if (set)
set_remove(set, index); set_remove(set, GPOINTER_TO_UINT(data));
if (g_unichar_isspace(g_utf8_get_char(c))) { if (g_unichar_isspace(g_utf8_get_char(c))) {
c = g_utf8_next_char(c); c = g_utf8_next_char(c);

View File

@ -102,9 +102,9 @@ static void track_free(struct db_entry *dbe)
if (track->tr_library) if (track->tr_library)
track->tr_library->li_size--; track->tr_library->li_size--;
filter_remove(track->tr_lower, dbe->dbe_index); filter_remove(track->tr_lower, track);
filter_remove(track->tr_artist->ar_lower, dbe->dbe_index); filter_remove(track->tr_artist->ar_lower, track);
filter_remove(track->tr_album->al_lower, dbe->dbe_index); filter_remove(track->tr_album->al_lower, track);
g_free(track->tr_title); g_free(track->tr_title);
g_free(track->tr_lower); g_free(track->tr_lower);
@ -115,9 +115,9 @@ static void track_setup(struct db_entry *dbe)
{ {
struct track *track = TRACK(dbe); struct track *track = TRACK(dbe);
filter_add(track->tr_lower, dbe->dbe_index); filter_add(track->tr_lower, track);
filter_add(track->tr_artist->ar_lower, dbe->dbe_index); filter_add(track->tr_artist->ar_lower, track);
filter_add(track->tr_album->al_lower, dbe->dbe_index); filter_add(track->tr_album->al_lower, track);
track->tr_library->li_size++; track->tr_library->li_size++;
} }

View File

@ -70,7 +70,7 @@ static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
return TRUE; return TRUE;
track = gui_queue_model_iter_get_track(gq_queue->gq_model, iter); track = gui_queue_model_iter_get_track(gq_queue->gq_model, iter);
return set_has(&gq_queue->gq_visible, track->tr_dbe.dbe_index); return set_has(&gq_queue->gq_visible, GPOINTER_TO_UINT(track));
} }
void __queue_filter(GtkSearchEntry *entry, gpointer data) void __queue_filter(GtkSearchEntry *entry, gpointer data)

View File

@ -16,10 +16,10 @@ void filter_init();
void filter_deinit(); void filter_deinit();
/* Add the input string to the index. */ /* Add the input string to the index. */
void filter_add(const gchar *, unsigned int); void filter_add(const gchar *, void *);
/* Remove the input string from the index. */ /* Remove the input string from the index. */
void filter_remove(const gchar *, unsigned int); void filter_remove(const gchar *, void *);
/* Search for the input string in the index. */ /* Search for the input string in the index. */
void filter_search(const gchar *, struct set *); void filter_search(const gchar *, struct set *);

View File

@ -30,7 +30,7 @@ static void test_filter()
filter_init(); filter_init();
for (i = 0; i < NUM_STRINGS; i++) { for (i = 0; i < NUM_STRINGS; i++) {
filter_add(test_strings[i], i); filter_add(test_strings[i], GUINT_TO_POINTER(i));
} test_loop_passed(); } test_loop_passed();
/* Search for a word! */ /* Search for a word! */
@ -66,7 +66,7 @@ static void test_filter()
test_equal(set_size(&res), 0); test_equal(set_size(&res), 0);
/* Remove a string and search again. */ /* Remove a string and search again. */
filter_remove("hyrule symphony", 1); filter_remove("hyrule symphony", GUINT_TO_POINTER(1));
filter_search("hyrule", &res); filter_search("hyrule", &res);
test_equal(set_size(&res), 2); test_equal(set_size(&res), 2);
test_equal(set_has(&res, 3), (bool)true); /* hyrule field */ test_equal(set_has(&res, 3), (bool)true); /* hyrule field */

View File

@ -135,15 +135,15 @@ static void test_track_filter()
filter_search("Title Theme", &search); filter_search("Title Theme", &search);
test_equal(set_size(&search), 1); test_equal(set_size(&search), 1);
test_equal(set_has(&search, 0), (bool)true); test_equal(set_has(&search, GPOINTER_TO_UINT(track)), (bool)true);
filter_search("Koji Kondo", &search); filter_search("Koji Kondo", &search);
test_equal(set_size(&search), 1); test_equal(set_size(&search), 1);
test_equal(set_has(&search, 0), (bool)true); test_equal(set_has(&search, GPOINTER_TO_UINT(track)), (bool)true);
filter_search("Hyrule Symphony", &search); filter_search("Hyrule Symphony", &search);
test_equal(set_size(&search), 1); test_equal(set_size(&search), 1);
test_equal(set_has(&search, 0), (bool)true); test_equal(set_has(&search, GPOINTER_TO_UINT(track)), (bool)true);
filter_search("No Track", &search); filter_search("No Track", &search);
test_equal(set_size(&search), 0); test_equal(set_size(&search), 0);