如何实现哈希表 [英] how to implement hashtable

查看:112
本文介绍了如何实现哈希表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想为以下情况实现哈希表.

我在类似表的数据中.

型号零件号
xxx iu 234
ZZZ 123
yyy 213
abc 890
xxx 234


我想追踪模型重复多少次.如果模型已经在哈希表中,则我想增加模型计数,否则将其添加到哈希表中.

但是在我的代码中,当它包含模型时,它的更新值.
我不知道如何实施,请帮助我.

还有另一个问题,我应该增加键值(何时将其添加到哈希表中)?

下面是我如何实现的代码...

我把所有这些行都放入了数据行.
通过循环到数据行,我想为modelnumber实现哈希表.


Hi,

i want to implement hashtable for the below scenario.

i have data in a table like.

Model Number Part number
xxx iu 234
ZZZ 123
yyy 213
abc 890
xxx 234


i want to trace how many times a model is repeated. and if the model is already in hashtable i want to increment model count else add it to hashtable.

but in my code it''s updating value when it contains a model.
i dono how to implement pls help me.

and another question should i increment key value (when ever i added to hashtable)?

below is code how i am implementing...

i got all these rows into a datarow.
By looping into datarow,i want to implement hashtable for modelnumber.


For Each aceDAERow In aceDAERows

 If aceDAERowHash.ContainsValue(aceDAERow.Item("Model_Number")) Then
        aceDAERowHash(modelnumber) = aceDAERowHash(modelnumber) + 1
 Else
       aceDAERowHash.Add(modelnumber, aceDAERow.Item("Model_Number"))
 End If
 modelnumber = modelnumber + 1

 Next




在此先谢谢您.




Thanks in advance.

推荐答案

我认为这可以解决问题(注意-我没有对此进行测试,因此您可能需要对其进行调整).

I think this will work (caveat - I didn''t test this, so you may need to tweak it).

Dim hash As New Dictionary(Of String, Integer)()

If hash.Containskey(name) Then
	hash(name).Value += 1
Else
	hash.Add(name, 1)
End If


这篇关于如何实现哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆