Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /plugins/lru.py [de6804] .. [a3f0ae] Maximize Restore

  Switch to unified view

a/plugins/lru.py b/plugins/lru.py
1
2
class Node:
3
    def __init__(self, prev, me):
4
        self.prev = prev
5
        self.me = me
6
        self.next = None
7
1
8
2
class lastused: #Implementation of a length-limited O(1) LRU cache
9
class lastused: #Implementation of a length-limited O(1) LRU cache
3
    class Node:
4
        def __init__(self, prev, me):
5
            self.prev = prev
6
            self.me = me
7
            self.next = None
8
    def __init__(self, count, lst=[]):
10
    def __init__(self, count, lst=[]):
9
        self.count = max(count, 2)
11
        self.count = max(count, 2)
10
        self.d = {}
12
        self.d = {}
11
        self.first = None
13
        self.first = None
12
        self.last = None
14
        self.last = None
...
...
17
    def __getitem__(self, obj):
19
    def __getitem__(self, obj):
18
        return self.d[obj].me[1]
20
        return self.d[obj].me[1]
19
    def __setitem__(self, obj, val):
21
    def __setitem__(self, obj, val):
20
        if obj in self.d:
22
        if obj in self.d:
21
            del self[obj]
23
            del self[obj]
22
        nobj = self.Node(self.last, (obj, val))
24
        nobj = Node(self.last, (obj, val))
23
        if self.first is None:
25
        if self.first is None:
24
            self.first = nobj
26
            self.first = nobj
25
        if self.last:
27
        if self.last:
26
            self.last.next = nobj
28
            self.last.next = nobj
27
        self.last = nobj
29
        self.last = nobj