【发布时间】:2015-08-18 19:02:02
【问题描述】:
我正在研究 Python 的 最近最少使用 (LRU) 缓存 实现 here。
有人能解释一下_make_key 函数在做什么吗?
def _make_key(args, kwds, typed,
kwd_mark = (object(),),
fasttypes = {int, str, frozenset, type(None)},
sorted=sorted, tuple=tuple, type=type, len=len):
'Make a cache key from optionally typed positional and keyword arguments'
key = args
if kwds:
sorted_items = sorted(kwds.items())
key += kwd_mark
for item in sorted_items:
key += item
if typed:
key += tuple(type(v) for v in args)
if kwds:
key += tuple(type(v) for k, v in sorted_items)
elif len(key) == 1 and type(key[0]) in fasttypes:
return key[0]
return _HashedSeq(key)
【问题讨论】:
-
喜欢....整个功能?你能缩小你的问题范围吗?有没有你不明白的特定行?
-
一种完整的功能。
sort在这里的作用是什么?kwd_mark是什么?