Changeset 662 for branches


Ignore:
Timestamp:
05/25/13 16:19:21 (3 years ago)
Author:
mmckerns
Message:

fixed import of inf_cache, already merged into cache;
added ability for keymap to store args, kwds either flat or (args, kwds)

Location:
branches/decorate
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/decorate/cache.py

    r661 r662  
    99from threading import RLock 
    1010from cache_helper import _CacheInfo, Counter, hashmap as _keymap 
    11 from INF_cache import inf_cache 
    12 from NO_cache import no_cache 
    1311 
    1412 
  • branches/decorate/cache_helper.py

    r660 r662  
    1212           typed = False, 
    1313           kwd_mark = (object(),), #XXX: 'nicer' kwd_mark = ("",) ?  None ? 
     14           flat = True, #XXX: if not flat, then key = (args, tuple) 
    1415           fasttypes = set((int, str, frozenset, type(None))), 
    1516           sorted=sorted, tuple=tuple, type=type, len=len): 
    1617    'Make a cache key from optionally typed positional and keyword arguments' 
     18    if not flat: 
     19        key = (args, kwds) #XXX: pickles larger, but is simpler to unpack 
     20        if typed: 
     21            sorted_items = sorted(kwds.items()) 
     22            key += (tuple(type(v) for v in args), \ 
     23                    tuple(type(v) for k, v in sorted_items)) 
     24        return key 
    1725    key = args 
    1826    if kwds: 
     
    2129        for item in sorted_items: 
    2230            key += item 
    23     if typed: 
    24         key += tuple(type(v) for v in args) 
     31    if typed: #XXX: 'kwd_mark' between each of the 4 parts, so easy to split 
     32        key += kwd_mark + tuple(type(v) for v in args) 
    2533        if kwds: 
    26             key += tuple(type(v) for k, v in sorted_items) 
     34            key += kwd_mark + tuple(type(v) for k, v in sorted_items) 
    2735    elif len(key) == 1 and type(key[0]) in fasttypes: 
    2836        return key[0] 
  • branches/decorate/memoize.py

    r660 r662  
    353353    if memo is None: memo = archive_dict() 
    354354    elif type(memo) is dict: memo = archive_dict(memo) 
    355     # does archive make sense with databas, file, ?... (requires more thought) 
     355    # does archive make sense with database, file, ?... (requires more thought) 
    356356 
    357357    if deep: rounded = deep_round 
Note: See TracChangeset for help on using the changeset viewer.