本文整理汇总了Python中Bio.Pathway.Rep.HashSet类的典型用法代码示例。如果您正苦于以下问题:Python HashSet类的具体用法?Python HashSet怎么用?Python HashSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HashSet类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testList
def testList(self):
a = HashSet(['a', 'b', 'c', 'd', 'e'])
l = a.list()
l.sort()
self.assertEqual(l, ['a', 'b', 'c', 'd', 'e'], "incorrect list")
l = []
self.assertTrue('e' in a, "set rep exposure")
示例2: remove_node
def remove_node(self, node):
"""Removes node and all edges connected to it."""
if node not in self.__adjacency_list:
raise ValueError("Unknown node: " + str(node))
# remove node (and all out-edges) from adjacency list
del self.__adjacency_list[node]
# remove all in-edges from adjacency list
for n in self.__adjacency_list:
self.__adjacency_list[n] = HashSet(filter(lambda x,node=node: x[0] is not node,
self.__adjacency_list[n].list()))
# remove all refering pairs in label map
for label in self.__label_map.keys():
lm = HashSet(filter(lambda x,node=node: \
(x[0] is not node) and (x[1] is not node),
self.__label_map[label].list()))
# remove the entry completely if the label is now unused
if lm.empty():
del self.__label_map[label]
else:
self.__label_map[label] = lm
示例3: testLen
def testLen(self):
a = HashSet()
self.assertEqual(len(a), 0, "incorrect default size")
a.add('a')
a.add('b')
self.assertEqual(len(a), 2, "incorrect size")
a.remove('b')
self.assertEqual(len(a), 1, "incorrect size after removal")
a.add('a')
self.assertEqual(len(a), 1, "incorrect size after duplicate add")
示例4: testLen
def testLen(self):
a = HashSet()
self.failUnless(len(a) == 0, "incorrect default size")
a.add('a')
a.add('b')
self.failUnless(len(a) == 2, "incorrect size")
a.remove('b')
self.failUnless(len(a) == 1, "incorrect size after removal")
a.add('a')
self.failUnless(len(a) == 1, "incorrect size after duplicate add")
示例5: testSetOps
def testSetOps(self):
n = HashSet()
a = HashSet(['a', 'b', 'c'])
b = HashSet(['a', 'd', 'e', 'f'])
c = HashSet(['g', 'h'])
# union
self.assertEqual(a.union(b), HashSet(['a','b','c','d','e','f']), "incorrect union")
self.assertEqual(a.union(n), a, "incorrect union with empty set")
# intersection
self.assertEqual(a.intersection(b), HashSet(['a']), "incorrect intersection")
self.assertEqual(a.intersection(c), HashSet(), "incorrect intersection")
self.assertEqual(a.intersection(n), HashSet(), "incorrect intersection with empty set")
# difference
self.assertEqual(a.difference(b), HashSet(['b','c']), "incorrect difference")
self.assertEqual(a.difference(c), HashSet(['a','b','c']), "incorrect difference")
self.assertEqual(b.difference(a), HashSet(['d','e','f']), "incorrect difference")
# cartesian product
self.assertEqual(a.cartesian(c), HashSet([('a','g'),('a','h'),
('b','g'),('b','h'),
('c','g'),('c','h')]),
"incorrect cartesian product")
self.assertEqual(a.cartesian(n), HashSet(), "incorrect cartesian product")
示例6: testContains
def testContains(self):
n = HashSet()
self.assertTrue('a' not in n, "element in empty set")
self.assertTrue(not n.contains('a'), "element in empty set (2)")
a = HashSet(['a','b','c','d'])
self.assertTrue('a' in a, "contained element not found")
self.assertTrue('d' in a, "contained element not found")
self.assertTrue('e' not in a, "not contained element found")
self.assertTrue(68 not in a, "not contained element found")
self.assertTrue(a.contains('a'), "contained element not found (2)")
self.assertTrue(a.contains('d'), "contained element not found (2)")
self.assertTrue(not a.contains('e'), "not contained element found (2)")
self.assertTrue(not a.contains(68), "not contained element found (2)")
示例7: children
def children(self, parent):
"""Returns a list of unique children for parent."""
s = HashSet([x[0] for x in self.child_edges(parent)])
return s.list()
示例8: parents
def parents(self, child):
"""Returns a list of unique parents for child."""
s = HashSet([x[0] for x in self.parent_edges(child)])
return s.list()
示例9: species
def species(self):
"""Returns a list of the species in this system."""
s = HashSet(reduce(lambda s,x: s + x,
[x.species() for x in self.reactions()], []))
return s.list()
示例10: __init__
def __init__(self, reactions = []):
"""Initializes a new System object."""
self.__reactions = HashSet(reactions)