コード例 #1
0
ファイル: collator.py プロジェクト: hwwhww/sharding_poc
async def windback(network, shard, header, availability_cache):
    assert WINDBACK_LENGTH > 0

    def add_parent_header(headers):
        parent_header = shard.headers_by_hash[headers[-1].parent_hash]
        return headers + [parent_header]

    header_chain = iterate(add_parent_header, [header])
    n_parents = min(WINDBACK_LENGTH - 1, header.number)
    headers_to_check = reversed(nth(n_parents,
                                    header_chain))  # from root to leaf

    availabilities = {}  # {hash: available, ...} for all headers checked here

    for header in headers_to_check:
        if header.hash in availabilities:
            available = availability_cache[header.hash]
        else:
            available = check_availability(header)
            availabilities[header.hash] = available

        if not available:
            # don't check children of unavailable collations
            break

    # remaining collations are unavailable as one of their ancestors is unavailable
    for header in headers_to_check:
        availabilities[header.hash] = False

    return availabilities
コード例 #2
0
ファイル: utils.py プロジェクト: chulse/NIRS_I2BL
def get(ind, coll, lazy=False):
    """

    >>> get(0, 'Hello')
    'H'

    >>> get([1, 0], 'Hello')
    ('e', 'H')

    >>> get(slice(1, 4), 'Hello')
    ('e', 'l', 'l')

    >>> get(slice(1, 4), 'Hello', lazy=True)
    <itertools.islice object at ...>
    """
    if isinstance(ind, list):
        result = nth_list(ind, coll)
    elif isinstance(ind, slice):
        result = islice(coll, ind.start, ind.stop, ind.step)
    else:
        if isinstance(coll, Iterator):
            result = nth(ind, coll)
        else:
            result = coll[ind]
    if not lazy and isinstance(result, Iterator):
        result = tuple(result)
    return result
コード例 #3
0
ファイル: utils.py プロジェクト: jessezwd/blaze
def get(ind, coll, lazy=False):
    """

    >>> get(0, 'Hello')
    'H'

    >>> get([1, 0], 'Hello')
    ('e', 'H')

    >>> get(slice(1, 4), 'Hello')
    ('e', 'l', 'l')

    >>> get(slice(1, 4), 'Hello', lazy=True)
    <itertools.islice object at ...>
    """
    if isinstance(ind, list):
        result = nth_list(ind, coll)
    elif isinstance(ind, slice):
        result = islice(coll, ind.start, ind.stop, ind.step)
    else:
        if isinstance(coll, Iterator):
            result = nth(ind, coll)
        else:
            result = coll[ind]
    if not lazy and isinstance(result, Iterator):
        result = tuple(result)
    return result
コード例 #4
0
ファイル: python.py プロジェクト: Casolt/blaze
def compute_up(expr, seq, **kwargs):
    index = expr.index
    if isinstance(index, tuple) and len(index) == 1:
        index = index[0]
    if isinstance(index, _inttypes):
        return nth(index, seq)
    if isinstance(index, slice):
        return itertools.islice(seq, index.start, index.stop, index.step)
    raise NotImplementedError("Only 1d slices supported")
コード例 #5
0
def compute_up(expr, seq, **kwargs):
    index = expr.index
    if isinstance(index, tuple) and len(index) == 1:
        index = index[0]
    if isinstance(index, _inttypes):
        return nth(index, seq)
    if isinstance(index, slice):
        return itertools.islice(seq, index.start, index.stop, index.step)
    raise NotImplementedError("Only 1d slices supported")
コード例 #6
0
ファイル: python.py プロジェクト: gyenney/Tools
def compute_up(expr, seq, **kwargs):
    index = expr.index
    if isinstance(index, tuple) and len(index) == 1:
        index = index[0]
    if isinstance(index, _inttypes):
        try:
            return seq[index]
        except:
            if index >= 0:
                return nth(index, seq)
            else:
                return tail(-index, seq)[0]
    if isinstance(index, slice):
        if index.start and index.start < 0 and index.stop is None and index.step in (1, None):
            return tail(-index.start, seq)
        else:
            return itertools.islice(seq, index.start, index.stop, index.step)
    raise NotImplementedError("Only 1d slices supported")
コード例 #7
0
ファイル: python.py プロジェクト: yihongfa/blaze
def compute_up(expr, seq, **kwargs):
    index = expr.index
    if isinstance(index, tuple) and len(index) == 1:
        index = index[0]
    if isinstance(index, _inttypes):
        try:
            return seq[index]
        except:
            if index >= 0:
                return nth(index, seq)
            else:
                return tail(-index, seq)[0]
    if isinstance(index, slice):
        if (index.start and index.start < 0 and index.stop is None
                and index.step in (1, None)):
            return tail(-index.start, seq)
        else:
            return itertools.islice(seq, index.start, index.stop, index.step)
    raise NotImplementedError("Only 1d slices supported")
コード例 #8
0
ファイル: q48.py プロジェクト: kuribayashi4/100knock
def make_pathes_list(line_index):
    neko = parse()
    pathes = [[chunk for chunk in chunk_list if len(chunk_list) > 1]
              for chunk_list in noun_to_root(nth(line_index, neko))]
    return pathes
コード例 #9
0
def main():
    make_tree(nth(3, parse()))
コード例 #10
0
ファイル: knock_41.py プロジェクト: t-tagami/100_knock
def main():
    for sent in nth(7, Chunk.make_chunk_object_list()):
        print('係り先 {:2d}\t係り元 {}\t{}'.format(sent.dst, sent.srcs, sent))
コード例 #11
0
ファイル: fcollections.py プロジェクト: PilCAki/fcollections
 def nth(self, n):
     return cytoolz.nth(n, self)
コード例 #12
0
ファイル: q40.py プロジェクト: kuribayashi4/100knock
def main():
    neko = parse()
    for morph in nth(3, neko):
        print(morph)
コード例 #13
0
def main():
    neko = parse()
    for chunk in nth(7, neko):
        print(chunk.details())
コード例 #14
0
def main():
	for sent in nth(3, Morph.make_sent_morph_list()):
		print(sent)