core/index: Move index_has() out of the index_entry struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
7dcfc2ba78
commit
025f13ffeb
|
@ -19,11 +19,6 @@ size_t index_entry :: size()
|
|||
return ie_set.size();
|
||||
}
|
||||
|
||||
bool index_entry :: has(unsigned int value)
|
||||
{
|
||||
return ie_set.find(value) != ie_set.end();
|
||||
}
|
||||
|
||||
typename index_entry::iterator index_entry :: begin()
|
||||
{
|
||||
return ie_set.begin();
|
||||
|
@ -81,3 +76,12 @@ void index_remove(Index *index, const gchar *key, unsigned int value)
|
|||
db_autosave(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool index_has(Index *index, const gchar *key, unsigned int value)
|
||||
{
|
||||
index_entry *it = db_get(index, key);
|
||||
|
||||
if (!it)
|
||||
return false;
|
||||
return it->ie_set.find(value) != it->ie_set.end();
|
||||
}
|
||||
|
|
|
@ -100,12 +100,7 @@ void playlist :: init()
|
|||
|
||||
bool playlist :: has(Track *track, const std::string &name)
|
||||
{
|
||||
std::set<unsigned int>::iterator it;
|
||||
index_entry *ent = db_get(&playlist_db, name.c_str());
|
||||
|
||||
if (ent == NULL)
|
||||
return false;
|
||||
return ent->has(track->index());
|
||||
return index_has(&playlist_db, name.c_str(), track->index());
|
||||
}
|
||||
|
||||
void playlist :: add(Track *track, const std::string &name)
|
||||
|
|
|
@ -47,14 +47,6 @@ struct index_entry : public DatabaseEntry {
|
|||
*/
|
||||
size_t size();
|
||||
|
||||
/**
|
||||
* Called to check if a specific value is stored in this IndexEntry.
|
||||
*
|
||||
* @param value The value to find.
|
||||
* @return True if the value was found and false otherwise.
|
||||
*/
|
||||
bool has(unsigned int);
|
||||
|
||||
/**
|
||||
* @return An iterator pointing to the first item in IndexEntry::_values
|
||||
*/
|
||||
|
@ -97,4 +89,7 @@ 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);
|
||||
|
||||
/* Called to check if the index has the specified (key, value) pair. */
|
||||
bool index_has(Index *, const gchar *, unsigned int);
|
||||
|
||||
#endif /* OCARINA_CORE_DATABASE_H */
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
static void test_entry()
|
||||
{
|
||||
index_entry *ie = new index_entry("Link");
|
||||
unsigned int i;
|
||||
struct file f;
|
||||
|
||||
ie->ie_set.insert(0);
|
||||
|
@ -18,10 +17,6 @@ static void test_entry()
|
|||
|
||||
test_equal(ie->primary_key(), "Link");
|
||||
test_equal(ie->size(), 3);
|
||||
for (i = 0; i < 3; i++) {
|
||||
test_loop_equal(ie->has(i), true, i);
|
||||
} test_loop_passed();
|
||||
test_equal(ie->has(3), false);
|
||||
|
||||
file_init(&f, "index_entry", 0);
|
||||
file_open(&f, OPEN_WRITE);
|
||||
|
@ -33,7 +28,6 @@ static void test_entry()
|
|||
ie = new index_entry();
|
||||
test_equal(ie->primary_key(), "");
|
||||
test_equal(ie->size(), 0);
|
||||
test_equal(ie->has(42), false);
|
||||
|
||||
file_open(&f, OPEN_READ);
|
||||
ie->read(f);
|
||||
|
@ -45,10 +39,6 @@ static void test_entry()
|
|||
test_equal(ie->size(), 3);
|
||||
file_close(&f);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
test_loop_equal(ie->has(i), true, i);
|
||||
} test_loop_passed();
|
||||
|
||||
delete ie;
|
||||
}
|
||||
|
||||
|
@ -76,14 +66,12 @@ static void test_stress(unsigned int N)
|
|||
} test_loop_passed();
|
||||
test_equal(index.db_size, 26);
|
||||
|
||||
/* index.has() */
|
||||
/* index_has() */
|
||||
for (c = 'a'; c <= 'z'; c += 4) {
|
||||
key = c;
|
||||
ie = db_find(&index, key.c_str());
|
||||
test_loop_not_equal(ie, NULL, i);
|
||||
for (i = 0; i < N; i++)
|
||||
test_loop_equal(ie->has(i), true, i);
|
||||
test_loop_equal(ie->has(N), false, c - 'a');
|
||||
test_loop_equal(index_has(&index, key.c_str(), i), true, i);
|
||||
test_loop_equal(index_has(&index, key.c_str(), N), false, c - 'a');
|
||||
} test_loop_passed();
|
||||
|
||||
/* index_remove() */
|
||||
|
|
Loading…
Reference in New Issue