我们在网络中有4个流,并为每个流分配一条路由。因此,在python中,我们可以:
dictFlowRoute = {"flow1":(1,2,3,4), #flow1 is sent by node 1 to node 4.
"flow2":(1,5,3,4),
"flow3":(1,2,5,3),
"flow4":(2,3,1,5)}
基于给定的路由(dictFlowRoute),我们可以知道每对节点传输哪些流例如,“流1”和“流3”通过节点对(1,2)传输在python中,我们可以生成另一个字典来存储这些数据
dictNodePairwithFlow = { (1,2):("flow1","flow3"),
(2,3): ("flow1","flow4"),
(3,4): ("flow1","flow2"),
(1,5): ("flow2", "flow4"),
(5,3): ("flow2","flow3")}
P>因此,在C++中,如何给出 DealFraseRead EEE>,以及如何根据给定的 DealFraseRouth[EEM><
Python的} 和^{} 。主要区别在于
Dictionary
数据类型是associative array。在C++中,我们有两个选项可以选择,^{std::map
使用Self Balancing Red-Black Tree,而std::unordered_map
使用Hash Table实现。正因为如此,std::unordered_map
通常比std::map
快对于你的情况,我将用
std::unordered_map
来演示。与Python不同,我们不使用Key:Value
来初始化映射,而是可以使用[]
操作符附加:^{} ,^{}
相关问题 更多 >
编程相关推荐