def rotate(self,n=1): result = super().__getattr__('rotate')(n) surrogate = runner.get_surrogate(self) if n < 0: m = -n % len(self) while m: DequeSurrogate.append(surrogate, DequeSurrogate.popleft(surrogate)) m -= 1 if n > 0: m = n % len(self) while m: DequeSurrogate.appendleft(surrogate, DequeSurrogate.pop(surrogate)) m -= 1
def __setitem__(self, key, value): result = super().__setitem__(key, value) surrogate = runner.get_surrogate(self) DequeSurrogate.setval(surrogate,key, value) return result
def __delitem__(self, key): result = super().__getitem__(key) surrogate = runner.get_surrogate(self) DequeSurrogate.delete(surrogate,key) return result
def remove(self, value): result = super().__getattr__('remove')(value) surrogate = runner.get_surrogate(self) DequeSurrogate.remove(surrogate, value) return result
def reverse(self): result = super().__getattr__('reverse')() surrogate = runner.get_surrogate(self) DequeSurrogate.reverse(surrogate) return result
def extendleft(self, elems): result = super().__getattr__('extendleft')(elems) surrogate = runner.get_surrogate(self) for el in elems: DequeSurrogate.appendleft(surrogate, el) return result
def clear(self, *args, **kwargs): result = super().__getattr__('clear')(*args, **kwargs) surrogate = runner.get_surrogate(self) DequeSurrogate.clear(surrogate,*args, **kwargs) return result
def popleft(self, *args, **kwargs): result = super().__getattr__('popleft')(*args, **kwargs) surrogate = runner.get_surrogate(self) DequeSurrogate.popleft(surrogate,*args, **kwargs) return result
def append(self, *args, **kwargs): result = super().__getattr__('append')(*args, **kwargs) surrogate = runner.get_surrogate(self) DequeSurrogate.append(surrogate,*args, **kwargs) return result
def stringify(self, obj): t = type(obj) if t in primitives: if t == float and obj == float('inf') or obj == -float('inf'): pass else: return obj if t in others: _id = self.gen_id(5, 5) if t == tuple: if self.map.has(obj): return self.map.get(obj) c = [] for item in obj: c.append(self.stringify(item)) self.types[_id] = c self.map.add(obj, _id) else: self.types[_id] = str(obj) return _id else: type_name = t.__name__ if self.map.has(obj): return self.map.get(obj) new_id = self.gen_id(5, 3) self.map.add(obj, new_id) i = 0 if isinstance(obj, (dict, Counter, OrderedDict)): copy = {} for key, value in obj.items(): copy[i] = [self.stringify(key), self.stringify(value)] obj[key] = self.virtualize(value) i += 1 self.objects[new_id] = copy elif isinstance(obj, (list)): copy = {} for i in range(len(obj)): val = obj[i] copy[i] = self.stringify(val) obj[i] = self.virtualize(val) copy['length'] = len(obj) self.objects[new_id] = copy elif isinstance(obj, set): copy = {} for value in obj: copy[i] = self.stringify(value) obj.discard(value) obj.add(self.virtualize(value)) i += 1 self.objects[new_id] = copy elif isinstance(obj, deque): surrogate = DequeSurrogate([self.virtualize(v) for v in obj]) new_id = self.stringify(surrogate) self.map.add(obj, new_id) self.virtualize_surrogate(obj, surrogate) elif hasattr(obj, '__dict__'): copy = {} for key, value in obj.__dict__.items(): if key[0] == '_': continue copy[key] = self.stringify(value) obj.__dict__[key] = self.virtualize(value) i += 1 self.objects[new_id] = copy else: new_id = self.gen_id(5, 5) self.map.add(obj, new_id) self.types[new_id] = str(obj) return new_id if i > 1000: raise Exception( f'{type_name} is too large. All objects are limited to 1000 elements.' ) if t in collections_types: type_name = 'collections.' + type_name elif t in queue_types: type_name = 'queue.' + type_name elif t in viz_types: type_name = 'viz.' + type_name ln = len(self.steps) if ln not in self.objectIndex: self.objectIndex[ln] = [] self.objectIndex[ln].append(new_id) self.types[new_id] = type_name return new_id