English 中文(简体)
我如何根据Ipv6地址部分建立一个黑板的表格?
原标题:How do I create a hash table based on an Ipv6 address segment?

我有特克斯特案,其中载有普韦6号地址范围和其他信息,如:

minip                     maxip                  border      ...
2001::  2001:0:ffff:ffff:ffff:ffff:ffff:ffff    domestic    nan Hurricane Electric LLC  nan nan nan nan nan nan
2001:1::    2001:1:ffff:ffff:ffff:ffff:ffff:ffff    outbound    nan nan nan nan nan nan nan nan
2001:2::    2001:3:ffff:ffff:ffff:ffff:ffff:ffff    outbound    nan nan nan nan nan nan nan nan
2001:4::    2001:4:ff:ffff:ffff:ffff:ffff:ffff  outbound    nan nan nan nan nan nan nan nan
2001:4:1000::   2001:4:1fff:ffff:ffff:ffff:ffff:ffff    outbound    nan nan nan nan nan nan nan nan

It contains millions of records, I want to create a hash map use the records. And other modules can query the hash table and get corresponding information by given an ipv6 address. The problem is How can i generate hash key from the minip and maxip, eg: minip = 2001::, maxip = 2001:0:ffff:ffff:ffff:ffff:ffff:ffff, and the query ipv6 address is 2001:0:50:124:70:65:80:214. If I generate the hash key with high 4 Bytes, there can be a long chain of conflicts and the query efficiency is low. eg:

2001:250:2::    2001:250:2:ffff:ffff:ffff:ffff:ffff domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:3::    2001:250:3:ffff:ffff:ffff:ffff:ffff domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:4::    2001:250:4:ffff:ffff:ffff:ffff:ffff domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:5::    2001:250:5:ffff:ffff:ffff:ffff:ffff domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:6::    2001:250:7:ffff:ffff:ffff:ffff:ffff domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:8::    2001:250:f:ffff:ffff:ffff:ffff:ffff domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:10::   2001:250:1f:ffff:ffff:ffff:ffff:ffff    domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:20::   2001:250:3f:ffff:ffff:ffff:ffff:ffff    domestic    nan  nan  nan  nan  86  110000  110000  51
2001:250:40::   2001:250:5f:ffff:ffff:ffff:ffff:ffff    domestic    nan  nan  nan  nan  86  110000  110000  51

Also, I can t use every class C network number as a Hash key like IPv4 does. IPv6 address is 128 bits, and ipv6 does not have a clear network division. If you use the first 8 Bytes as network numbers, there may be many network numbers in each record belonging to [minip, maxip]. At the same time, this does not guarantee that the conflict chain is relatively short, and will cause a lot of memory consumption. How can I design a hash map so that memory consumption is within acceptable limits and queries are as efficient as possible?

问题回答

页: 1 你已经表示,这或许对普韦4来说是可行的,但随着普韦6的到来,它就变得不舒服。

I d treat the ipv6 address (16 bytes) as a fixed 16 byte string, not worrying [too much] about which part is the network part and the address part.

Then, the problem is [somewhat] similar to a word/dictionary lookup.

就在同一个页上,这里是我的50个拼写回答之一:cs50 pset5 Speller 优化

请注意,我的最后版本使用了记名员的分配库。 这有助于尽量减少记忆的分散。

并且,每个节点都保留了散面价值,因此,在寻找特定海面表条目的相关节点清单时,首先比较了32倍光面面面值,而不是全方位,只有对面值相对应的全方位比较。


链接中的散列函数有些简单。 散列函数的质量是关键:我们希望有一只 has子,在 b子里平均分配价值。 而且,我们希望散射功能迅速。

一种非常有用的资源被永久混为一谈。 它不再存在,而是存档:

  1. Tutorials
  2. Hash Tables
  3. Introduction to Hashing

发现的一个更好的散列功能是perl。 [因为它有许多洗 has,它需要好好]。 这实际上是民族阵线。 而且,它被视为是《公约》的状态。 在这方面,我自己的一些法典重新实施:

// strhash -- calculate a string hash
uint32_t
strhash(const void *bf,size_t bflen)
{
    const uint8_t *bp;
    const uint8_t *bfe;
    uint32_t hash;

    bp = bf;
    bfe = bp + bflen;

    hash = 0x37FB26C5;

    for (;  bp < bfe;  ++bp) {
        hash += *bp;
        hash += hash << 10;
        hash ^= hash >> 6;
    }

    hash += hash << 3;
    hash ^= hash >> 11;
    hash += hash << 15;

    return hash;
}

All of the above uses a single hash table lookup.

We might do better with nested hash tables. A top hash table using the network part. Then, each network entry points to a separate hash table for node part.

Then, each hash node only needs to hold the hash entry and an 8 byte value (vs. a 16 byte value).





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签