|
From: Jim A. <ji...@tr...> - 2001-03-28 07:36:21
|
This problem is similar to my last one about using 'hashCode' vs
'identityHashCode': there are several places in PyStringMap where
Strings are compared with '=='.
When passing in arbitrary Strings from Java this can fail: see the
sample code in my last post.
To make it work, I added/changed the comparisons using '.equals' as
follows:
In '__finditem__' after this:
if (tkey == key) {
//if (collisions > 0) {
// System.err.println("key: "+key+", "+collisions+",
"+
// maxindex+",
"+System.identityHashCode(key));
//}
return values[index];
}
if (tkey == null) {
return values[index];
}
I added this:
if (tkey.equals(key)) {
return values[index];
}
in 'insertkey':
-- } else if (tkey == key) {
++ } else if (tkey.equals(key)) { // null is taken care of
above
or would you rather see this..it might be faster ?:
++ } else if ( (tkey == key) || tkey.equals(key) ) {
and in '__delitem__':
-- if (tkey == key) {
++ if (tkey.equals(key)) {
or:
++ if ( (tkey == key) || (tkey.equals(key)) {
Does this look OK? Or am I off base somehow ? (and would it be easier
for you if I learned to use 'diff' ;^) ?? )
--
__o
Jim Adrig _ \<,_
ji...@tr... ' `/ ' `
___________ `-' `-'
|