Module to handle spacemaps

Annotation For spacemap.py
anonymous

Annotation For spacemap.py

Origin for each line in spacemap.py from check-in bfe3da6658:

bfe3da6658 2010-10-14 c.kworr@f7677: class SpaceMap:
bfe3da6658 2010-10-14 c.kworr@f7677: 	''' Here we have:
bfe3da6658 2010-10-14 c.kworr@f7677: 	__bottom - minimum space address possible;
bfe3da6658 2010-10-14 c.kworr@f7677: 	__top - maximum space address possible;
bfe3da6658 2010-10-14 c.kworr@f7677: 	__pairs - internal list of ranges;
bfe3da6658 2010-10-14 c.kworr@f7677: 	__walk_list - internal list of keys.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	__slots__ = frozenset(('__bottom', '__pairs', '__top', '__walk_list'))
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __init__(self, source = None, bottom = 0, top = None):
bfe3da6658 2010-10-14 c.kworr@f7677: 		''' This one can be bootstrapped by giving a dict in format {x:y, x:y}.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__pairs = {}
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__walk_list = None
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__bottom = bottom
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__top = top
bfe3da6658 2010-10-14 c.kworr@f7677: 		if type(source) == dict:
bfe3da6658 2010-10-14 c.kworr@f7677: 			for key in source:
bfe3da6658 2010-10-14 c.kworr@f7677: 				self.__set(key, source[key])
bfe3da6658 2010-10-14 c.kworr@f7677: 			self.fold()
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __getitem__(self, name):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Returns last range address by first range address.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		if name in self.__pairs:
bfe3da6658 2010-10-14 c.kworr@f7677: 			return(self.__pairs[name])
bfe3da6658 2010-10-14 c.kworr@f7677: 		else:
bfe3da6658 2010-10-14 c.kworr@f7677: 			return(None)
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __set(self, name, value):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Internal function to add ranges without folding. Also checks for range correctness.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		if type(name) != int or type(value) != int or name >= value:
bfe3da6658 2010-10-14 c.kworr@f7677: 			return(False)
bfe3da6658 2010-10-14 c.kworr@f7677: 		if not self.__bottom == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 			if name < self.__bottom or value < self.__bottom:
bfe3da6658 2010-10-14 c.kworr@f7677: 				return(False)
bfe3da6658 2010-10-14 c.kworr@f7677: 		if not self.__top == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 			if name >= self.__top or value >= self.__top:
bfe3da6658 2010-10-14 c.kworr@f7677: 				return(False)
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__pairs[name] = value
bfe3da6658 2010-10-14 c.kworr@f7677: 		return True
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __setitem__(self, name, value):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Adds one more range and tries to fold a space map.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__set(name, value)
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.fold()
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def fold(self):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Tries to normalize spacemap by joining coaligned or overlapping ranges.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		pairs = ()
bfe3da6658 2010-10-14 c.kworr@f7677: 		while True:
bfe3da6658 2010-10-14 c.kworr@f7677: 			pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 			if pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 				break
bfe3da6658 2010-10-14 c.kworr@f7677: 			pairs += pair,
bfe3da6658 2010-10-14 c.kworr@f7677: 		last_pair = self.__bottom
bfe3da6658 2010-10-14 c.kworr@f7677: 		for pair in pairs:
bfe3da6658 2010-10-14 c.kworr@f7677: 			if last_pair in self.__pairs and pair[0] <= self.__pairs[last_pair] and pair[1] > self.__pairs[last_pair]:
bfe3da6658 2010-10-14 c.kworr@f7677: 				self.__pairs[last_pair] = pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 				del(self.__pairs[pair[0]])
bfe3da6658 2010-10-14 c.kworr@f7677: 			else:
bfe3da6658 2010-10-14 c.kworr@f7677: 				last_pair = pair[0]
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def rewind(self):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Reinitialises internal ordered list of ranges.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__walk_list = list(self.__pairs.keys())
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__walk_list.sort()
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def clear(self):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Clears internal ordered list of ranges.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.__walk_list = None
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def pop(self):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Returns next range from ordered list of ranges.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		if self.__walk_list != None:
bfe3da6658 2010-10-14 c.kworr@f7677: 			if len(self.__walk_list) > 0:
bfe3da6658 2010-10-14 c.kworr@f7677: 				next = self.__walk_list.pop(0)
bfe3da6658 2010-10-14 c.kworr@f7677: 				return([next, self.__pairs[next]])
bfe3da6658 2010-10-14 c.kworr@f7677: 		return([None, None])
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __repr__(self):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Returns the inner dict with ranges.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		return(repr(self.__pairs))
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __and__(self, other):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Returns new space map with ranges that appears both in A and B.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		if not type(other) == SpaceMap:
bfe3da6658 2010-10-14 c.kworr@f7677: 			return(False)
bfe3da6658 2010-10-14 c.kworr@f7677: 		new = {}
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other_pair = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 		# if there are no pairs in B - we have nothing to do
bfe3da6658 2010-10-14 c.kworr@f7677: 		if other_pair[0] == None or my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 			all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 		else:
bfe3da6658 2010-10-14 c.kworr@f7677: 			all_parts_found = False
bfe3da6658 2010-10-14 c.kworr@f7677: 		while not all_parts_found:
bfe3da6658 2010-10-14 c.kworr@f7677: 			if my_pair[0] > other_pair[0]:
bfe3da6658 2010-10-14 c.kworr@f7677: 				# when my pair starts after other pair starts
bfe3da6658 2010-10-14 c.kworr@f7677: 				#  m---
bfe3da6658 2010-10-14 c.kworr@f7677: 				# o---
bfe3da6658 2010-10-14 c.kworr@f7677: 				if my_pair[0] > other_pair[1]:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair starts after other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 					#       m---
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 					other_pair = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if other_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 				else:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair starts before other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 					#    m--- |     m---
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o---o   | o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 					if my_pair[1] > other_pair[1]:
bfe3da6658 2010-10-14 c.kworr@f7677: 						# when my pair ends after other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 						#    m---m |     m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 						# o---o    | o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 						other_pair[0] = my_pair[0]
bfe3da6658 2010-10-14 c.kworr@f7677: 						# trimming other pair by my pair start
bfe3da6658 2010-10-14 c.kworr@f7677: 						#   m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 						# o.o-o
bfe3da6658 2010-10-14 c.kworr@f7677: 					else:
bfe3da6658 2010-10-14 c.kworr@f7677: 						# when my pair ends before other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 						#  m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 						# o-----o
bfe3da6658 2010-10-14 c.kworr@f7677: 						new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 						# my pair is covered and should be added to result
bfe3da6658 2010-10-14 c.kworr@f7677: 						my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 						# tossing out my pair
bfe3da6658 2010-10-14 c.kworr@f7677: 						if my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 							all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 			elif my_pair[0] < other_pair[0]:
bfe3da6658 2010-10-14 c.kworr@f7677: 				# when my pair starts before other one
bfe3da6658 2010-10-14 c.kworr@f7677: 				# m---
bfe3da6658 2010-10-14 c.kworr@f7677: 				#  o---
bfe3da6658 2010-10-14 c.kworr@f7677: 				if my_pair[1] < other_pair[0]:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends before other pair starts
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 					#       o---
bfe3da6658 2010-10-14 c.kworr@f7677: 					my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out my pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 				else:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends before other pair starts
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 					#   o---
bfe3da6658 2010-10-14 c.kworr@f7677: 					my_pair[0] = other_pair[0]
bfe3da6658 2010-10-14 c.kworr@f7677: 					# trimming my pair by other pair start
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m.m-m
bfe3da6658 2010-10-14 c.kworr@f7677: 					#   o---
bfe3da6658 2010-10-14 c.kworr@f7677: 			else:
bfe3da6658 2010-10-14 c.kworr@f7677: 				# when both pairs starts simultaneously
bfe3da6658 2010-10-14 c.kworr@f7677: 				# m---
bfe3da6658 2010-10-14 c.kworr@f7677: 				# o---
bfe3da6658 2010-10-14 c.kworr@f7677: 				if my_pair[1] < other_pair[1]:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends before other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o-----o
bfe3da6658 2010-10-14 c.kworr@f7677: 					new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 					# my pair is covered and should be added to result
bfe3da6658 2010-10-14 c.kworr@f7677: 					my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out my pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 				else:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends after other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m-----m
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 					new[my_pair[0]] = other_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 					# part of my pair is covered and should be added to result
bfe3da6658 2010-10-14 c.kworr@f7677: 					other_pair = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if other_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 		return(SpaceMap(new, self.__bottom, self.__top))
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __sub__(self, other):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Returns new space map with ranges in A not covered by B.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		if not type(other) == SpaceMap:
bfe3da6658 2010-10-14 c.kworr@f7677: 			return(False)
bfe3da6658 2010-10-14 c.kworr@f7677: 		new = {}
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other_pair = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 		# if there are no pairs in B - copy this one to new SpaceMap
bfe3da6658 2010-10-14 c.kworr@f7677: 		if other_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 			new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 			all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 		elif my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 			all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 		else:
bfe3da6658 2010-10-14 c.kworr@f7677: 			all_parts_found = False
bfe3da6658 2010-10-14 c.kworr@f7677: 		while not all_parts_found:
bfe3da6658 2010-10-14 c.kworr@f7677: 			if my_pair[0] > other_pair[0]:
bfe3da6658 2010-10-14 c.kworr@f7677: 				# when my pair starts after other pair starts
bfe3da6658 2010-10-14 c.kworr@f7677: 				#  m---
bfe3da6658 2010-10-14 c.kworr@f7677: 				# o---
bfe3da6658 2010-10-14 c.kworr@f7677: 				if my_pair[0] > other_pair[1]:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair starts after other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 					#       m---
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 					other_pair = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if other_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						# this was last one - my pair goes to result
bfe3da6658 2010-10-14 c.kworr@f7677: 						new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 				else:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair starts before other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 					#    m--- |     m---
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o---o   | o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 					if my_pair[1] > other_pair[1]:
bfe3da6658 2010-10-14 c.kworr@f7677: 						# when my pair ends after other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 						#    m---m |     m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 						# o---o    | o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 						my_pair[0] = other_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 						# trimming my pair by other pair end
bfe3da6658 2010-10-14 c.kworr@f7677: 						#   m.m-m
bfe3da6658 2010-10-14 c.kworr@f7677: 						# o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 						other_pair = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 						# tossing out other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 						if other_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						# this was last one - my pair goes to result
bfe3da6658 2010-10-14 c.kworr@f7677: 							new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 							all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 					else:
bfe3da6658 2010-10-14 c.kworr@f7677: 						# when my pair ends before other pair ends
bfe3da6658 2010-10-14 c.kworr@f7677: 						#  m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 						# o-----o
bfe3da6658 2010-10-14 c.kworr@f7677: 						my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 						# tossing out my pair
bfe3da6658 2010-10-14 c.kworr@f7677: 						if my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 							all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 			elif my_pair[0] < other_pair[0]:
bfe3da6658 2010-10-14 c.kworr@f7677: 				# when my pair starts before other one
bfe3da6658 2010-10-14 c.kworr@f7677: 				# m---
bfe3da6658 2010-10-14 c.kworr@f7677: 				#  o---
bfe3da6658 2010-10-14 c.kworr@f7677: 				if my_pair[1] < other_pair[0]:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends before other pair starts
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 					#       o---
bfe3da6658 2010-10-14 c.kworr@f7677: 					new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 					# my pair is not covered and should be added to result
bfe3da6658 2010-10-14 c.kworr@f7677: 					my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out my pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 				else:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends before other pair starts
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 					#   o---
bfe3da6658 2010-10-14 c.kworr@f7677: 					new[my_pair[0]] = other_pair[0]
bfe3da6658 2010-10-14 c.kworr@f7677: 					# start of my pair is not covered and should be added to result
bfe3da6658 2010-10-14 c.kworr@f7677: 					my_pair[0] = other_pair[0]
bfe3da6658 2010-10-14 c.kworr@f7677: 					# trimming my pair by other pair start
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m.m-m
bfe3da6658 2010-10-14 c.kworr@f7677: 					#   o---
bfe3da6658 2010-10-14 c.kworr@f7677: 			else:
bfe3da6658 2010-10-14 c.kworr@f7677: 				# when both pairs starts simultaneously
bfe3da6658 2010-10-14 c.kworr@f7677: 				# m---
bfe3da6658 2010-10-14 c.kworr@f7677: 				# o---
bfe3da6658 2010-10-14 c.kworr@f7677: 				if my_pair[1] < other_pair[1]:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends before other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m---m
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o-----o
bfe3da6658 2010-10-14 c.kworr@f7677: 					my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out my pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 				else:
bfe3da6658 2010-10-14 c.kworr@f7677: 					# when my pair ends after other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m-----m
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 					my_pair[0] = other_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 					# trimming my pair by other pair end
bfe3da6658 2010-10-14 c.kworr@f7677: 					# m...m-m
bfe3da6658 2010-10-14 c.kworr@f7677: 					# o---o
bfe3da6658 2010-10-14 c.kworr@f7677: 					other_pair = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 					# tossing out other pair
bfe3da6658 2010-10-14 c.kworr@f7677: 					if other_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 						# this was last one - my pair goes to result
bfe3da6658 2010-10-14 c.kworr@f7677: 						new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 						all_parts_found = True
bfe3da6658 2010-10-14 c.kworr@f7677: 		while True:
bfe3da6658 2010-10-14 c.kworr@f7677: 			# copy any leftover in A to new SpaceMap
bfe3da6658 2010-10-14 c.kworr@f7677: 			my_pair = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 			if my_pair[0] == None:
bfe3da6658 2010-10-14 c.kworr@f7677: 				break
bfe3da6658 2010-10-14 c.kworr@f7677: 			else:
bfe3da6658 2010-10-14 c.kworr@f7677: 				new[my_pair[0]] = my_pair[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 		return(SpaceMap(new, self.__bottom, self.__top))
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __eq__(self, other):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Compares two space maps.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		if type(other) != SpaceMap:
bfe3da6658 2010-10-14 c.kworr@f7677: 			return(False)
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		result = None
bfe3da6658 2010-10-14 c.kworr@f7677: 		while True:
bfe3da6658 2010-10-14 c.kworr@f7677: 			this = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 			that = other.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 			if this != that:
bfe3da6658 2010-10-14 c.kworr@f7677: 				result = False
bfe3da6658 2010-10-14 c.kworr@f7677: 				break
bfe3da6658 2010-10-14 c.kworr@f7677: 			if this == [None, None] and that == [None, None]:
bfe3da6658 2010-10-14 c.kworr@f7677: 				result = True
bfe3da6658 2010-10-14 c.kworr@f7677: 				break
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 		other.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 		return(result)
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def end(self):
bfe3da6658 2010-10-14 c.kworr@f7677: 		'''Returns last known point.'''
bfe3da6658 2010-10-14 c.kworr@f7677: 		end = None
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.rewind()
bfe3da6658 2010-10-14 c.kworr@f7677: 		while True:
bfe3da6658 2010-10-14 c.kworr@f7677: 			this = self.pop()
bfe3da6658 2010-10-14 c.kworr@f7677: 			if this == [None, None]:
bfe3da6658 2010-10-14 c.kworr@f7677: 				break
bfe3da6658 2010-10-14 c.kworr@f7677: 			elif end == None or this[1] > end:
bfe3da6658 2010-10-14 c.kworr@f7677: 				end = this[1]
bfe3da6658 2010-10-14 c.kworr@f7677: 		self.clear()
bfe3da6658 2010-10-14 c.kworr@f7677: 		return(end)
bfe3da6658 2010-10-14 c.kworr@f7677: 
bfe3da6658 2010-10-14 c.kworr@f7677: 	def __len__(self):
bfe3da6658 2010-10-14 c.kworr@f7677: 		return(len(self.__pairs))