Module to handle spacemaps

Diff
anonymous

Diff

Differences From Artifact [6e71065e5d]:

To Artifact [292e80c547]:


1
2
3
4
5
6
7
8
class SpaceMap:
	''' Here we have:
	__bottom - minimum space address possible;
	__top - maximum space address possible;
	__pairs - internal list of ranges;
	__walk_list - internal list of keys.'''

	__slots__ = frozenset(('__bottom', '__pairs', '__top', '__walk_list'))
|







1
2
3
4
5
6
7
8
class SpaceMap(object):
	''' Here we have:
	__bottom - minimum space address possible;
	__top - maximum space address possible;
	__pairs - internal list of ranges;
	__walk_list - internal list of keys.'''

	__slots__ = frozenset(('__bottom', '__pairs', '__top', '__walk_list'))
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
		else:
			return(None)

	def __set(self, name, value):
		'''Internal function to add ranges without folding. Also checks for range correctness.'''
		if type(name) != int or type(value) != int or name >= value:
			return(False)
		if not self.__bottom == None:
			if name < self.__bottom or value < self.__bottom:
				return(False)
		if not self.__top == None:
			if name >= self.__top or value >= self.__top:
				return(False)
		self.__pairs[name] = value
		return True

	def __setitem__(self, name, value):
		'''Adds one more range and tries to fold a space map.'''







|


|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
		else:
			return(None)

	def __set(self, name, value):
		'''Internal function to add ranges without folding. Also checks for range correctness.'''
		if type(name) != int or type(value) != int or name >= value:
			return(False)
		if self.__bottom != None:
			if name < self.__bottom or value < self.__bottom:
				return(False)
		if self.__top != None:
			if name >= self.__top or value >= self.__top:
				return(False)
		self.__pairs[name] = value
		return True

	def __setitem__(self, name, value):
		'''Adds one more range and tries to fold a space map.'''
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

	def __repr__(self):
		'''Returns the inner dict with ranges.'''
		return(repr(self.__pairs))

	def __and__(self, other):
		'''Returns new space map with ranges that appears both in A and B.'''
		if not type(other) == SpaceMap:
			return(False)
		new = {}
		self.rewind()
		other.rewind()
		my_pair = self.pop()
		other_pair = other.pop()
		# if there are no pairs in B - we have nothing to do







|







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

	def __repr__(self):
		'''Returns the inner dict with ranges.'''
		return(repr(self.__pairs))

	def __and__(self, other):
		'''Returns new space map with ranges that appears both in A and B.'''
		if type(other) != SpaceMap:
			return(False)
		new = {}
		self.rewind()
		other.rewind()
		my_pair = self.pop()
		other_pair = other.pop()
		# if there are no pairs in B - we have nothing to do
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
						all_parts_found = True
		self.clear()
		other.clear()
		return(SpaceMap(new, self.__bottom, self.__top))

	def __sub__(self, other):
		'''Returns new space map with ranges in A not covered by B.'''
		if not type(other) == SpaceMap:
			return(False)
		new = {}
		self.rewind()
		other.rewind()
		my_pair = self.pop()
		other_pair = other.pop()
		# if there are no pairs in B - copy this one to new SpaceMap







|







177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
						all_parts_found = True
		self.clear()
		other.clear()
		return(SpaceMap(new, self.__bottom, self.__top))

	def __sub__(self, other):
		'''Returns new space map with ranges in A not covered by B.'''
		if type(other) != SpaceMap:
			return(False)
		new = {}
		self.rewind()
		other.rewind()
		my_pair = self.pop()
		other_pair = other.pop()
		# if there are no pairs in B - copy this one to new SpaceMap