Skip to content
Snippets Groups Projects
Commit d11e1c14 authored by Chris's avatar Chris
Browse files

Add len operator for BSet + minor fixes.

parent b9858f2e
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ from btypes.BString import * ...@@ -4,7 +4,6 @@ from btypes.BString import *
from btypes.BStruct import * from btypes.BStruct import *
class BSet: class BSet:
def __init__(self, *args): def __init__(self, *args):
...@@ -28,6 +27,9 @@ class BSet: ...@@ -28,6 +27,9 @@ class BSet:
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __len__(self):
return len(self.__set)
def union(self, other=None): def union(self, other=None):
if other is None: if other is None:
if len(self.__set) == 0: if len(self.__set) == 0:
...@@ -112,7 +114,7 @@ class BSet: ...@@ -112,7 +114,7 @@ class BSet:
start = BSet() start = BSet()
queue = [start] queue = [start]
result = result.union(BSet(start)) result = result.union(BSet(start))
while not len(queue) == 0: while not (len(queue) == 0):
currentSet = queue.pop() currentSet = queue.pop()
for element in self.__set: for element in self.__set:
nextSet = currentSet.union(BSet(element)) nextSet = currentSet.union(BSet(element))
...@@ -245,5 +247,5 @@ class BSet: ...@@ -245,5 +247,5 @@ class BSet:
def __iter__(self): def __iter__(self):
return iter(self.__set) return iter(self.__set)
#Import is at the bottom due to cyclic dependencies
from btypes.BRelation import * from btypes.BRelation import *
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment