JInterface objects missing hashCode method
Shawn Pearce
spearce@REDACTED
Fri Jan 26 06:04:00 CET 2001
In R7B-0, the JInterface (Java side) objects are missing overriding
methods for the hashCode() method. This makes them impossible to ues
in a java.util.Hashtable, as two different instances of an OtpErlangAtom
(even if they have the same name) do not hash to the same location in
the Hashtable, and therefore cannot ever be considered equal.
Now it wouldn't be so bad if I made the objects by hand, but in this
case the OtpErlangAtoms are being sent over from an existing ERTS
based node and are coming out with different hashCodes.
Attached below is a set of patches which add the missing hashCode
methods (sorry, no Javadoc added). It also includes the
acceptor.start() bug fix that was already noted for R7B-0, as well as
the patch from my previous email to support 0 arity tuples.
--
Shawn.
``If this had been a real
life, you would have
received instructions
on where to go and what
to do.''
diff -r -c otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangAtom.java otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangAtom.java
*** otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangAtom.java Tue Aug 22 08:01:26 2000
--- otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangAtom.java Thu Jan 25 23:49:58 2001
***************
*** 135,140 ****
--- 135,149 ----
}
/**
+ * Get the hashcode of the atom value.
+ *
+ * @return hashCode of atomValue().
+ **/
+ public int hashCode() {
+ return this.atom.hashCode();
+ }
+
+ /**
* Convert this atom to the equivalent Erlang external representation.
*
* @param buf an output stream to which the encoded atom should be
diff -r -c otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangBinary.java otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangBinary.java
*** otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangBinary.java Tue Aug 22 08:01:29 2000
--- otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangBinary.java Thu Jan 25 23:58:42 2001
***************
*** 180,186 ****
return true;
}
!
public Object clone() {
OtpErlangBinary newBin = (OtpErlangBinary)(super.clone());
newBin.bin = (byte[])bin.clone();
--- 180,196 ----
return true;
}
!
! public int hashCode() {
! int hc = 0;
!
! int size = this.size();
! for(int x = 0; x < size; x++) {
! hc += this.bin[x];
! }
! return hc;
! }
!
public Object clone() {
OtpErlangBinary newBin = (OtpErlangBinary)(super.clone());
newBin.bin = (byte[])bin.clone();
diff -r -c otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangDouble.java otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangDouble.java
*** otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangDouble.java Tue Aug 22 08:01:40 2000
--- otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangDouble.java Thu Jan 25 23:53:20 2001
***************
*** 113,116 ****
--- 113,121 ----
OtpErlangDouble d = (OtpErlangDouble)o;
return this.d == d.d;
}
+
+ public int hashCode() {
+ return (int)(d * 100);
+ }
+
}
diff -r -c otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangList.java otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangList.java
*** otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangList.java Tue Aug 22 08:01:50 2000
--- otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangList.java Thu Jan 25 23:54:26 2001
***************
*** 230,235 ****
--- 230,244 ----
return true;
}
+ public int hashCode() {
+ int a = this.arity();
+ int hc = 0;
+ for (int i = 0; i < a; i++) {
+ hc += this.elems[i].hashCode();
+ }
+ return hc;
+ }
+
public Object clone() {
OtpErlangList newList = (OtpErlangList)(super.clone());
newList.elems = (OtpErlangObject[])elems.clone();
diff -r -c otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangLong.java otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangLong.java
*** otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangLong.java Tue Aug 22 08:01:52 2000
--- otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangLong.java Thu Jan 25 23:54:44 2001
***************
*** 222,225 ****
--- 222,229 ----
OtpErlangLong l = (OtpErlangLong)o;
return this.val == l.val;
}
+
+ public int hashCode() {
+ return (int)this.val;
+ }
}
diff -r -c otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangTuple.java otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangTuple.java
*** otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangTuple.java Tue Aug 22 08:02:14 2000
--- otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangTuple.java Thu Jan 25 21:13:58 2001
***************
*** 105,113 ****
this.elems = new OtpErlangObject[arity];
for (int i=0; i<arity; i++) {
! elems[i] = buf.read_any();
! }
! }
}
/**
--- 105,115 ----
this.elems = new OtpErlangObject[arity];
for (int i=0; i<arity; i++) {
! elems[i] = buf.read_any();
! }
! } else {
! this.elems = new OtpErlangObject[0];
! }
}
/**
diff -r -c otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpNode.java otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpNode.java
*** otp_src_R7B-0.orig/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpNode.java Tue Aug 22 08:05:26 2000
--- otp_src_R7B-0/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpNode.java Fri Jan 12 22:13:59 2001
***************
*** 610,616 ****
this.setDaemon(true);
this.setName("acceptor");
publishPort();
! acceptor.start();
}
private boolean publishPort()
--- 610,616 ----
this.setDaemon(true);
this.setName("acceptor");
publishPort();
! this.start();
}
private boolean publishPort()
More information about the erlang-questions
mailing list