[PATCH 1 of 5] util: add an LRU cache dict

Idan Kamara idankk86 at gmail.com
Fri Feb 8 15:38:13 CST 2013


On Fri, Feb 8, 2013 at 11:13 PM, Siddharth Agarwal <sid0 at fb.com> wrote:
>
> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1360351263 0
> # Node ID 642bf4f92100a41182de15646e37db70b391bfeb
> # Parent  08e00496e7b3bda8db3fbe7084a013d77e4932d2
> util: add an LRU cache dict
>
> This is the bare minimum dictionary implementation needed for an upcoming
> patch.
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -211,6 +211,30 @@ except AttributeError:
>                      del self[i]
>                      break
>
> +class lrucachedict(object):
> +    '''cache most recent get or sets to this dictionary'''
> +    def __init__(self, size):
> +        self._cache = {}
> +        self._size = {}
> +        self._order = deque()

Looks like you forgot to assign to _size here, so your
LRU isn't really bounded :)

>>> 0 > {}
False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130208/d9765d80/attachment.html>


More information about the Mercurial-devel mailing list