Hi,
I've been trying to workout a good way of doing this fast but I'm not sure what will be the most optimal, I'm hoping some of you more experienced developers can assist via your Data Structures knowledge :-)
Essentially I have a list of paths (Eg. C:\inetpub\wwwroot\, C:\www\websites\vhosts\somesite.com\, D:\www-mirror\websites\vhosts\somesite.co.uk), I have to check that the current file I'm working on (say C:\inetpub\wwwroot\styles\style.css) exists in the preconfigured list of paths.
So what I initially thought was to interate my list of items and do a CurrentFilename.StartsWith(PreconfigureListOfPathsPathName). But I'm iterating through the list quite regularly and it slows down as the list can contain sometimes 10, othertimes 1000 (clients on a server) paths.
What would you suggest as a fast solution for this problem? I'm writing in C# 3.5, this is only a small (but a critical) section of the project.
I thought about binary search trees, breaking down the paths and then doing a treemap and iterating through each path. But I'm not sure if its correct as we could have lots of nodes.
D:\www-mirror\websites\vhosts\somesite.co.uk\
D:\www-mirror\websites\vhosts\somesite.com\
D:\www-mirror\websites\vhosts\somesite.org\
D:\www-mirror\websites\vhosts\somesite.pl\
Tree map:
www-mirror->websites->vhosts->somesite* (has 4 nodes)
www-mirror->blah->woah->okay
But it looks a bit wonky.