vector<string> findRepeatedDnaSequences(string s) {
     vector<string> result;
     if(s.length() < 10) {
         return result;
     }
     unordered_map <int, int> Map;
     
     string substr = s.substr(0, 10);
     int hash = stringHash(substr);
     Map[hash]++;
     
     for(int i = 10; i < s.length(); ++i) {
         int newHash = updateHash(hash, s[i]);
         Map[newHash]++;
         hash = newHash;
     }
     
     for(auto it = Map.begin(); it != Map.end(); ++it) {
         if(it->second > 1) {
             string str = hashToStr(it->first);
             result.push_back(str);
         }
     }
     return result;
 }
예제 #2
0
string FileHash::generate()
{
    char buf[512];
    SHA512_CTX sha;
    unsigned char out[SHA512_DIGEST_LENGTH];

    SHA512_Init(&sha);

    while (!file_.eof()) {
        memset(buf, 0x00, 512);
        file_.read(buf, 512);
        SHA512_Update(&sha, buf, 512);
    }

    SHA512_Final(out, &sha);
    return hashToStr(out);
}