Skip to content

Commit

Permalink
Add docs for the Hamming distance.
Browse files Browse the repository at this point in the history
  • Loading branch information
xrash committed Apr 3, 2016
1 parent c56542a commit 733fb28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ The Soundex encoding. It is a phonetic algorithm that considers how the words so
smetrics.Soundex("Ladd")
>> L300

## Hamming

func Hamming(a, b string) (int, error)

The Hamming distance is simply the minimum number of substitutions required to change one string into the other. Both strings must have the same size, of the function returns an error.

#### Examples:

smetrics.Hamming("aaa", "aaa")
>> 0, nil

smetrics.Hamming("aaa", "aab")
>> 1, nil

smetrics.Hamming("aaaa", "a")
>> -1, error

# TODO

- Accept cost functions instead of constant values in every Levenshtein implementation.
Expand Down
17 changes: 17 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ The Soundex encoding. It is a phonetic algorithm that considers how the words so
smetrics.Soundex("Ladd")
>> L300
## Hamming
func Hamming(a, b string) (int, error)
The Hamming distance is simply the minimum number of substitutions required to change one string into the other. Both strings must have the same size, of the function returns an error.
#### Examples:
smetrics.Hamming("aaa", "aaa")
>> 0, nil
smetrics.Hamming("aaa", "aab")
>> 1, nil
smetrics.Hamming("aaaa", "a")
>> -1, error
# TODO
- Optimize WagnerFischer for memory; currently it stores the whole matrix and so it needs O(mn) space. Only the previous row of the matrix needs to be stored, so it can be easily optimized to use O(m) space.
Expand Down

0 comments on commit 733fb28

Please sign in to comment.