Пример #1
0
    def split_at(n, rope, /):
        '-> (initial_seq, tail_rope)'
        check_uint(n)
        check_type_is(tuple, rope)
        if n == 0:
            return (), rope

        size = rope[0]
        if not 0 <= n <= size: raise ValueError
        N = n
        L = size
        lss = []
        while n > 0:
            (size, num_skips, seq, rope) = rope
            end = num_skips + n
            ls = seq[num_skips:end]
            lss.append(ls)
            n -= len(ls)
        if not n == 0: raise logic - err
        #bug:tail_rope = RopeOps.mk(num_skips+n, seq, rope)
        tail_rope = mk(end, seq, rope)
        it = itertools.chain.from_iterable(lss)
        initial_seq = (*it, )
        assert len(initial_seq) == N
        assert L == N + tail_rope[0]
        return initial_seq, tail_rope
Пример #2
0
 def mk1(num_skips, seq, /):
     check_uint(num_skips)
     size = len(seq) - num_skips
     check_uint(size)
     if not size:
         return empty_rope
     return (size, num_skips, seq, None)
 def __init__(sf, num_args4call, uXss4body, /):
     check_uint(num_args4call)
     #check_type_is(tuple, uXss4body)
     #   uint|tuple
     check_uintXs_lt(num_args4call, uXss4body)
     sf._num_args4call = num_args4call
     sf._uXss4body = uXss4body
     return
 def __init__(sf, func, args_rglnkls, num_remain_args,
              num_remain_tail_laziness, /):
     check_callable(func)
     check_type_is(tuple, args_rglnkls)
     check_uint(num_remain_args)
     check_uint(num_remain_tail_laziness)
     assert len(args_rglnkls) in [0, 2]
     if not (num_remain_args or num_remain_tail_laziness): raise TypeError
     sf._func = func
     sf._args_rglnkls = args_rglnkls
     sf._num_remain_args = num_remain_args
     sf._num_remain_tail_laziness = num_remain_tail_laziness
     return
Пример #5
0
    def check_snapshot_point(sf, snapshot_point, /):
        check_pair(snapshot_point)
        (history_sz, itop_time) = snapshot_point
        check_uint(history_sz)
        check_uint(itop_time)
        #################################
        if not itop_time <= history_sz: raise ValueError
        history = sf._history
        if not history_sz <= len(history): raise ValueError

        #check history_sz ->iparent_time*-> itop_time ->iparent_time*-> 0
        if itop_time:
            itime = history_sz
            for itime in sf._iter_itimes_from_top_to_bottom(history, itime):
                if not itop_time < itime:
                    break
            else:
                raise logic - err
            if not itop_time == itime:
                raise ValueError(
                    'itop_time not match history_sz, not its ancestor')
        return
Пример #6
0
 def test_uints(us, /):
     for u in us:
         check_uint(u)
         test_uint(u)