~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-24 06:48:13 UTC
  • mfrom: (2592.3.241 mbp-packrepo-as-knits)
  • Revision ID: pqm@pqm.ubuntu.com-20071024064813-wjcmv8ofabf6kdrb
Pack repositories!

Show diffs side-by-side

added added

removed removed

Lines of Context:
369
369
            return set(heads)
370
370
 
371
371
 
 
372
class HeadsCache(object):
 
373
    """A cache of results for graph heads calls."""
 
374
 
 
375
    def __init__(self, graph):
 
376
        self.graph = graph
 
377
        self._heads = {}
 
378
 
 
379
    def heads(self, keys):
 
380
        """Return the heads of keys.
 
381
 
 
382
        :see also: Graph.heads.
 
383
        :param keys: The keys to calculate heads for.
 
384
        :return: A set containing the heads, which may be mutated without
 
385
            affecting future lookups.
 
386
        """
 
387
        keys = frozenset(keys)
 
388
        try:
 
389
            return set(self._heads[keys])
 
390
        except KeyError:
 
391
            heads = self.graph.heads(keys)
 
392
            self._heads[keys] = heads
 
393
            return set(heads)
 
394
 
 
395
 
372
396
class _BreadthFirstSearcher(object):
373
397
    """Parallel search breadth-first the ancestry of revisions.
374
398