Article View: cn.bbs.comp.lang.java
Article #20966Re: һ��hashtable��һ��key�ɲ����Զ�Ӧ����� ��
From: Java & .Net
Date: Sat, 13 Dec 2003 02:30
Date: Sat, 13 Dec 2003 02:30
45 lines
2050 bytes
2050 bytes
��һ��Hashtable��put���������Ϳ����˽���
public synchronized Object put(Object key, Object value) {
// Make sure the value is not null
if (value == null) {
throw new NullPointerException();
}
// Makes sure the key is not already in the hashtable.
Entry tab[] = table;
int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index] ; e != null ; e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) {
Object old = e.value;
e.value = value;
return old;
}
}
modCount++;
if (count >= threshold) {
// Rehash the table if the threshold is exceeded
rehash();
tab = table;
index = (hash & 0x7FFFFFFF) % tab.length;
}
// Creates the new entry.
Entry e = new Entry(hash, key, value, tab[index]);
tab[index] = e;
count++;
return null;
}
�Ĵ������ᵽ: ��
: att
--
�ο��أ��α��أ�
[m[1;35m�� ��Դ:��Ʈ��ˮ�Ƽ� Freecity.dhs.org��[FROM: skyhit][m
Technical Details
Message-ID:
<49ccJM$AKL@Freecity.dhs.org>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-05!sn-xit-08!supernews.com!newsfeed.news2me.com!yellow.newsread.com!netaxs.com!newsread.com!feed1.newsreader.com!newsreader.com!news3.optonline.net!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!FreecityShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,GB X-Google-Thread: f6cb0,33f908c1879bd91c,start X-Google-Attributes: gidf6cb0,public X-Google-ArrivalTime: 2003-12-12 18:32:52 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-05!sn-xit-08!supernews.com!newsfeed.news2me.com!yellow.newsread.com!netaxs.com!newsread.com!feed1.newsreader.com!newsreader.com!news3.optonline.net!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!Freecity From: skyhit.bbs@Freecity.dhs.org (Java & .Net) Newsgroups: cn.bbs.comp.lang.java Subject: Re: һ��hashtable��һ��key�ɲ����Զ�Ӧ����� �� Date: 13 Dec 2003 02:30:37 GMT Organization: Ʈ��ˮ�Ƽ� Message-ID: <49ccJM$AKL@Freecity.dhs.org> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: Java/M.1071282598.A