check if song is in playlist in O(nlogn) instead of O(n^2)

This commit is contained in:
Andrzej Rybczak
2012-09-04 03:12:37 +02:00
parent 8ab8da2a30
commit 60ca9de919
7 changed files with 50 additions and 51 deletions

View File

@@ -21,6 +21,8 @@
#ifndef _PLAYLIST_H
#define _PLAYLIST_H
#include <map>
#include "interfaces.h"
#include "screen.h"
#include "song.h"
@@ -80,7 +82,7 @@ class Playlist : public Screen<NC::Window>, public Filterable, public HasSongs,
void UpdateTimer() { time(&itsTimer); }
time_t Timer() const { return itsTimer; }
bool Add(const MPD::Song &s, bool in_playlist, bool play, int position = -1);
bool Add(const MPD::Song &s, bool play, int position = -1);
bool Add(const MPD::SongList &l, bool play, int position = -1);
void PlayNewlyAddedSongs();
@@ -88,6 +90,9 @@ class Playlist : public Screen<NC::Window>, public Filterable, public HasSongs,
bool checkForSong(const MPD::Song &s);
void registerHash(size_t hash);
void unregisterHash(size_t hash);
//static std::string SongToString(const MPD::Song &s);
//static std::string SongInColumnsToString(const MPD::Song &s);
@@ -106,6 +111,8 @@ class Playlist : public Screen<NC::Window>, public Filterable, public HasSongs,
std::string TotalLength();
std::string itsBufferedStats;
std::map<size_t, int> itsSongHashes;
size_t itsTotalLength;
size_t itsRemainingTime;
size_t itsScrollBegin;