Пример #1
0
 def dogets():
     d = util.lrucachedict(size)
     for v in values:
         d[v] = v
     for key in getseq:
         value = d[key]
         value  # silence pyflakes warning
Пример #2
0
 def __init__(self, repo):
     # It's important that we store the repo, and not just the changelog,
     # since the changelog may be mutated in memory. So we need to refetch
     # the changelog each time we want to access it.
     self.repo = repo
     self._revlogs = util.lrucachedict(100)
     self._repackstartlinkrev = 0
Пример #3
0
    def __init__(self, packs, cachesize):
        self._packs = set(packs)
        self._lrucache = util.lrucachedict(cachesize)
        self._lastpack = None

        # Avoid cold start of the cache by populating the most recent packs
        # in the cache.
        for i in reversed(range(min(cachesize, len(packs)))):
            self._movetofront(packs[i])
Пример #4
0
    def domixed():
        d = util.lrucachedict(size)

        for op, v in mixedops:
            if op == 0:
                try:
                    d[v]
                except KeyError:
                    pass
            else:
                d[v] = v
Пример #5
0
 def dosets():
     d = util.lrucachedict(size)
     for v in setseq:
         d[v] = v
Пример #6
0
 def doinit():
     for i in xrange(10000):
         util.lrucachedict(size)
Пример #7
0
def test_lrucachedict():
    d = util.lrucachedict(4)
    d["a"] = "va"
    d["b"] = "vb"
    d["c"] = "vc"
    d["d"] = "vd"

    # all of these should be present
    printifpresent(d, ["a", "b", "c", "d"])

    # 'a' should be dropped because it was least recently used
    d["e"] = "ve"
    printifpresent(d, ["a", "b", "c", "d", "e"])

    assert d.get("a") is None
    assert d.get("e") == "ve"

    # touch entries in some order (get or set).
    d["e"]
    d["c"] = "vc2"
    d["d"]
    d["b"] = "vb2"

    # 'e' should be dropped now
    d["f"] = "vf"
    printifpresent(d, ["b", "c", "d", "e", "f"])

    d.clear()
    printifpresent(d, ["b", "c", "d", "e", "f"])

    # Now test dicts that aren't full.
    d = util.lrucachedict(4)
    d["a"] = 1
    d["b"] = 2
    d["a"]
    d["b"]
    printifpresent(d, ["a", "b"])

    # test copy method
    d = util.lrucachedict(4)
    d["a"] = "va3"
    d["b"] = "vb3"
    d["c"] = "vc3"
    d["d"] = "vd3"

    dc = d.copy()

    # all of these should be present
    print("\nAll of these should be present:")
    printifpresent(dc, ["a", "b", "c", "d"], "dc")

    # 'a' should be dropped because it was least recently used
    print("\nAll of these except 'a' should be present:")
    dc["e"] = "ve3"
    printifpresent(dc, ["a", "b", "c", "d", "e"], "dc")

    # contents and order of original dict should remain unchanged
    print("\nThese should be in reverse alphabetical order and read 'v?3':")
    dc["b"] = "vb3_new"
    for k in list(iter(d)):
        print("d['%s']: %s" % (k, d[k]))