English 中文(简体)
从头开始创造出一个哈希姆? [闭门]
原标题:Creating a Hashtable from scratch? [closed]

我正在起草一个方案,将用一份文件中的话语及其使用频率和行号。 我认为,当我被告知,你必须从头开始开一个黑板的桌子时,我就已经结束。 我不知道何时开始。 欢迎对起点和启动方式的任何建议。

最佳回答

散列表是一个重要和基本的数据结构。 可在http://en.wikipedia.org/wiki/Hash_table”rel=“noreferer”上读更多。 Wikipedia s Hash table article 。 幸运的是,它们很容易执行。

基本上,一个散列表是数据结构,具有关键意义,回报或为这一关键人物储存价值。

核心内容通常是使用一个阵列加以实施,我们称之为<条码>。 因此,关键价值乳制品储存在arr[key.hashCode()%arr.length]。 通知说,由于你的阵列时间不定,且<代码>hashC ode/code>没有保证产生独特的价值,你最终将用标明阵列相同指数的关键。 页: 1

One way of resolving these collisions is to store a linked list for each member of arr. Then the definition of arr would look like this

LinkedList<Object> arr[];

标号为<代码>arr[key.hashCode()%arr.length]的所有物体将列入该职位名单。 当你想从表中提取物体时,跳跃到在<编码>上的链接清单中,[关键.hashCode()%arr.length],并在发现钥匙为<代码>的关键数值时通过相关名单的每个成员检索。

良好的单表执行方式可能与转版arr等。 它一度过于全面。

问题回答

1. 设立一个股, 你们需要牢记你们想要建设的结构。 名录有2个要素、一套关键和一套价值。 思考你如何代表这些要素,以及你如何确保这些关键因素总是能够显示出适当的价值。

其次,思考一下你的作用。 认为没有“正确”散列函数。 你们刚刚需要与你一起工作。

Once these two things are taken care of, the rest is simple. Writing methods to work on the two sets are basically just a matter of cleverly using the hash function.

Good Luck!

附加说明:认为该表的价值等级不一定与关键等级相同。 保留桶子的概念。 这一点非常重要。

仅用一个阵列供您发言。 伤者需要洗衣功能和装货系数。 装载系数将决定你何时重新编制表格以保持其效率。 插图的简单散列功能是,将每个特性的体值加起来,乘以2^(焦炭指数),并将这一数值按表长度加以改动。 e.g.

static int hash(String s) {
    int len = 30;
    int sum = 0;
    for(int i = 0; i < s.length(); i++) {
        sum += ((int)s.charAt(i)) * (1<<i);
    }
    return sum%len;
}

You could use String.hashCode too. To resolve collisions the simplest method to use is linear probing, but clustering will occur quickly. You can implement double hashing for better performance.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签