Hi, 2011/1/18 Martin Asser Hansen <mail / maasha.dk>: > I was wondering why Ruby don't have a low level implementation of bitwise > operators for strings. You may know, Integer has bitwise operators. We know that we need binary/bitwise methods/operators for strings, and add String#getbyte/setbyte before, but we didn't have enough use cases and knowledge about them. So if you provide enough use cases, we can design and implement. > This is extremely useful for detecting changes in > strings such as Hamming Distance - which in Perl is super efficient: > sub hamming_distance($$) > { > length( $_[ 0 ] ) - ( ( $_[ 0 ] ^ $_[ 1 ] ) =~ tr[\0][\0] ) > } > The optimal implementation would perform bitwise operations on machine words > at a time (i.e. 32 or 64 bits). > This feature is also useful for bitarrays. There was a proposal of String#hamming_distance. http://redmine.ruby-lang.org/issues/show/2571 But it was rejected because * String#hamming_distance doesn't have enough use cases to implement as builtin. * People may want to have String#levenshtein distance if it is merged * it should be extension library or provided as gem. The patch also provided String#^ but it was also rejected because String#^'s behavior is not clear * bitwise or binary? * when the length or two strings are different Anyway I agree with the needs of bitwise methods. If you have a comprehensive proposal with enough use cases, we can begin the discussion. -- NARUSE, Yui naruse / airemix.jp>