mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-28 15:03:23 +00:00
026055a0b7
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.3.0 to 2.27.1. - [Release notes](https://github.com/urfave/cli/releases) - [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md) - [Commits](https://github.com/urfave/cli/compare/v2.3.0...v2.27.1) --- updated-dependencies: - dependency-name: github.com/urfave/cli/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
26 lines
544 B
Go
26 lines
544 B
Go
package smetrics
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// The Hamming distance is the minimum number of substitutions required to change string A into string B. Both strings must have the same size. If the strings have different sizes, the function returns an error.
|
|
func Hamming(a, b string) (int, error) {
|
|
al := len(a)
|
|
bl := len(b)
|
|
|
|
if al != bl {
|
|
return -1, fmt.Errorf("strings are not equal (len(a)=%d, len(b)=%d)", al, bl)
|
|
}
|
|
|
|
var difference = 0
|
|
|
|
for i := range a {
|
|
if a[i] != b[i] {
|
|
difference = difference + 1
|
|
}
|
|
}
|
|
|
|
return difference, nil
|
|
}
|