def make_demand_func(query):
    func = N.get_query_demand_func_name(query.name)
    uset = N.get_query_demand_set_name(query.name)
    
    maxsize = query.demand_set_maxsize
    
    if maxsize is None:
        code = L.Parser.ps('''
            def _FUNC(_elem):
                if _elem not in _U:
                    _U.reladd(_elem)
            ''', subst={'_FUNC': func, '_U': uset})
    elif maxsize == 1:
        code = L.Parser.ps('''
            def _FUNC(_elem):
                if _elem not in _U:
                    _U.relclear()
                    _U.reladd(_elem)
            ''', subst={'_FUNC': func, '_U': uset})
    elif not isinstance(maxsize, int) or maxsize <= 0:
        raise L.ProgramError('Invalid value for demand_set_maxsize')
    else:
        code = L.Parser.ps('''
            def _FUNC(_elem):
                if _elem not in _U:
                    while len(_U) >= _MAXSIZE:
                        _stale = _U.peek()
                        _U.relremove(_stale)
                    _U.reladd(_elem)
            ''', subst={'_FUNC': func, '_U': uset,
                        '_MAXSIZE': L.Num(maxsize)})
    
    return code
Exemple #2
0
def make_demand_set(symtab, query):
    """Create a demand set, update the query's demand_set attribute, and
    return the new demand set symbol.
    """
    uset_name = N.get_query_demand_set_name(query.name)
    uset_tuple = L.tuplify(query.demand_params)
    uset_tuple_type = symtab.analyze_expr_type(uset_tuple)
    uset_type = T.Set(uset_tuple_type)
    maxsize = query.demand_set_maxsize
    uset_lru = maxsize is not None and maxsize > 1
    uset_sym = symtab.define_relation(uset_name, type=uset_type, lru=uset_lru)

    query.demand_set = uset_name

    return uset_sym
def make_demand_set(symtab, query):
    """Create a demand set, update the query's demand_set attribute, and
    return the new demand set symbol.
    """
    uset_name = N.get_query_demand_set_name(query.name)
    uset_tuple = L.tuplify(query.demand_params)
    uset_tuple_type = symtab.analyze_expr_type(uset_tuple)
    uset_type = T.Set(uset_tuple_type)
    maxsize = query.demand_set_maxsize
    uset_lru = maxsize is not None and maxsize > 1
    uset_sym = symtab.define_relation(uset_name, type=uset_type,
                                      lru=uset_lru)
    
    query.demand_set = uset_name
    
    return uset_sym
Exemple #4
0
def make_demand_func(query):
    func = N.get_query_demand_func_name(query.name)
    uset = N.get_query_demand_set_name(query.name)

    maxsize = query.demand_set_maxsize

    if maxsize is None:
        code = L.Parser.ps('''
            def _FUNC(_elem):
                if _elem not in _U:
                    _U.reladd(_elem)
            ''',
                           subst={
                               '_FUNC': func,
                               '_U': uset
                           })
    elif maxsize == 1:
        code = L.Parser.ps('''
            def _FUNC(_elem):
                if _elem not in _U:
                    _U.relclear()
                    _U.reladd(_elem)
            ''',
                           subst={
                               '_FUNC': func,
                               '_U': uset
                           })
    elif not isinstance(maxsize, int) or maxsize <= 0:
        raise L.ProgramError('Invalid value for demand_set_maxsize')
    else:
        code = L.Parser.ps('''
            def _FUNC(_elem):
                if _elem not in _U:
                    while len(_U) >= _MAXSIZE:
                        _stale = _U.peek()
                        _U.relremove(_stale)
                    _U.reladd(_elem)
            ''',
                           subst={
                               '_FUNC': func,
                               '_U': uset,
                               '_MAXSIZE': L.Num(maxsize)
                           })

    return code