From a580e5cdb5700e0ab8e38f77e196f2712c3fc14a Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 29 Sep 2015 16:07:34 -0400 Subject: [PATCH] core/index: Move index_remove() out of the Index class And fold IndexEntry :: remove() into index_remove(). Signed-off-by: Anna Schumaker --- core/index.cpp | 13 ++++--------- core/playlist.cpp | 2 +- include/core/index.h | 19 +++---------------- tests/core/index.cpp | 6 +++--- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/core/index.cpp b/core/index.cpp index 5fc65862..2933ffc3 100644 --- a/core/index.cpp +++ b/core/index.cpp @@ -14,11 +14,6 @@ const std::string index_entry :: primary_key() const return ie_key; } -void index_entry :: remove(unsigned int value) -{ - ie_set.erase(value); -} - size_t index_entry :: size() { return ie_set.size(); @@ -78,11 +73,11 @@ index_entry *index_insert(Index *index, const gchar *key, unsigned int value) return it; } -void Index :: remove(const std::string &key, unsigned int value) +void index_remove(Index *index, const gchar *key, unsigned int value) { - index_entry *it = db_get(this, key.c_str()); + index_entry *it = db_get(index, key); if (it) { - it->remove(value); - ::db_autosave(this); + it->ie_set.erase(value); + db_autosave(index); } } diff --git a/core/playlist.cpp b/core/playlist.cpp index 60aca2c0..ea916f72 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -123,7 +123,7 @@ void playlist :: add(Track *track, const std::string &name) void playlist :: del(Track *track, const std::string &name) { - playlist_db.remove(name, track->index()); + index_remove(&playlist_db, name.c_str(), track->index()); if (cur_plist == name) playlist_q.del(track); if (name == "Banned") diff --git a/include/core/index.h b/include/core/index.h index 85d28694..7580cc63 100644 --- a/include/core/index.h +++ b/include/core/index.h @@ -40,13 +40,6 @@ struct index_entry : public DatabaseEntry { */ const std::string primary_key() const; - /** - * Remove a value from this IndexEntry. - * - * @param value The value to remove. - */ - void remove(unsigned int); - /** * Called to find the number of values in our backing std::set. * @@ -103,19 +96,13 @@ public: * @param autosave True if changes should automatically be saved. */ Index(const std::string &, bool); - - /** - * Remove value from the IndexEntry corresponding to key. The - * IndexEntry will not be removed even if it has 0 values left. - * - * @param key Key associated with the value to be removed. - * @param value Value to remove from the index. - */ - void remove(const std::string &, unsigned int); }; /* Add a value to an index item with the specified key. */ index_entry *index_insert(Index *, const gchar *, unsigned int); +/* Remove a value from an index item with the specified key. */ +void index_remove(Index *, const gchar *, unsigned int); + #endif /* OCARINA_CORE_DATABASE_H */ diff --git a/tests/core/index.cpp b/tests/core/index.cpp index 306fbf5d..6ac586da 100644 --- a/tests/core/index.cpp +++ b/tests/core/index.cpp @@ -84,16 +84,16 @@ static void test_stress(unsigned int N) test_loop_equal(ie->has(N), false, c - 'a'); } test_loop_passed(); - /* index.remove() */ + /* index_remove() */ for (c = 'a'; c <= 'z'; c += 4) { key = c; for (i = 0; i < N; i++) - index.remove(key, i); + index_remove(&index, key.c_str(), i); ie = db_find(&index, key.c_str()); test_loop_not_equal(ie, NULL, c - 'a'); test_loop_equal(ie->size(), 0, c - 'a'); } test_loop_passed(); - index.remove("ZZ", 42); + index_remove(&index, "ZZ", 42); test_equal(index.db_size, 26); }