void WaveBother::addTrack(string name) { ofstream spectre(dbPrefix + "fingerprintBase.spct", ios_base::app); set<double> fingerprints = fingerPrint(suspPrefix + name); set<double>::iterator it; for(it = fingerprints.begin(); it != fingerprints.end(); ++it) { spectre << setprecision(16) << *it << " " << name << endl; } spectre.close(); cout << name + " added to base." << endl; }
// TODO: create in TEMP directory instead? static WCHAR *GetThumbnailPath(const WCHAR *filePath) { // create a fingerprint of a (normalized) path for the file name // I'd have liked to also include the file's last modification time // in the fingerprint (much quicker than hashing the entire file's // content), but that's too expensive for files on slow drives unsigned char digest[16]; ScopedMem<char> pathU(str::conv::ToUtf8(filePath)); if (path::HasVariableDriveLetter(filePath)) pathU[0] = '?'; // ignore the drive letter, if it might change CalcMD5Digest((unsigned char *)pathU.Get(), str::Len(pathU), digest); ScopedMem<char> fingerPrint(str::MemToHex(digest, 16)); ScopedMem<WCHAR> thumbsPath(AppGenDataFilename(THUMBNAILS_DIR_NAME)); if (!thumbsPath) return NULL; ScopedMem<WCHAR> fname(str::conv::FromAnsi(fingerPrint)); return str::Format(L"%s\\%s.png", thumbsPath, fname); }
// using a int vector[26] to caculate the fingerPrint of the str // 304ms vector<string> anagrams(vector<string> &strs) { vector<string> result; if (strs.empty()) return result; map<vector<int>, vector<string> > dict; vector<string>::iterator st = strs.begin(); for (; st != strs.end(); ++ st) { dict[fingerPrint(*st)].push_back(*st); } map<vector<int>, vector<string> >::iterator it = dict.begin(); for (; it != dict.end(); ++ it) { if (it->second.size() > 1) { for(st = it->second.begin(); st != it->second.end(); st ++) result.push_back(*st); } } return result; }
void WaveBother::findTrack(string name) { set<double> fingerprints = fingerPrint(dbPrefix + name); multimap<double, string>::iterator it; map<string, int> occasions; map<string, int>::iterator iter; clock_t startTime = clock(); for(it = database.begin(); it != database.end(); ++it) { if(fingerprints.find(it->first) != fingerprints.end()) { occasions[it->second]++; } } cout << name << " " << double(clock() - startTime) / (double)CLOCKS_PER_SEC<< " seconds." << endl; int max = 0; int k = 0; string j; for(iter = occasions.begin(); iter != occasions.end(); ++iter) { //cout << iter->first << " " << iter->second << endl; if(iter->second > max) { max = iter->second; j = iter->first; } } cout << j << " " << occasions[j] << endl << endl; }
// TODO: create in TEMP directory instead? static WCHAR* GetThumbnailPath(const WCHAR* filePath) { // create a fingerprint of a (normalized) path for the file name // I'd have liked to also include the file's last modification time // in the fingerprint (much quicker than hashing the entire file's // content), but that's too expensive for files on slow drives unsigned char digest[16]; // TODO: why is this happening? Seen in crash reports e.g. 35043 if (!filePath) return nullptr; OwnedData pathU(str::conv::ToUtf8(filePath)); if (!pathU.Get()) return nullptr; if (path::HasVariableDriveLetter(filePath)) pathU.Get()[0] = '?'; // ignore the drive letter, if it might change CalcMD5Digest((unsigned char*)pathU.Get(), str::Len(pathU.Get()), digest); AutoFree fingerPrint(_MemToHex(&digest)); AutoFreeW thumbsPath(AppGenDataFilename(THUMBNAILS_DIR_NAME)); if (!thumbsPath) return nullptr; AutoFreeW fname(str::conv::FromAnsi(fingerPrint)); return str::Format(L"%s\\%s.png", thumbsPath.Get(), fname.Get()); }