Author: bryanduxbury
Date: Fri May 29 20:18:58 2009
New Revision: 780094
URL: http://svn.apache.org/viewvc?rev=780094&view=rev
Log:
THRIFT-511. rb: Better performing hash method for generated structs
This patch uses a hash function that takes into account the hashes of struct
elements, instead of just returning 0. This make hashes of Thrift structs O(1)
instead of O(n).
Modified:
incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb?rev=780094&r1=780093&r2=780094&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb Fri May 29 20:18:58 2009
@@ -141,9 +141,13 @@
self.class == other.class && self == other
end
- # for the time being, we're ok with a naive hash. this could definitely be
improved upon.
def hash
- 0
+ field_values = []
+ each_field do |fid, field_info|
+ name = field_info[:name]
+ field_values << self.instance_variable_get("@#{name}")
+ end
+ field_values.hash
end
def differences(other)