avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bachran, Michael" <MBach...@onebridge.de>
Subject Bug in BucketMap?
Date Thu, 16 May 2002 10:59:52 GMT
Hi,

as far as I can see there is a bug in the put method of the BucketMap.
If there is no bucket node for the calculated hashcode it is not checked
wether the key is already present so another node with the same key may be
added.
Also NULL will not be returned in this case but the value that is added. If
I am not totally wrong I would suggest the following patch shifting the if
down and returning 
null instead of value:

            Node n = m_buckets[ hash ];

-            if( n == null )
-            {
-                n = new Node();
-                n.key = key;
-                n.value = value;
-                m_buckets[ hash ] = n;
-                return value;
-            }

            // Set n to the last node in the linked list.  Check each key
along the way
            //  If the key is found, then change the value of that node and
return
            //  the old value.
            for( Node next = n; next != null; next = next.next )
            {
                n = next;

                if( n.key.equals( key ) )
                {
                    Object returnVal = n.value;
                    n.value = value;
                    return returnVal;
                }
            }

+            if( n == null )
+           {
+                n = new Node();
+                n.key = key;
+                n.value = value;
+                m_buckets[ hash ] = n;
+                return null;				// return null here!
+            }


MfG, Michael

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message