comparison mercurial/revset.py @ 25308:036c26b08b71

revset: add helper to build balanced addsets from chained 'or' operations This function will be used by revset.orset() and scmutil.revrange() to reduce the stack depth from O(n) to O(log(n)). We've bikeshed the interface of this function, but we couldn't come to an agreement. So we decided to attempt to make it move forward. marmoute: - new factory function isn't necessary for balanced addsets - addset.__init__ can just recurse, should handle "len(subsets) == 2+" yuja: - want to write all "len(subsets) == 0, 1, 2, 3+" cases in the same function - no recursion in __init__ for cosmetic reason: can't return, can't call __init__ directly I've changed it to a private function so that nobody would be tempted to utilize it.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 24 May 2015 14:10:52 +0900
parents 4d1e56b29a91
children b333ca94403d
comparison
equal deleted inserted replaced
25307:4d1e56b29a91 25308:036c26b08b71
2942 return None 2942 return None
2943 2943
2944 def __repr__(self): 2944 def __repr__(self):
2945 return '<%s %r>' % (type(self).__name__, self._subset) 2945 return '<%s %r>' % (type(self).__name__, self._subset)
2946 2946
2947 # this function will be removed, or merged to addset or orset, when
2948 # - scmutil.revrange() can be rewritten to not combine calculated smartsets
2949 # - or addset can handle more than two sets without balanced tree
2950 def _combinesets(subsets):
2951 """Create balanced tree of addsets representing union of given sets"""
2952 if not subsets:
2953 return baseset()
2954 if len(subsets) == 1:
2955 return subsets[0]
2956 p = len(subsets) // 2
2957 xs = _combinesets(subsets[:p])
2958 ys = _combinesets(subsets[p:])
2959 return addset(xs, ys)
2960
2947 def _iterordered(ascending, iter1, iter2): 2961 def _iterordered(ascending, iter1, iter2):
2948 """produce an ordered iteration from two iterators with the same order 2962 """produce an ordered iteration from two iterators with the same order
2949 2963
2950 The ascending is used to indicated the iteration direction. 2964 The ascending is used to indicated the iteration direction.
2951 """ 2965 """