大龍的博客
導航
C++博客
首頁
新隨筆
聯系
聚合
管理
<
2012年1月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
留言簿
(43)
給我留言
查看公開留言
查看私人留言
收藏夾
ps
(rss)
隨筆檔案
2014年10月 (1)
2014年8月 (4)
2014年6月 (1)
2013年12月 (6)
2013年11月 (2)
2013年10月 (5)
2013年9月 (4)
2013年7月 (1)
2013年6月 (2)
2013年3月 (1)
2013年2月 (20)
2013年1月 (10)
2012年12月 (8)
2012年11月 (5)
2012年10月 (9)
2012年9月 (4)
2012年8月 (16)
2012年7月 (8)
2012年6月 (10)
2012年5月 (11)
2012年4月 (3)
2012年3月 (10)
2012年2月 (6)
2012年1月 (4)
2011年12月 (6)
2011年11月 (16)
2011年10月 (32)
2011年9月 (13)
2011年8月 (6)
2011年7月 (27)
2011年6月 (18)
2011年5月 (12)
2011年4月 (2)
2011年3月 (1)
2011年2月 (5)
2011年1月 (24)
2010年12月 (5)
2010年11月 (2)
2010年10月 (3)
2010年9月 (4)
2010年8月 (7)
2010年6月 (13)
2010年5月 (18)
2010年4月 (21)
2010年3月 (6)
2010年2月 (7)
2010年1月 (7)
2009年12月 (7)
2009年11月 (2)
2009年10月 (8)
2009年9月 (19)
2009年8月 (11)
2009年6月 (28)
2009年5月 (35)
2009年4月 (18)
2009年3月 (24)
2009年2月 (13)
2009年1月 (10)
2008年12月 (2)
2008年11月 (6)
2008年10月 (4)
2008年9月 (11)
2008年8月 (18)
2008年7月 (8)
2008年6月 (19)
2008年5月 (9)
2008年4月 (6)
2008年3月 (2)
2008年2月 (4)
2008年1月 (21)
2007年12月 (14)
2007年11月 (4)
2007年10月 (7)
2007年9月 (17)
2007年8月 (10)
2007年7月 (20)
2007年6月 (11)
2007年5月 (8)
2007年4月 (13)
2007年3月 (2)
2007年2月 (6)
2007年1月 (14)
2006年12月 (23)
2006年11月 (15)
2006年10月 (5)
2006年9月 (4)
文章檔案
2007年11月 (1)
2006年12月 (1)
閱讀排行榜
1.?LinuxShell算術運算(49332)
2.?Windows XP DDK 的有效下載地址(45161)
3.?WinDBG教程(40978)
4.?Android 打包簽名 從生成keystore到完成簽名 -- 轉(40693)
5.?在Cygwin上安裝編輯器vim (39055)
評論排行榜
1.?Windows XP DDK 的有效下載地址(116)
2.?在Cygwin上安裝編輯器vim (24)
3.?(TCP-over-UDP library):基于UDP協議之上實現通用、可靠、高效的TCP協議 ---------- 轉(14)
4.?Compuware DriverStudio V3.2(10)
5.? 經典好書 (10)
常用鏈接
我的隨筆
我的評論
我參與的隨筆
統計
隨筆 - 864
文章 - 2
評論 - 378
引用 - 0
最新評論
1.?re: 安裝Nexus私服
謝謝博主。我剛學搭建nexus,挺不錯的。
--做有為青年
2.?re: 用slf4j+logback實現多功能日志解決方案 --- 轉
謝謝樓主,整個流程非常清楚,照著做了一遍就會了。另外我分享一個logback目前尚存在的bug:當你發現INFO級和ERROR級的日志沒有寫成功時,上下移動一下配置文件中appender的位置就好了。
--welldone
3.?re: LinuxShell算術運算
你這些都驗證過嗎
--是是是
4.?re: 用slf4j+logback實現多功能日志解決方案 --- 轉
寫的非常好!
--Hello
5.?re: (TCP-over-UDP library):基于UDP協議之上實現通用、可靠、高效的TCP協議 ---------- 轉
評論內容較長,點擊標題查看
--pcplayer
hashcode重復的可能性超大(轉)
用String的hashcode得到int類型作為主鍵。其實hashcode重復的可能性超大,下面是java的缺省算法:
public
int
hashCode()
{
int
h
=
hash;
if
(h
==
0
)
{
int
off
=
offset;
char
val[]
=
value;
int
len
=
count;
for
(
int
i
=
0
; i
<
len; i
++
)
{
h
=
31
*
h
+
val[off
++
];
}
hash
=
h;
}
return
h;
}
但是什么情況下會重復?下面是測試代碼
import java.util.HashMap;
public
class
Test
{
static
HashMap map
=
new
HashMap();
private
static
char
startChar
=
'
A
'
;
private
static
char
endChar
=
'
z
'
;
private
static
int
offset
=
endChar
-
startChar
+
1
;
private
static
int
dup
=
0
;
public
static
void
main(String[] args)
{
int
len
=
3
;
char
[] chars
=
new
char
[len];
tryBit(chars, len);
System.
out
.println((
int
)Math.pow(offset, len)
+
"
:
"
+
dup);
}
private
static
void
tryBit(
char
[] chars,
int
i)
{
for
(
char
j
=
startChar; j
<=
endChar; j
++
)
{
chars[i
-
1
]
=
j;
if
(i
>
1
)
tryBit(chars, i
-
1
);
else
test(chars);
}
}
private
static
void
test(
char
[] chars)
{
String str
=
new
String(chars).replaceAll(
"
[^a-zA-Z_]
"
,
""
).toUpperCase();
//
195112:0
//
String str = new String(chars).toLowerCase();
//
195112:6612
//
String str = new String(chars).replaceAll("[^a-zA-Z_]","");
//
195112:122500
//
String str = new String(chars);
//
195112:138510
int
hash
=
str.hashCode();
if
(map.containsKey(hash))
{
String s
=
(String) map.
get
(hash);
if
(
!
s.equals(str))
{
dup
++
;
System.
out
.println(s
+
"
:
"
+
str);
}
}
else
{
map.put(hash, str);
//
System.out.println(str);
}
}
}
在A-z范圍內有特殊字符,從結果看,僅僅3位長度的字符串:
不處理: 138510次重復
去掉字母意外字符: 122500次重復
所有字符轉小寫:6612次重復(少了很多)
去掉字母意外字符,并且轉小寫:沒有重復!4位字符串也沒見重復
不難看出:
1. 缺省實現為英文字母優化
2. 字母大小寫可能導致重復
可能:
長字符串可能hashcode重復
中文字符串和特殊字符可能hashcode重復
注:由于是2006年的事,所以上面得出的數據有誤。可自己進行測試。hash沖突次數大大減少。
posted on 2014-08-31 14:59
大龍
閱讀(940)
評論(0)
編輯
收藏
引用
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
Powered by:
C++博客
Copyright © 大龍
精品久久久久久无码人妻蜜桃
|
无码人妻久久一区二区三区
|
久久久无码精品亚洲日韩京东传媒
|
久久99精品九九九久久婷婷
|
久久国产精品视频
|
久久亚洲AV成人无码国产
|
中文字幕久久波多野结衣av
|
香蕉久久AⅤ一区二区三区
|
久久精品亚洲福利
|
久久综合亚洲色HEZYO国产
|
久久精品无码一区二区日韩AV
|
久久婷婷综合中文字幕
|
97久久精品人人做人人爽
|
曰曰摸天天摸人人看久久久
|
国产精品gz久久久
|
久久久久99精品成人片
|
香港aa三级久久三级老师2021国产三级精品三级在
|
欧美久久综合性欧美
|
亚洲va中文字幕无码久久
|
久久精品国产亚洲沈樵
|
麻豆AV一区二区三区久久
|
久久香蕉国产线看观看猫咪?v
|
久久夜色精品国产亚洲av
|
亚洲国产精品成人久久蜜臀
|
国产69精品久久久久APP下载
|
久久伊人五月天论坛
|
久久综合色老色
|
77777亚洲午夜久久多喷
|
国产精品熟女福利久久AV
|
国产无套内射久久久国产
|
亚洲精品无码久久久
|
欧美精品久久久久久久自慰
|
久久久久国产精品
|
国产成人精品综合久久久久
|
久久精品国内一区二区三区
|
久久这里有精品视频
|
人妻精品久久无码专区精东影业
|
亚洲成色999久久网站
|
久久天天躁狠狠躁夜夜不卡
|
青青草国产成人久久91网
|
久久婷婷国产剧情内射白浆
|