core/index: Move index_remove() out of the Index class
And fold IndexEntry :: remove() into index_remove(). Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
46363b1406
commit
a580e5cdb5
|
@ -14,11 +14,6 @@ const std::string index_entry :: primary_key() const
|
||||||
return ie_key;
|
return ie_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void index_entry :: remove(unsigned int value)
|
|
||||||
{
|
|
||||||
ie_set.erase(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t index_entry :: size()
|
size_t index_entry :: size()
|
||||||
{
|
{
|
||||||
return ie_set.size();
|
return ie_set.size();
|
||||||
|
@ -78,11 +73,11 @@ index_entry *index_insert(Index *index, const gchar *key, unsigned int value)
|
||||||
return it;
|
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) {
|
if (it) {
|
||||||
it->remove(value);
|
it->ie_set.erase(value);
|
||||||
::db_autosave(this);
|
db_autosave(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ void playlist :: add(Track *track, const std::string &name)
|
||||||
|
|
||||||
void playlist :: del(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)
|
if (cur_plist == name)
|
||||||
playlist_q.del(track);
|
playlist_q.del(track);
|
||||||
if (name == "Banned")
|
if (name == "Banned")
|
||||||
|
|
|
@ -40,13 +40,6 @@ struct index_entry : public DatabaseEntry {
|
||||||
*/
|
*/
|
||||||
const std::string primary_key() const;
|
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.
|
* 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.
|
* @param autosave True if changes should automatically be saved.
|
||||||
*/
|
*/
|
||||||
Index(const std::string &, bool);
|
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. */
|
/* Add a value to an index item with the specified key. */
|
||||||
index_entry *index_insert(Index *, const gchar *, unsigned int);
|
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 */
|
#endif /* OCARINA_CORE_DATABASE_H */
|
||||||
|
|
|
@ -84,16 +84,16 @@ static void test_stress(unsigned int N)
|
||||||
test_loop_equal(ie->has(N), false, c - 'a');
|
test_loop_equal(ie->has(N), false, c - 'a');
|
||||||
} test_loop_passed();
|
} test_loop_passed();
|
||||||
|
|
||||||
/* index.remove() */
|
/* index_remove() */
|
||||||
for (c = 'a'; c <= 'z'; c += 4) {
|
for (c = 'a'; c <= 'z'; c += 4) {
|
||||||
key = c;
|
key = c;
|
||||||
for (i = 0; i < N; i++)
|
for (i = 0; i < N; i++)
|
||||||
index.remove(key, i);
|
index_remove(&index, key.c_str(), i);
|
||||||
ie = db_find(&index, key.c_str());
|
ie = db_find(&index, key.c_str());
|
||||||
test_loop_not_equal(ie, NULL, c - 'a');
|
test_loop_not_equal(ie, NULL, c - 'a');
|
||||||
test_loop_equal(ie->size(), 0, c - 'a');
|
test_loop_equal(ie->size(), 0, c - 'a');
|
||||||
} test_loop_passed();
|
} test_loop_passed();
|
||||||
index.remove("ZZ", 42);
|
index_remove(&index, "ZZ", 42);
|
||||||
test_equal(index.db_size, 26);
|
test_equal(index.db_size, 26);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue