我想加快顶点/边属性访问过程。
对于顶点属性访问,我找到了一种优化方法,但是对于边属性访问,这对我来说并不是那么微不足道。
vertex 属性的思路是直接修改内部数组(a 属性)。
例如
vfilt = g.new_vertex_property('bool')
for i in range(9999):
vfilt.a[int(i % n)] = random.randint(0, 1)
(注意 vfilt.a 而不是 vfilt)
而不是使用:
vfilt = g.new_vertex_property('bool')
for i in range(9999):
vfilt[int(i % n)] = random.randint(0, 1)
然而,对于边缘,我不确定边缘与其在属性数组中的内部索引之间的映射。
我的问题是:
- 如何优化边缘属性访问?
- 还有其他方法可以优化顶点属性吗?
请您参考如下方法:
怎么样
for e in g.edges():
vfilt[e] = random.randint(0, 1)
类似地,对于顶点:
for v in g.vertices():
vfilt[v] = random.randint(0, 1)
