/[classpath]/classpath/java/util/Hashtable.java
ViewVC logotype

Diff of /classpath/java/util/Hashtable.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by bryce, Thu Sep 13 23:25:43 2001 UTC revision 1.15 by ericb, Sun Sep 16 05:52:04 2001 UTC
# Line 1  Line 1 
1  /* Hashtable.java -- a class providing a basic hashtable data structure,  /* Hashtable.java -- a class providing a basic hashtable data structure,
2     mapping Object --> Object     mapping Object --> Object
3     Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.     Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4    
5  This file is part of GNU Classpath.  This file is part of GNU Classpath.
6    
# Line 64  import java.io.ObjectOutputStream; Line 64  import java.io.ObjectOutputStream;
64   * @author      Jon Zeppieri   * @author      Jon Zeppieri
65   * @author      Warren Levy   * @author      Warren Levy
66   * @author      Bryce McKinlay   * @author      Bryce McKinlay
67     * @author      Eric Blake <ebb9@email.byu.edu>
68   */   */
69  public class Hashtable extends Dictionary  public class Hashtable extends Dictionary
70    implements Map, Cloneable, Serializable    implements Map, Cloneable, Serializable
# Line 71  public class Hashtable extends Dictionar Line 72  public class Hashtable extends Dictionar
72    /** Default number of buckets. This is the value the JDK 1.3 uses. Some    /** Default number of buckets. This is the value the JDK 1.3 uses. Some
73      * early documentation specified this value as 101. That is incorrect. */      * early documentation specified this value as 101. That is incorrect. */
74    private static final int DEFAULT_CAPACITY = 11;      private static final int DEFAULT_CAPACITY = 11;  
75    /** The defaulty load factor; this is explicitly specified by the spec. */    /** The default load factor; this is explicitly specified by the spec. */
76    private static final float DEFAULT_LOAD_FACTOR = 0.75f;    private static final float DEFAULT_LOAD_FACTOR = 0.75f;
77    
78    private static final long serialVersionUID = 1421746759512286392L;    private static final long serialVersionUID = 1421746759512286392L;
# Line 122  public class Hashtable extends Dictionar Line 123  public class Hashtable extends Dictionar
123          throw new NullPointerException();          throw new NullPointerException();
124        return super.setValue(newVal);        return super.setValue(newVal);
125      }      }
126    
127        Entry copy()
128        {
129          Entry e = new Entry(key, value);
130          if (next != null)
131            e.next = next.copy();
132          return e;
133        }
134    }    }
135    
136    /**    /**
# Line 144  public class Hashtable extends Dictionar Line 153  public class Hashtable extends Dictionar
153     */     */
154    public Hashtable(Map m)    public Hashtable(Map m)
155    {    {
156      int size = Math.max(m.size() * 2, DEFAULT_CAPACITY);      this(Math.max(m.size() * 2, DEFAULT_CAPACITY));
     buckets = new Entry[size];  
     threshold = (int) (size * loadFactor);  
157      putAll(m);      putAll(m);
158    }    }
159    
# Line 223  public class Hashtable extends Dictionar Line 230  public class Hashtable extends Dictionar
230     */     */
231    public synchronized boolean contains(Object value)    public synchronized boolean contains(Object value)
232    {    {
233        // if Hashtable is empty, this method doesn't dereference
234        // `value' anywhere, so check for it explicitly.
235        if (value == null)
236          throw new NullPointerException();
237      for (int i = 0; i < buckets.length; i++)      for (int i = 0; i < buckets.length; i++)
238        {        {
239          Entry e = buckets[i];          Entry e = buckets[i];
# Line 389  public class Hashtable extends Dictionar Line 400  public class Hashtable extends Dictionar
400    public synchronized void clear()    public synchronized void clear()
401    {    {
402      modCount++;      modCount++;
403      for (int i=0; i < buckets.length; i++)      buckets = new Entry[buckets.length];
       {  
         buckets[i] = null;  
       }  
404      size = 0;      size = 0;
405    }    }
406    
# Line 415  public class Hashtable extends Dictionar Line 423  public class Hashtable extends Dictionar
423      for (int i=0; i < buckets.length; i++)      for (int i=0; i < buckets.length; i++)
424        {        {
425          Entry e = buckets[i];          Entry e = buckets[i];
426          Entry last = null;          if (e != null)
427                      copy.buckets[i] = e.copy();
         while (e != null)  
           {  
             if (last == null)  
               {  
                 copy.buckets[i] = new Entry(e.key, e.value);  
                 last = copy.buckets[i];  
               }  
             else                  
               {  
                 last.next = new Entry(e.key, e.value);  
                 last = last.next;  
               }  
             e = e.next;  
           }  
428        }        }
429      return copy;      return copy;
430    }    }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26