简体   繁体   English

Patricia Trie用于快速检索IPv4地址和卫星数据

[英]Patricia Trie for fast retrieval of IPv4 address and satellite data

I am writing a program in C++ that requires IP addresses( all IPv4) to be looked up and stored in a fast way. 我正在用C ++编写一个程序,该程序需要快速查找和存储IP地址(所有IPv4)。 Every IP address has a data associated with it. 每个IP地址都有一个与之关联的数据。 In case it already exists in the trie, I intend to merge the data of the IP address in the trie with the new addresses data. 如果在Trie中已经存在,我打算将Trie中IP地址的数据与新的地址数据合并。 If it is not present, I intend to add it as a new entry to the trie. 如果不存在,我打算将其添加为该Trie的新条目。 Deletion of IP address is not necessary. 无需删除IP地址。

In order to implement this, I need to design a Patricia Trie. 为了实现这一点,我需要设计一个Patricia Trie。 However, I am unable to visualize the design beyond this. 但是,我无法将设计可视化。 It seems quite naive of me, but the only idea that came to my mind was to change the IP address to their binary form and then use the trie. 我似乎很天真,但是我想到的唯一想法是将IP地址更改为二进制格式,然后使用trie。 I am however clueless about HOW exactly to implement this. 但是,我对如何确切地实现此目标一无所知。

I would be really thankful to you if you could help me with this one. 如果您能帮助我,我将非常感谢您。 Please note that I did find a similar question here . 请注意,我确实在这里找到了类似的问题。 The question or more specifically the answer was beyond my understanding as the code in the CPAN web site was not clear enough for me. 这个问题或更确切的答案是我无法理解的,因为CPAN网站上的代码对我来说还不够清楚。

Also note, my data is the following format 另请注意,我的数据是以下格式

10.10.100.1: "Tom","Jack","Smith" 10.10.100.1:“汤姆”,“杰克”,“史密斯”

192.168.12.12: "Jones","Liz" 192.168.12.12:“琼斯”,“丽兹”

12.124.2.1: "Jimmy","George" 12.124.2.1:“吉米”,“乔治”

10.10.100.1: "Mike","Harry","Jennifer" 10.10.100.1:“Mike”、“Harry”、“Jennifer”

I think you are referring to a RadixTree . 我认为您指的是RadixTree I have an implementation of a RadixTrie in Java, if you want to use that as a starting point, which does the actual key to value mapping. 我想用Java实现RadixTrie的实现,如果您想将其用作起点,它会执行到值映射的实际键。 It uses a PatriciaTrie as it's backing structure. 它使用PatriciaTrie作为支持结构。

Example using the following strings. 使用以下字符串的示例。

  1. 10.10.101.2 10.10.101.2
  2. 10.10.100.1 10.10.100.1
  3. 10.10.110.3 10.10.110.3

Trie example (uncompressed) Trie示例(未压缩)

└── 1
    └── 0
        └── .
            └── 1
                └── 0
                    └── .
                        └── 1
                            ├── 0
                            │   ├── 1
                            │   │   └── .
                            │   │       └── (2) 10.10.101.2
                            │   └── 0
                            │       └── .
                            │           └── (1) 10.10.100.1
                            └── 1
                                └── 0
                                    └── .
                                        └── (3) 10.10.110.3

Patricia Trie (compressed) 帕特里夏·特里(压缩)

└── [black] 10.10.1
    ├── [black] 0
    │   ├── [white] (0.1) 00.1
    │   └── [white] (1.2) 01.2
    └── [white] (10.3) 10.10.110.3

Patricia tries solve the problem of finding the best covering prefix for a given IP address (they are used by routers to quickly determine that 192.168.0.0/16 is the best choice for 192.168.14.63, for example). Patricia尝试解决为给定IP地址找到最佳覆盖前缀的问题(例如,路由器使用它们来快速确定192.168.0.0/16是192.168.14.63的最佳选择)。 If you are just trying to match IP addresses exactly, a hash table is a better choice. 如果您只是想完全匹配IP地址,那么哈希表是一个更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM