Class: Amatch::Hamming
- Inherits:
-
Object
- Object
- Amatch::Hamming
- Defined in:
- ext/amatch_ext.c,
ext/amatch_ext.c
Overview
This class computes the Hamming distance between two strings.
The Hamming distance between two strings is the number of characters, that are different. Thus a hamming distance of 0 means an exact match, a hamming distance of 1 means one character is different, and so on. If one string is longer than the other string, the missing characters are counted as different characters.
Instance Method Summary collapse
-
#new(pattern) ⇒ Object
constructor
Creates a new Amatch::Hamming instance from
pattern. - #match ⇒ Object
-
#pattern ⇒ Object
call-seq: pattern -> pattern string.
-
#pattern= ⇒ Object
call-seq: pattern=(pattern).
-
#similar(strings) ⇒ Object
Uses this Amatch::Hamming instance to match Amatch::Hamming#pattern against
strings, and compute a Hamming distance metric number between 0.0 for very unsimilar strings and 1.0 for an exact match.
Constructor Details
#new(pattern) ⇒ Object
Creates a new Amatch::Hamming instance from pattern.
1395 1396 1397 1398 1399 1400 |
# File 'ext/amatch_ext.c', line 1395 static VALUE rb_Hamming_initialize(VALUE self, VALUE pattern) { GET_STRUCT(General) General_pattern_set(amatch, pattern); return self; } |
Instance Method Details
#match ⇒ Object
#pattern ⇒ Object
call-seq: pattern -> pattern string
Returns the current pattern string of this Amatch::Sellers instance.
#pattern= ⇒ Object
call-seq: pattern=(pattern)
Sets the current pattern string of this Amatch::Sellers instance to
pattern.
#similar(strings) ⇒ Object
Uses this Amatch::Hamming instance to match Amatch::Hamming#pattern against
strings, and compute a Hamming distance metric number between
0.0 for very unsimilar strings and 1.0 for an exact match.
strings has to be either a String or an Array of Strings. The
returned results is either a Fixnum or an Array of Fixnums
respectively.
1429 1430 1431 1432 1433 |
# File 'ext/amatch_ext.c', line 1429 static VALUE rb_Hamming_similar(VALUE self, VALUE strings) { GET_STRUCT(General) return General_iterate_strings(amatch, strings, Hamming_similar); } |