[mythtv] MythMusic playlists still not intelligent enough IMHO
Lasse Nisted
zartzartzart+mythtv-dev at gmail.com
Thu Apr 19 14:12:36 UTC 2007
> > 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
Interesting! :) It seems correct, though I'm not sure the selection
will be uniform, but maybe it is... I can't think right now :)
- Lasse Nisted
More information about the mythtv-dev
mailing list