class Distributor: def __init__(self, distributorName): self.distributorName = distributorName self.includes = BinarySearchTree() self.excludes = [BinarySearchTree()] def addIncludePermission(self, startID, endID, parentDistributorNode): if (parentDistributorNode == None): self.includes.insertNode(self.includes.root, startID, endID) else: isPresentInParentInclude = parentDistributorNode.includes.isInRange( parentDistributorNode.includes.root, startID, endID) isPresentInParentExclude = self.checkExcludes( parentDistributorNode, startID, endID) if (isPresentInParentInclude and not (isPresentInParentExclude)): self.includes.insertNode(self.includes.root, startID, endID) elif (isPresentInParentExclude): return 0 return 1 def checkExcludes(self, node, startID, endID): for i in range(len(node.excludes)): isPresent = node.excludes[i].isInRange(node.excludes[i].root, startID, endID) if (isPresent): return isPresent return False def addExcludePermission(self, startID, endID): isPresent = self.includes.isInRange(self.includes.root, startID, endID) if (isPresent): self.excludes[0].insertNode(self.excludes[0].root, startID, endID) return 1 else: return 0