core/index: Convert IndexEntry class to a struct
In addition, I added the prefix "ie_" to all member names. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
1244531f0d
commit
a91326551f
|
@ -29,7 +29,7 @@ const std::string filter :: add(const std::string &text, unsigned int index)
|
|||
return lc;
|
||||
}
|
||||
|
||||
static void do_set_intersection(IndexEntry *entry,
|
||||
static void do_set_intersection(index_entry *entry,
|
||||
std::set<unsigned int> &res)
|
||||
{
|
||||
std::set<unsigned int> tmp;
|
||||
|
@ -44,7 +44,7 @@ void filter :: search(const std::string &text, std::set<unsigned int> &res)
|
|||
gchar *g_lc = string_lowercase(text.c_str());
|
||||
const std::string lc = g_lc;
|
||||
size_t begin = 0, end;
|
||||
IndexEntry *found;
|
||||
index_entry *found;
|
||||
|
||||
g_free(g_lc);
|
||||
res.clear();
|
||||
|
|
|
@ -4,61 +4,61 @@
|
|||
#include <core/index.h>
|
||||
|
||||
|
||||
IndexEntry :: IndexEntry() {}
|
||||
IndexEntry :: IndexEntry(const std::string &key)
|
||||
: _key(key)
|
||||
index_entry :: index_entry() {}
|
||||
index_entry :: index_entry(const std::string &key)
|
||||
: ie_key(key)
|
||||
{}
|
||||
|
||||
const std::string IndexEntry :: primary_key() const
|
||||
const std::string index_entry :: primary_key() const
|
||||
{
|
||||
return _key;
|
||||
return ie_key;
|
||||
}
|
||||
|
||||
void IndexEntry :: insert(unsigned int value)
|
||||
void index_entry :: insert(unsigned int value)
|
||||
{
|
||||
_values.insert(value);
|
||||
ie_set.insert(value);
|
||||
}
|
||||
|
||||
void IndexEntry :: remove(unsigned int value)
|
||||
void index_entry :: remove(unsigned int value)
|
||||
{
|
||||
_values.erase(value);
|
||||
ie_set.erase(value);
|
||||
}
|
||||
|
||||
size_t IndexEntry :: size()
|
||||
size_t index_entry :: size()
|
||||
{
|
||||
return _values.size();
|
||||
return ie_set.size();
|
||||
}
|
||||
|
||||
bool IndexEntry :: has(unsigned int value)
|
||||
bool index_entry :: has(unsigned int value)
|
||||
{
|
||||
return _values.find(value) != _values.end();
|
||||
return ie_set.find(value) != ie_set.end();
|
||||
}
|
||||
|
||||
typename IndexEntry::iterator IndexEntry :: begin()
|
||||
typename index_entry::iterator index_entry :: begin()
|
||||
{
|
||||
return _values.begin();
|
||||
return ie_set.begin();
|
||||
}
|
||||
|
||||
typename IndexEntry::iterator IndexEntry :: end()
|
||||
typename index_entry::iterator index_entry :: end()
|
||||
{
|
||||
return _values.end();
|
||||
return ie_set.end();
|
||||
}
|
||||
|
||||
void IndexEntry :: write(file &file)
|
||||
void index_entry :: write(file &file)
|
||||
{
|
||||
std::set<unsigned int>::iterator it;
|
||||
file_writef(&file, "%s\n%zu ", _key.c_str(), _values.size());
|
||||
for (it = _values.begin(); it != _values.end(); it++)
|
||||
file_writef(&file, "%s\n%zu ", ie_key.c_str(), ie_set.size());
|
||||
for (it = ie_set.begin(); it != ie_set.end(); it++)
|
||||
file_writef(&file, "%u ", *it);
|
||||
}
|
||||
|
||||
void IndexEntry :: read(file &file)
|
||||
void index_entry :: read(file &file)
|
||||
{
|
||||
unsigned int num, val;
|
||||
gchar *key = file_readl(&file);
|
||||
|
||||
file_readf(&file, "%u ", &num);
|
||||
_key = key;
|
||||
ie_key = key;
|
||||
g_free(key);
|
||||
|
||||
for (unsigned int i = 0; i < num; i++) {
|
||||
|
@ -76,14 +76,14 @@ Index :: Index(const std::string &filepath, bool autosave)
|
|||
|
||||
void Index :: insert(const std::string &key, unsigned int value)
|
||||
{
|
||||
IndexEntry *it = db_find(this, key.c_str());
|
||||
index_entry *it = db_find(this, key.c_str());
|
||||
it->insert(value);
|
||||
::db_autosave(this);
|
||||
}
|
||||
|
||||
void Index :: remove(const std::string &key, unsigned int value)
|
||||
{
|
||||
IndexEntry *it = db_get(this, key.c_str());
|
||||
index_entry *it = db_get(this, key.c_str());
|
||||
if (it) {
|
||||
it->remove(value);
|
||||
::db_autosave(this);
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
del((unsigned)0);
|
||||
}
|
||||
|
||||
void fill(IndexEntry *ent)
|
||||
void fill(index_entry *ent)
|
||||
{
|
||||
std::set<unsigned int>::iterator it;
|
||||
|
||||
|
@ -89,7 +89,7 @@ void playlist :: init()
|
|||
|
||||
db_load(&playlist_db);
|
||||
|
||||
IndexEntry *ent = get_tracks("Banned");
|
||||
index_entry *ent = get_tracks("Banned");
|
||||
if (!ent)
|
||||
return;
|
||||
|
||||
|
@ -100,7 +100,7 @@ void playlist :: init()
|
|||
bool playlist :: has(Track *track, const std::string &name)
|
||||
{
|
||||
std::set<unsigned int>::iterator it;
|
||||
IndexEntry *ent = db_get(&playlist_db, name.c_str());
|
||||
index_entry *ent = db_get(&playlist_db, name.c_str());
|
||||
|
||||
if (ent == NULL)
|
||||
return false;
|
||||
|
@ -132,7 +132,7 @@ void playlist :: del(Track *track, const std::string &name)
|
|||
|
||||
void playlist :: select(const std::string &name)
|
||||
{
|
||||
IndexEntry *ent = db_get(&playlist_db, name.c_str());
|
||||
index_entry *ent = db_get(&playlist_db, name.c_str());
|
||||
|
||||
if (ent != NULL)
|
||||
playlist_q.fill(ent);
|
||||
|
@ -142,7 +142,7 @@ void playlist :: select(const std::string &name)
|
|||
cur_plist = name;
|
||||
}
|
||||
|
||||
IndexEntry *playlist :: get_tracks(const std::string &name)
|
||||
index_entry *playlist :: get_tracks(const std::string &name)
|
||||
{
|
||||
return db_get(&playlist_db, name.c_str());
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ void update_paths()
|
|||
static void remove_banned_tracks()
|
||||
{
|
||||
std::set<unsigned int>::iterator it;
|
||||
IndexEntry *ent = playlist :: get_tracks("Banned");
|
||||
index_entry *ent = playlist :: get_tracks("Banned");
|
||||
|
||||
if (!ent)
|
||||
return;
|
||||
|
|
|
@ -11,29 +11,26 @@
|
|||
|
||||
|
||||
/**
|
||||
* The IndexEntry class is used to associate a specific key with a set of
|
||||
* The index_entry struct is used to associate a specific key with a set of
|
||||
* integer identifiers. This lets us use a Database as an inverted index.
|
||||
*/
|
||||
class IndexEntry : public DatabaseEntry {
|
||||
private:
|
||||
std::string _key; /**< The term stored by this IndexEntry. */
|
||||
std::set<unsigned int> _values; /**< Integers representing strings that
|
||||
contain this term. */
|
||||
struct index_entry : public DatabaseEntry {
|
||||
std::string ie_key;
|
||||
std::set<unsigned int> ie_set;
|
||||
|
||||
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. */
|
||||
index_entry(); /**< Create an empty IndexEntry. */
|
||||
|
||||
/**
|
||||
* Create an IndexEntry with a specific key.
|
||||
*
|
||||
* @param key The key associated with this IndexEntry.
|
||||
*/
|
||||
IndexEntry(const std::string &);
|
||||
index_entry(const std::string &);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -103,7 +100,7 @@ public:
|
|||
* An Index is a special Database for mapping std::strings to a std::set of
|
||||
* integer identifiers.
|
||||
*/
|
||||
class Index : public database<IndexEntry> {
|
||||
class Index : public database<index_entry> {
|
||||
public:
|
||||
/**
|
||||
* Index constructor. This simply passes the filepath and autosave
|
||||
|
|
|
@ -72,9 +72,9 @@ namespace playlist
|
|||
* Use to access specific tracks in a playlist.
|
||||
*
|
||||
* @param name The playlist to access.
|
||||
* @return The IndexEntry containing the tracks.
|
||||
* @return The index_entry containing the tracks.
|
||||
*/
|
||||
IndexEntry *get_tracks(const std::string &);
|
||||
index_entry *get_tracks(const std::string &);
|
||||
|
||||
/**
|
||||
* @return The playlist queue.
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
static void test_entry()
|
||||
{
|
||||
IndexEntry *ie = new struct IndexEntry("Link");
|
||||
index_entry *ie = new index_entry("Link");
|
||||
unsigned int i;
|
||||
struct file f;
|
||||
|
||||
|
@ -30,7 +30,7 @@ static void test_entry()
|
|||
file_close(&f);
|
||||
delete ie;
|
||||
|
||||
ie = new IndexEntry();
|
||||
ie = new index_entry();
|
||||
test_equal(ie->primary_key(), "");
|
||||
test_equal(ie->size(), 0);
|
||||
test_equal(ie->has(42), false);
|
||||
|
@ -56,7 +56,7 @@ static void test_stress(unsigned int N)
|
|||
{
|
||||
Index index("stress.idx", false);
|
||||
std::string key;
|
||||
IndexEntry *ie;
|
||||
index_entry *ie;
|
||||
unsigned int i;
|
||||
char c;
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
#include <core/tags/tags.h>
|
||||
#include "test.h"
|
||||
|
||||
static IndexEntry *IDX_NULL = NULL;
|
||||
static index_entry *IDX_NULL = NULL;
|
||||
static Queue *Q_NULL = NULL;
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
IndexEntry *ent;
|
||||
index_entry *ent;
|
||||
Queue *q = playlist :: get_queue();
|
||||
|
||||
test_not_equal(q, Q_NULL);
|
||||
|
@ -58,7 +58,7 @@ static void test_queue()
|
|||
|
||||
static void test_add()
|
||||
{
|
||||
IndexEntry *ent;
|
||||
index_entry *ent;
|
||||
Queue *q = playlist :: get_queue();
|
||||
Queue *l = library :: get_queue();
|
||||
|
||||
|
@ -82,7 +82,7 @@ static void test_add()
|
|||
|
||||
static void test_delete()
|
||||
{
|
||||
IndexEntry *ent;
|
||||
index_entry *ent;
|
||||
Queue *q = playlist :: get_queue();
|
||||
Queue *l = library :: get_queue();
|
||||
|
||||
|
|
Loading…
Reference in New Issue