Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My prog is a streaming mp3 player. At program start, a file is downloaded containing a list of tracks available online at the moment. Currently there are 20.000.000 items in this list!

This textfile is read and converted to a list(of mediadata), where mediadata is a custom class containg 14 items per track (e.g. artist as string, title as string, album as string, duration as string...)
So I have a list(of mediadata) containing approx. 20.000.000 items.

Locally I likewise have playlists containing roughly 1000 tracks each, existing of the same type (mediadata)


My problem:
Because not all songs online are always available I need to compare these playlists based on "artist" and "title" (the other values may be different!) against MusicLibrary, and if a match is found, I load the data from the MusicLibray into my player.


I can do this with a for each loop of course,but this takes ages to load.

What would be the fastest way to make this comparison? A binarysearch is not possible as far as I know?


Am I approaching this problem the wrong way? Any refreshing ideas?
Posted
Updated 22-Feb-15 9:16am
v3
Comments
Maciej Los 22-Feb-15 15:19pm    
I'd suggest to use database such as SQL server, MySQL, etc instead of textfile...
fanoftheplanet 22-Feb-15 16:05pm    
That would be an idea. The problem with this, is that the program should work offline as well (when there is no access to the database). What I do atm is compare that downloaded list to files that are locally available.
Dave Kreskowiak 22-Feb-15 15:29pm    
So you're telling us you want to make 20,000,000 comparisons on data that doesn't have an index? Am I hearing that correctly?
fanoftheplanet 22-Feb-15 16:01pm    
A list is indexed, isn't it?
What would be the proper way to do this then?
Dave Kreskowiak 22-Feb-15 22:27pm    
Yes, it is, but your file is not. The index has to be built by the List<t> class as you load the data from the file.

The bottom line is storing 20,000,000 records in a file is not the best way to do it. A database is far better suited for this.

Try this.

C#
var MyListC = MyListA.Where(t2 => MyListB.Count(t1 => t2.Author == t1.Author && t2.Title == t1.Title) == 0);
 
Share this answer
 
Use SQLite locally to store playlist and make exchanges using common SQL commands that can work for local SQLite and the main network database.
This should avoid to reinvent the wheel...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900