~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-23 07:15:13 UTC
  • mfrom: (2926 +trunk)
  • mto: (2961.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2962.
  • Revision ID: v.ladeuil+lp@free.fr-20071023071513-elryt6g2at34d2ur
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
371
371
        return False
372
372
 
373
373
 
 
374
class HeadsCache(object):
 
375
    """A cache of results for graph heads calls."""
 
376
 
 
377
    def __init__(self, graph):
 
378
        self.graph = graph
 
379
        self._heads = {}
 
380
 
 
381
    def heads(self, keys):
 
382
        """Return the heads of keys.
 
383
 
 
384
        This matches the API of Graph.heads(), specifically the return value is
 
385
        a set which can be mutated, and ordering of the input is not preserved
 
386
        in the output.
 
387
 
 
388
        :see also: Graph.heads.
 
389
        :param keys: The keys to calculate heads for.
 
390
        :return: A set containing the heads, which may be mutated without
 
391
            affecting future lookups.
 
392
        """
 
393
        keys = frozenset(keys)
 
394
        try:
 
395
            return set(self._heads[keys])
 
396
        except KeyError:
 
397
            heads = self.graph.heads(keys)
 
398
            self._heads[keys] = heads
 
399
            return set(heads)
 
400
 
 
401
 
374
402
class _BreadthFirstSearcher(object):
375
403
    """Parallel search the breadth-first the ancestry of revisions.
376
404