Unsubscribe
On Jan 18, 2011 8:56 PM, "dblock" <dblockdotorg / gmail.com> wrote:
> I am trying to improve performance of Euclidian distance between two
> hash maps. The code is pretty straightforward:
>
> def self.euclidian_distance(lhs, rhs)
> @s = lhs.inject(0.0) do |s, (k,v)|
> rhs.has_key?(k) ? (s + (v - rhs[k])**2) : (s + v**2)
> end
> @s = rhs.inject(@s) do |s, (k,v)|
> lhs.has_key?(k) ? s : (s + v**2)
> end
> @s
> end
>
> Any suggestions?
>