2. 305"Vt́pi"mj噂 p (Match)
2.8 Generic Dictionary trong C#
A吋 8違m b違q"8瓜 ph泳c t衣r"ejq"eƒe"rjfir"vqƒp"vj‒ọ"z„c"x "v·o"mk院m v噂k"8k隠u ki羽p"Ð?Ñ n "Q*3+."Igpgtke"Fkevkqpct{"8逢嬰e"z¤{"f詠ng d詠c"vt‒p"o瓜t b違pi"d<o"*jcuj"
table). B違pi" d<o" *jcuj" vcdng+" n " o瓜t c医w" vt¿e" f英 li羽u bao g欝m m瓜t m違pi" eƒe" ÐdwemgvuÑ"f́pi"8吋 ch泳c"eƒe"rj亥n t穎0"Eƒej"vj泳c b違pi"d<o"z穎 n#"swƒ"vt·pj"ejflp"o瓜t ph亥n t穎 m噂k"8逢嬰c th詠c hi羽n b茨ni"eƒej"vt ej"zw医v"tc"o«"d<o"*jcuj"eqfg+"ejq"v瑛ng
8嘘k"v逢嬰ng. Nh運 o«"d<o"8„"o "vc"e„"vj吋zƒe"8鵜pj"8逢嬰e"ej pj"zƒe"dwemgv"8吋8員t item
*vj»pi"vj逢運ng th詠c hi羽n b茨ng nh英pi"rjfir"v pj"8挨p"ik違p"8吋 8k隠u ch雨pj"o«"d<o"e栄a m瓜v"8嘘k"v逢嬰pi"ejq"rj́"j嬰p v噂k"m ej"vj逢噂c c栄a m違pi"eƒe"dwemgvu"- 荏 8¤{"n "j o"
modulo). B違pi"d<o"u胤 t詠 m荏 r瓜ng khi s嘘 n逢嬰ng ph亥n t穎 x逢嬰v"swƒ"m ej"vj逢噂c cho
rjfir"*o荏 r瓜ng theo s嘘piw{‒p"v嘘 prime number).
J o"d<o"o "Fkevkqpct{"vtqpi"E%"vj逢運ng s穎 d映pi"n "o瓜v"j o"xktvwcn"ucw<
public virtual int GetHashCode( )
J o" p {" n " o瓜t trong nh英pi" j o" e„" u印n trong System.Object.
U{uvgo0Qdlgev"n "n噂r"e挨"d違p"o "v医t c違eƒe"8嘘k"v逢嬰pi"vtqpi"E%"8隠u th瑛a k院."fq"8„"vc" jq p"vq p"e„"vj吋 override l衣k"j o"p {"ejq"rj́"j嬰p v噂k"{‒w"e亥ụ T医t c違 eƒe"vjcq"vƒe" pj逢"vj‒ọ"z„c."v·o"mk院o"8隠u c„"nk‒p"swcp"v噂k"j o"IgvJcujEqfg"p {0"Vw{"pjk‒p"o«" d<o"vt違 v隠 b荏k"j o"vt‒p"mj»pi"rj違k"n "x»"j衣n (Int32 Î pij c"n "v嘘k"8c"432 ikƒ"vt鵜 e„"
th吋8逢嬰c tr違 v隠 b荏k"j o"vt‒p+."pj逢"x壱{"jq p"vq p"e„"vj吋 x違{"tc"8映pi"8瓜 (collision).
Eqnnkukqp" pij c"n " jck" rj亥n t穎 mjƒe"pjcw"pj逢pi"n衣k"e„"épi" o«"d<o" x "pj逢"x壱y
ej¿pi"n衣i n茨o"épi"x鵜 vt "dwemgv0"F衣pi"d<o"e栄c"Fkevkqpct{"n "f衣pi"d<o"o荏 (cho
rjfir"mj„c"e„"épi"8鵜a ch雨, n¿e"p {"o厩i m映e"8鵜a ch雨 s胤n "o瓜v"fcpj"uƒej"nk‒p"m院v"eƒe"
ph亥n t穎e„"épi"8鵜a ch雨)
Rj逢挨pi"rjƒr"ik違i quy院v"8映pi"8瓜:
Dictionary x穎n#"8映pi"8瓜 b茨pi"rj逢挨pi"rjƒr"ÐejckpkpiÑ<"u穎 d映pi"jck"cttc{"e„" épi"u嘘 ph亥n t穎
- Buckets array: ch泳a ch雨 m映e"o "8嘘k"v逢嬰pi"8逢嬰e"n逢w"vt英 trong m違ng bucket - Entries array: ch泳c"eƒe"rj亥n t穎 th壱t s詠 8逢嬰e"n逢w"vt英 n院u n茨o"vtqpi"épi"
J·pj"2.10 Minh h丑c"eƒej"z穎n#"8映pi"8瓜 trong b違pi"d<o
Pj逢"j·pj"x胤 vt‒p."vc"vj医y n院w"pj逢"4"8嘘k"v逢嬰pi"Qdl3"x "Qdl4"8逢嬰e"d<o"x q" épi"o瓜t v鵜vt ."vj·"Fkevkqpct{"u胤n逢w"vt英4"8嘘k"v逢嬰pi"8„"x q"o瓜v"fcpj"uƒej"nk‒p"m院t.
N院w"pj逢"vc"ow嘘p"v·o"mk院o"Qdl3"x "Qdl4"vj·"vc"e亥n ph違i t嘘p"vj‒o"ejk"rj "
duy羽v"fcpj"uƒej"nk‒p"m院v"p {"x "uq"vt́pi"jck"rj亥n t穎 (tham chi院u) b茨pi"j o"Equal( ) 8逢嬰c cung c医p s印n.
T瑛 e挨"u荏 n#"vjw{院v"vt‒p."vc"vj医{"8逢嬰c ejk"rj "vtwpi"d·pj"mjk"v·o"mk院m m瓜t ph亥n t穎 n "v雨 s嘘 gi英a s嘘 ph亥n t穎 8cpi"e„"ejkc"ejq"m ej"vj逢噂c c栄a Dictionarỵ Tuy
pjk‒p"Fkevkqpct{"nw»p"e嘘 g逸pi"fw{"vt·"v雨 s嘘 gi英a s嘘 ph亥n t穎 p„"8cpi"ej泳c"x "m ej" vj逢噂c c栄c"p„"n "3-3"*m ej"vj逢噂e"Fkevkqpct{"mj»pi"pj臼 j挨p"u嘘n逢嬰pi"kvgo"vtqpi"8„+0" Fq"8„"ejk"rj "vtwpi"d·pj"zgo"pj逢"n "Q*3+0
EJ姶愛PI"5 <"EèE"EðPI"VTîPJ"PIJKçP"E永W"NKçP"SWCP 3.1 Eƒe"rj逢挨pi"rjƒr"v·o"oqvkh"vtqpi"f英 li羽u chu厩i th運i gian
3.103"Rj逢挨pi"rjƒr"v·o"oqvkh"8嘘i v噂k"e挨"u荏 d英 li羽u chu厩i th運i gian l噂n
Pj„o"vƒe"ik違R0Rcvgn."G0Mgqij."L0Nkp."U0Nqpctfk"*4224+"]39̲"8«"8隠 xu医t m瓜t
rj逢挨pi"rjƒr"v·o"oqvkhu"vt‒p"f英 li羽u chu厩i th運k"ikcp0"A亥w"vk‒p"j丑 ƒr"f映pi"rj逢挨pi" rjƒr"x医p x雨 g瓜p t瑛pi"8q衣n (PAA) 8吋 thu gi違m d英 li羽w."ucw"8„"e»pi"vt·pj"ejw{吋n chu厩i d英 li羽u sang d衣ng m "v詠 b茨pi"rj逢挨pi"rjƒr"UCZ0"Ew嘘k"épi"j丑 s穎 d映ng gi違i thu壱v"GOOC"8吋v·o"tc"oqvkh"e„"ejk隠w"f k"n ejq"vt逢噂c [17].
A員e"8k吋m c栄a gi違i thu壱v"GOOC"n "ƒr"f映ng m瓜v"j o"d<o"8吋 8逢c"eƒe"ejw厩i
eqp"v逢挨pi"v詠pjcw"x q"épi"o瓜v"8鵜a ch雨 vtqpi"dwemgv0"Vc"e pi"n逢w"vt英 v鵜 tt "d逸v"8亥u c栄a chu厩i trong b違pi" d<o0" Ucw" 8„" ik違i thu壱t s胤 ti院p" j pj" mj違q" uƒv" vt‒p" x鵜 vt " e„"
nhi隠u ph亥n t穎 nh医t (g丑k"n "ORE"Î Most Promising Candidate). Gi違i thu壱v"e pi"ƒr"
d映pi" e»pi" vj泳e" v pj" 8瓜 v逢挨pi" v詠 c栄a 2 chu厩k" eqp" 8吋 z¤{" f詠ng t壱p n¤p" e壱n g欝m nh英ng ph亥n t穎vtqpi"ORE"x "pj英ng chu厩i con n茨m 荏 nh英ng v鵜 vt "mjƒe"pj逢pi"e„"8瓜 v逢挨pi"v詠 so v噂i ph亥n t穎 trong MPC v磯n nh臼j挨p"o瓜v"vj»pi"u嘘T"fq"pi逢運k"f́pi"n詠a ch丑n.
Ucw"8„"pj„o"vƒe"ik違 s穎 d映ng gi違i thu壱t ADM fq"Ujcujc"x "Ycpi"8隠 xu医t [52] 8吋 v·o"eƒe"oqvkh"vj壱t s詠 (true-motif) t瑛 t壱p 泳pi"xk‒p"8«"e„0"N#"fq"vc"rj違k"f́pi"
gi違i thu壱v"CFO"n "x·"j o"v pj"mjq違pi"eƒej"荏vt‒p"ej雨 m噂k"ƒr"f映ng cho chu厩i d衣ng
m "v詠 p‒p"vc"rj違i ti院p"j pj"vj‒o"o瓜v"d逢噂c ki吋m tra kho違pi"eƒej"vj壱t s詠 荏 d英 li羽u g嘘e"8吋 xem m瓜t 泳pi"xk‒p"e„"vj壱t s詠n "oqvkh"jc{"mj»pi0"Swƒ"vt·pj"n員p l衣i cho t噂i khi
oqvkh"v·o"8逢嬰e"e„"u嘘 l亥n xu医t hi羽n l噂n nh医t (1 motif). Gi違i thu壱v"e„"vj吋 8逢嬰c m荏
r瓜pi"8吋 v·o"m"Î motif.
3.104"Rj逢挨pi"rjƒr"v·o"oqvkh"f詠c"vt‒p"OFN
[0Vcpcmc"x "M0Wgjctc"]41̲"8隠 xu医v"rj逢挨pi"rjƒr"v·o"oqvkh"f詠c"vt‒p"o瓜t gi違i thu壱v"e„"mj違 p<pi"v·o"8逢嬰e"8瓜 f k"vj運i kho違ng t嘘k"逢w"e栄a motif. Gi違i thu壱v"v·o"8瓜 f k" vj運i kho違ng t嘘k" 逢w" *qrvkowo" rgtkqf" ngpivj+" zw医v" rjƒv" v瑛 mjƒk" pk羽m MDL
(Minimum Description Length) - m瓜v"mjƒk"pk羽o"8逢嬰c 8隠 xu医t b荏i Rissanen (1989)
8逢嬰e"f́pi"8吋8ƒpj"ikƒ"8瓜 t嘘k"逢w"e栄a m瓜v"o»"j·pj"pi磯w"pjk‒p0"
E»pi"vt·pj"tc"8運i xu医v"rjƒv"v瑛 th詠c t院n "vj»pi"u嘘 chi隠w"f k"e栄a motif ph違i do
pi逢運k"f́pi"v詠 8鵜pj"pij c0"Ak隠w"p {"f磯p"8院n vi羽e"zƒe"8鵜nh chi隠w"f k"e栄a motif tr荏 vj pj" o瓜t v医p" 8隠 mj»pi" 8挨p" ik違n. N院w" pj逢" vc" ƒr" f映pi" eƒe" ik違i thu壱v" v·o" oqvkh" vj»pi"f映pi"pj逢"GOOC"x噂k"eƒe"ejk隠w"f k" oqvkh"mjƒe"pjcw"e„"vj吋 e„"vj·"t "t pi" rj逢挨pi"rjƒr"8„"mj»pi"mj違 vjk"x "mfio"jk羽u qu違0"Pj„o"vƒe"ik違 8«"8隠 xu医v"eƒej"v·o"
chi隠w"f k"oqvkh"v詠8瓜pi"vj»pi"swc"mjƒk"pk羽m MDL.
A亥w" vk‒p" e»pi" vt·pj" vk院p" j pj" ejw{吋p" 8鰻i chu厩i th運i gian g嘘c sang d衣ng chu厩k"m "v詠 b茨pi"eƒej"m院t h嬰r"rj逢挨pi"rjƒr"RCC"x "UCZ0"Ejk隠w"f k"e栄a c穎a s鰻 vt逢嬰v"n "Vmin ."8¤{"n "ikƒ"vt鵜 chi隠w"f k"pj臼 nh医v"e„"vj吋 e„"e栄c"oqvkh"fq"pi逢運k"f́pi" 8鵜nh ngj c0"Ew嘘k"épi"ucw"mjk"e„"8逢嬰e"eƒe"ejw厩k"eqp"f逢噂i d衣ng chu厩k"m "v詠."pj„o" vƒe"ik違iƒp"eƒe"m "v詠j pj"xk"ejq"v瑛ng chu厩k"eqp"8„0
Vi羽e"mjck"rjƒ"oqvkh"8逢嬰c chuy吋p"8鰻i t瑛 chu厩i d英 li羽u th運i gian g嘘c sang
mjck"rjƒ"oqvkh"vt‒p"ejw厩k"m "v詠j pj"xk0
Swƒ"vt·pj"vt‒p"8逢嬰e"v„o"v逸v"pj逢"j·pj"x胤 sau:
Gi違i thu壱v"v·o"ejk隠w"f k"o磯u t嘘k"逢w8逢嬰e"v„o"v逸v"pj逢"ucw: T瑛 chu厩i
~
C gi違i thu壱t s穎 d映ng m瓜t c穎a s鰻 vt逢嬰t v噂i chi隠w"f k"e嘘 8鵜pj"vt逢嬰t
vt‒p"C~ 8吋 e„"8逢嬰e"eƒe"ejw厩i con. L亥p"n逢嬰v"zgo"zfiv"pj英ng m磯w"e„"u嘘 l亥n xu医t hi羽n nhi隠u nh医v"n " o磯u t嘘t nh医t c栄a chu厩k"m "v詠 hi羽n t衣k0"Ucw"8„"vc"v pj"j o" OFN"x "
chi隠w"f k"o磯u L1."vc"e pi"8欝ng th運k"n逢w"eqp"vt臼 P1 t噂i v鵜 vt "d逸v"8亥u c栄a m磯ụ Thay th院 m磯u b茨ng m瓜v"m "v詠mjƒe0"Swƒ"vt·pj"vt‒p"8逢嬰c l員p l衣i cho t噂k"mjk"mj»pi"e”p"o磯u
p q"zw医t hi羽p"j挨p"4"n亥n trong chu厩k"m "v詠.
Mjk"swƒ"vt·pj"rj¤p"v ej"vt‒p"jq p"vj pj."o磯w"e„"ikƒ"vt鵜 MDL nh臼 nh医v"8逢嬰c
zgo"n "o磯u t嘘t nh医t trong
~
C. S穎 d映ng chi隠w"f k"o磯w"n "Np, chi隠w"f k"v嘘k"逢w"e栄a
oqvkh"8逢嬰e"v pj"pj逢"ucw<
Topt = Tmin + Lp
Ta xem m磯w"p {"n "泳pi"xk‒p"e栄c"oqvkh0"Ucw"8„"pj„o"vƒe"ik違 s穎 d映ng gi違i thu壱v"GOOC"8吋 v·o"oqvkh"th壱t s詠 v噂i t壱p 泳pi"xk‒p"ORE"ej pj"n "v壱p 泳pi"xk‒p"vc"
v瑛c"v·o"vj医{"vtqpi"swƒ"vt·pj"rj¤p"v ej"荏vt‒p0