IndexEntry: Make _values private
I don't want anybody outside of the IndexEntry class to modify the values in this container. This patch makes it private and provides iterator access instead. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
dcb79dceed
commit
2b71ecbeca
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <core/filter.h>
|
||||
#include <core/index.h>
|
||||
#include <core/print.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
|
@ -91,22 +92,23 @@ std::string filter :: add(const std::string &text, unsigned int track_id)
|
|||
return reassemble_text(parsed);
|
||||
}
|
||||
|
||||
static void do_set_intersection(std::set<unsigned int> &a,
|
||||
std::set<unsigned int> &b,
|
||||
static void do_set_intersection(IndexEntry *entry,
|
||||
std::set<unsigned int> &res)
|
||||
{
|
||||
set_intersection(a.begin(), a.end(), b.begin(), b.end(),
|
||||
std::inserter<std::set<unsigned int> >(res, res.begin()));
|
||||
std::set<unsigned int> tmp;
|
||||
|
||||
set_intersection(entry->begin(), entry->end(), res.begin(), res.end(),
|
||||
std::inserter<std::set<unsigned int> >(tmp, tmp.begin()));
|
||||
res.swap(tmp);
|
||||
}
|
||||
|
||||
static void find_intersection(std::string &text, std::set<unsigned int> &res)
|
||||
{
|
||||
std::set<unsigned int> tmp;
|
||||
IndexEntry *it = filter_index.find(text);
|
||||
|
||||
if (it)
|
||||
do_set_intersection(res, it->_values, tmp);
|
||||
res.swap(tmp);
|
||||
do_set_intersection(it, res);
|
||||
else
|
||||
res.clear();
|
||||
}
|
||||
|
||||
void filter :: search(const std::string &text, std::set<unsigned int> &res)
|
||||
|
@ -117,6 +119,7 @@ void filter :: search(const std::string &text, std::set<unsigned int> &res)
|
|||
|
||||
res.clear();
|
||||
parse_text(text, parsed);
|
||||
|
||||
if (parsed.size() == 0)
|
||||
return;
|
||||
|
||||
|
@ -124,7 +127,7 @@ void filter :: search(const std::string &text, std::set<unsigned int> &res)
|
|||
found = filter_index.find(*it);
|
||||
if (!found)
|
||||
return;
|
||||
res = found->_values;
|
||||
std::copy(found->begin(), found->end(), std::inserter(res, res.begin()));
|
||||
|
||||
for (it++; it != parsed.end(); it++)
|
||||
find_intersection(*it, res);
|
||||
|
|
|
@ -25,6 +25,26 @@ void IndexEntry :: remove(unsigned int value)
|
|||
_values.erase(value);
|
||||
}
|
||||
|
||||
size_t IndexEntry :: size()
|
||||
{
|
||||
return _values.size();
|
||||
}
|
||||
|
||||
bool IndexEntry :: has(unsigned int value)
|
||||
{
|
||||
return _values.find(value) != _values.end();
|
||||
}
|
||||
|
||||
typename IndexEntry::iterator IndexEntry :: begin()
|
||||
{
|
||||
return _values.begin();
|
||||
}
|
||||
|
||||
typename IndexEntry::iterator IndexEntry :: end()
|
||||
{
|
||||
return _values.end();
|
||||
}
|
||||
|
||||
void IndexEntry :: write(File &file)
|
||||
{
|
||||
std::set<unsigned int>::iterator it;
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
while (size() > 0)
|
||||
del((unsigned)0);
|
||||
|
||||
for (it = ent->_values.begin(); it != ent->_values.end(); it++)
|
||||
for (it = ent->begin(); it != ent->end(); it++)
|
||||
add(tagdb :: lookup(*it));
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ void playlist :: init()
|
|||
if (!ent)
|
||||
return;
|
||||
|
||||
for (it = ent->_values.begin(); it != ent->_values.end(); it++)
|
||||
for (it = ent->begin(); it != ent->end(); it++)
|
||||
library :: get_queue()->del(tagdb :: lookup(*it));
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,7 @@ bool playlist :: has(Track *track, const std::string &name)
|
|||
|
||||
if (ent == NULL)
|
||||
return false;
|
||||
|
||||
it = ent->_values.find(track->index());
|
||||
return it != ent->_values.end();
|
||||
return ent->has(track->index());
|
||||
}
|
||||
|
||||
void playlist :: add(Track *track, const std::string &name)
|
||||
|
|
|
@ -18,11 +18,15 @@
|
|||
class IndexEntry : public DatabaseEntry {
|
||||
private:
|
||||
std::string _key; /**< The term stored by this IndexEntry. */
|
||||
|
||||
public:
|
||||
std::set<unsigned int> _values; /**< Integers representing strings that
|
||||
contain this term. */
|
||||
|
||||
public:
|
||||
/** Iterator access for our backing std::set */
|
||||
typedef typename std::set<unsigned int>::iterator iterator;
|
||||
/** Const iterator access for our backing std::set */
|
||||
typedef typename std::set<unsigned int>::const_iterator const_iterator;
|
||||
|
||||
IndexEntry(); /**< Create an empty IndexEntry. */
|
||||
|
||||
/**
|
||||
|
@ -54,6 +58,31 @@ public:
|
|||
*/
|
||||
void remove(unsigned int);
|
||||
|
||||
/**
|
||||
* Called to find the number of values in our backing std::set.
|
||||
*
|
||||
* @return IndexEntry::_values.size()
|
||||
*/
|
||||
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
|
||||
*/
|
||||
iterator begin();
|
||||
|
||||
/**
|
||||
* @return An iterator pointing past the last item in IndexEntry::_vaues
|
||||
*/
|
||||
iterator end();
|
||||
|
||||
|
||||
/**
|
||||
* Write an IndexEntry to file.
|
||||
|
|
|
@ -57,7 +57,7 @@ static void remove_banned_tracks()
|
|||
if (!ent)
|
||||
return;
|
||||
|
||||
for (it = ent->_values.begin(); it != ent->_values.end(); it++)
|
||||
for (it = ent->begin(); it != ent->end(); it++)
|
||||
library :: get_queue()->del(tagdb :: lookup(*it));
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ static void test_single_item()
|
|||
|
||||
test_not_equal(it, IDX_NULL);
|
||||
test_equal(index.size(), (unsigned)1);
|
||||
test_equal(it->_values.size(), (size_t)1);
|
||||
test_equal(*(it->_values.begin()), (unsigned)0);
|
||||
test_equal(it->size(), (size_t)1);
|
||||
test_equal(*(it->begin()), (unsigned)0);
|
||||
|
||||
index.remove("a", 0);
|
||||
test_equal(index.size(), (unsigned)1);
|
||||
test_equal(it->_values.size(), (size_t)0);
|
||||
test_equal(it->size(), (size_t)0);
|
||||
}
|
||||
|
||||
static void test_insertion(struct TestArgs *args)
|
||||
|
@ -80,7 +80,7 @@ static void test_insertion(struct TestArgs *args)
|
|||
check_equal(it, IDX_NULL);
|
||||
else {
|
||||
check_not_equal(it, IDX_NULL);
|
||||
check_equal(it->_values.size(), (size_t)args->n);
|
||||
check_equal(it->size(), (size_t)args->n);
|
||||
}
|
||||
}
|
||||
test :: success();
|
||||
|
@ -102,7 +102,7 @@ static void test_removal(struct TestArgs *args)
|
|||
check_equal(it, IDX_NULL);
|
||||
else {
|
||||
check_not_equal(it, IDX_NULL);
|
||||
check_equal(it->_values.size(), (size_t)0);
|
||||
check_equal(it->size(), (size_t)0);
|
||||
}
|
||||
}
|
||||
test :: success();
|
||||
|
@ -135,7 +135,7 @@ static void test_saving(struct TestArgs *args)
|
|||
} else {
|
||||
check_not_equal(it1, IDX_NULL);
|
||||
check_not_equal(it2, IDX_NULL);
|
||||
check_equal(it1->_values.size(), it2->_values.size());
|
||||
check_equal(it1->size(), it2->size());
|
||||
}
|
||||
}
|
||||
test :: success();
|
||||
|
|
|
@ -27,10 +27,10 @@ static void test_init()
|
|||
playlist :: init();
|
||||
|
||||
ent = playlist :: get_tracks("Banned");
|
||||
test_equal(ent->_values.size(), (size_t)4);
|
||||
test_equal(ent->size(), (size_t)4);
|
||||
test_equal(library :: get_queue()->size(), (unsigned)20);
|
||||
ent = playlist :: get_tracks("Favorites");
|
||||
test_equal(ent->_values.size(), (size_t)8);
|
||||
test_equal(ent->size(), (size_t)8);
|
||||
ent = playlist :: get_tracks("No Such Playlist");
|
||||
test_equal(ent, IDX_NULL);
|
||||
}
|
||||
|
@ -54,14 +54,14 @@ static void test_add()
|
|||
|
||||
playlist :: add(tagdb :: lookup(5), "Banned");
|
||||
ent = playlist :: get_tracks("Banned");
|
||||
test_equal(ent->_values.size(), (size_t)5);
|
||||
test_equal(ent->size(), (size_t)5);
|
||||
test_equal(q->size(), (unsigned)8);
|
||||
test_equal(l->size(), (unsigned)19);
|
||||
|
||||
playlist :: add(tagdb :: lookup(16), "Favorites");
|
||||
playlist :: add(tagdb :: lookup(5), "Favorites");
|
||||
ent = playlist :: get_tracks("Favorites");
|
||||
test_equal(ent->_values.size(), (size_t)9);
|
||||
test_equal(ent->size(), (size_t)9);
|
||||
test_equal(q->size(), (unsigned)9);
|
||||
|
||||
playlist :: add(tagdb :: lookup(6), "No Playlist");
|
||||
|
@ -76,13 +76,13 @@ static void test_delete()
|
|||
|
||||
playlist :: del(tagdb :: lookup(5), "Banned");
|
||||
ent = playlist :: get_tracks("Banned");
|
||||
test_equal(ent->_values.size(), (size_t)4);
|
||||
test_equal(ent->size(), (size_t)4);
|
||||
test_equal(q->size(), (unsigned)9);
|
||||
test_equal(l->size(), (unsigned)20);
|
||||
|
||||
playlist :: del(tagdb :: lookup(5), "Favorites");
|
||||
ent = playlist :: get_tracks("Favorites");
|
||||
test_equal(ent->_values.size(), (size_t)8);
|
||||
test_equal(ent->size(), (size_t)8);
|
||||
test_equal(q->size(), (unsigned)8);
|
||||
|
||||
playlist :: del(tagdb :: lookup(6), "No Playlist");
|
||||
|
|
Loading…
Reference in New Issue