test.d (891B)
1 import puzzle; 2 import std.stdio; 3 import std.file; 4 import std.conv; 5 import std.parallelism; 6 import std.algorithm; 7 import std.range; 8 import std.getopt; 9 10 static bool isImage(string name){ 11 return name.endsWith("jpg","JPG","png","PNG","gif","GIF")!=0; 12 } 13 14 void main(string args[]){ 15 SpanMode m=SpanMode.shallow; 16 double threshold=0.55; 17 18 if(args.length<3){ 19 writeln("Usage: ", args[0], " <[-r|--recursive]> <[--threshold,-t] double> <File> <Directory>"); 20 return; 21 } 22 23 getopt(args, 24 "recursive|r", (){m=SpanMode.breadth;}, 25 "threshold|t", &threshold); 26 27 Puzzle p; 28 p.initialize(); 29 CVec cva=p.cvec(); 30 cva.load(args[1]); 31 auto cvb=taskPool.workerLocalStorage(p.cvec()); 32 foreach(ref name; parallel(dirEntries(args[2], m, false).filter!(a=>isImage(a)).array)){ 33 try{cvb.get.load(name);}catch(PuzzleException e){continue;} 34 35 if(cva.compare(cvb.get)<threshold){ 36 writeln(name); 37 } 38 } 39 }