@NotNull
 @Override
 public Condition<CommitId> getContainedInBranchCondition(
     @NotNull final Collection<CommitId> heads) {
   List<Integer> headIds =
       ContainerUtil.map(
           heads,
           new Function<CommitId, Integer>() {
             @Override
             public Integer fun(CommitId head) {
               return myPermanentCommitsInfo.getNodeId(head);
             }
           });
   if (!heads.isEmpty() && ContainerUtil.getFirstItem(heads) instanceof Integer) {
     final TIntHashSet branchNodes = new TIntHashSet();
     myReachableNodes.walk(
         headIds,
         new Consumer<Integer>() {
           @Override
           public void consume(Integer node) {
             branchNodes.add((Integer) myPermanentCommitsInfo.getCommitId(node));
           }
         });
     return new Condition<CommitId>() {
       @Override
       public boolean value(CommitId commitId) {
         return branchNodes.contains((Integer) commitId);
       }
     };
   } else {
     final Set<CommitId> branchNodes = ContainerUtil.newHashSet();
     myReachableNodes.walk(
         headIds,
         new Consumer<Integer>() {
           @Override
           public void consume(Integer node) {
             branchNodes.add(myPermanentCommitsInfo.getCommitId(node));
           }
         });
     return new Condition<CommitId>() {
       @Override
       public boolean value(CommitId commitId) {
         return branchNodes.contains(commitId);
       }
     };
   }
 }
  public Set<Integer> getContainingBranches(
      int nodeIndex, @NotNull final Collection<Integer> branchNodeIndexes) {
    final Set<Integer> result = new HashSet<Integer>();

    walk(
        Collections.singletonList(nodeIndex),
        false,
        new Consumer<Integer>() {
          @Override
          public void consume(Integer integer) {
            if (branchNodeIndexes.contains(integer)) result.add(integer);
          }
        });

    return result;
  }
  @NotNull
  public static UnsignedBitSet getReachableNodes(
      @NotNull PermanentLinearGraphImpl permanentGraph, @Nullable Set<Integer> headNodeIndexes) {
    if (headNodeIndexes == null) {
      UnsignedBitSet nodesVisibility = new UnsignedBitSet();
      nodesVisibility.set(0, permanentGraph.nodesCount() - 1, true);
      return nodesVisibility;
    }

    assert !headNodeIndexes.isEmpty();

    final UnsignedBitSet result = new UnsignedBitSet();
    ReachableNodes getter = new ReachableNodes(LinearGraphUtils.asLiteLinearGraph(permanentGraph));
    getter.walk(
        headNodeIndexes,
        new Consumer<Integer>() {
          @Override
          public void consume(Integer node) {
            result.set(node, true);
          }
        });

    return result;
  }
 public void walk(
     @NotNull Collection<Integer> headIds, @NotNull final Consumer<Integer> consumer) {
   walk(headIds, true, consumer);
 }