Sha256: 0f9ea603ff6e794125f0d1ddf0a792cf8ca283a79227978ae29b7372730fc35d

Contents?: true

Size: 528 Bytes

Versions: 396

Compression:

Stored size: 528 Bytes

Contents

#include "hamming.h"
#include <algorithm>
#include <stdexcept>

namespace hamming
{

int compute(std::string const& lhs, std::string const& rhs)
{
    if (rhs.length() != lhs.length())
    {
        throw std::domain_error("Hamming distance is not defined for different length strings.");
    }

    int count = 0;
    for (auto p = std::mismatch(lhs.begin(), lhs.end(), rhs.begin());
        p.first != lhs.end();
        p = std::mismatch(++p.first, lhs.end(), ++p.second))
    {
        ++count;
    }
    return count;
}

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.0.4.0 tracks/cpp/hamming/example.cpp
trackler-2.0.3.9 tracks/cpp/hamming/example.cpp
trackler-2.0.3.8 tracks/cpp/hamming/example.cpp
trackler-2.0.3.7 tracks/cpp/hamming/example.cpp
trackler-2.0.3.6 tracks/cpp/hamming/example.cpp
trackler-2.0.3.5 tracks/cpp/hamming/example.cpp
trackler-2.0.3.4 tracks/cpp/hamming/example.cpp
trackler-2.0.3.3 tracks/cpp/hamming/example.cpp
trackler-2.0.3.2 tracks/cpp/hamming/example.cpp
trackler-2.0.3.1 tracks/cpp/hamming/example.cpp
trackler-2.0.3.0 tracks/cpp/hamming/example.cpp
trackler-2.0.2.0 tracks/cpp/hamming/example.cpp
trackler-2.0.1.2 tracks/cpp/hamming/example.cpp
trackler-2.0.1.1 tracks/cpp/hamming/example.cpp
trackler-2.0.1.0 tracks/cpp/hamming/example.cpp
trackler-2.0.0.10 tracks/cpp/hamming/example.cpp
trackler-2.0.0.9 tracks/cpp/hamming/example.cpp
trackler-2.0.0.8 tracks/cpp/hamming/example.cpp
trackler-2.0.0.7 tracks/cpp/hamming/example.cpp
trackler-2.0.0.6 tracks/cpp/hamming/example.cpp