~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: John Arbash Meinel
  • Date: 2008-03-15 13:51:09 UTC
  • mfrom: (3280 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3281.
  • Revision ID: john@arbash-meinel.com-20080315135109-7v9gimdidd1s7llr
[merge] bzr.dev 3280

Show diffs side-by-side

added added

removed removed

Lines of Context:
498
498
            return set(heads)
499
499
 
500
500
 
 
501
class FrozenHeadsCache(object):
 
502
    """Cache heads() calls, assuming the caller won't modify them."""
 
503
 
 
504
    def __init__(self, graph):
 
505
        self.graph = graph
 
506
        self._heads = {}
 
507
 
 
508
    def heads(self, keys):
 
509
        """Return the heads of keys.
 
510
 
 
511
        Similar to Graph.heads(). The main difference is that the return value
 
512
        is a frozen set which cannot be mutated.
 
513
 
 
514
        :see also: Graph.heads.
 
515
        :param keys: The keys to calculate heads for.
 
516
        :return: A frozenset containing the heads.
 
517
        """
 
518
        keys = frozenset(keys)
 
519
        try:
 
520
            return self._heads[keys]
 
521
        except KeyError:
 
522
            heads = frozenset(self.graph.heads(keys))
 
523
            self._heads[keys] = heads
 
524
            return heads
 
525
 
 
526
    def cache(self, keys, heads):
 
527
        """Store a known value."""
 
528
        self._heads[frozenset(keys)] = frozenset(heads)
 
529
 
 
530
 
501
531
class _BreadthFirstSearcher(object):
502
532
    """Parallel search breadth-first the ancestry of revisions.
503
533