[mythtv] MythMusic playlists still not intelligent enough IMHO
David Härdeman
david at hardeman.nu
Thu Apr 19 13:58:00 UTC 2007
On Thu, April 19, 2007 14:15, Lasse Nisted said:
> On 4/19/07, David Härdeman <david at hardeman.nu> wrote:
>> On Thu, April 19, 2007 9:56, Lasse Nisted said:
>> > I have not followed the discussion, but why not simply create an array
>> > [0,1,2,...,N-1] and shuffle this using STL's random_shuffle?
>> >
>> > A playlist containing 32,000 songs results in a 1MB array, is that
>> > really too large?
>>
>> Use a bitmap? 32k songs => 4kB memory
>>
> Hmm, what would be the interpretation of that bitmap?
char * bitmap = NULL;
int pickasong() {
static int played = num_songs;
int index = rand() % num_songs;
if (!bitmap)
bitmap = malloc((num_songs + 7)/8);
played++;
if (played >= num_songs) {
memset(bitmap, 0, (num_songs + 7)/8);
played = 0;
}
while(bitmap[index/8] & (1 << (index % 8))) {
index++;
if (index >= num_songs)
index = 0;
}
bitmap[index/8] &= (1 << (index % 8));
return index;
}
Worst case scenario is num_songs bit comparisons before a song is found
(which could be reduced with more code to a worst case of num_songs / 8
byte comparisons and 8 bit comparisons).
--
David Härdeman
More information about the mythtv-dev
mailing list