001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.jikesrvm.compilers.opt.regalloc;
014
015import java.util.Comparator;
016
017/**
018 * Implements a set of Basic Intervals, sorted by start number.
019 * <p>
020 * This version does NOT use container-mapping as a function in the comparator.
021 */
022class IncreasingStartIntervalSet extends IntervalSet {
023  /** Support for Set serialization */
024  static final long serialVersionUID = -7086728932911844728L;
025
026  /**
027   * Imposes an ascending ordering based on the start points of basic intervals.
028   * <p>
029   * Note that this ordering is inconsistent with equals for objects of type
030   * {@link MappedBasicInterval}. It would consider two MappedBasicIntervals
031   * with different containers the same if begin and end would match.
032   */
033  private static class StartComparator implements Comparator<BasicInterval> {
034    @Override
035    public int compare(BasicInterval b1, BasicInterval b2) {
036      int result = b1.getBegin() - b2.getBegin();
037      if (result == 0) {
038        result = b1.getEnd() - b2.getEnd();
039      }
040      return result;
041    }
042  }
043
044  static final IncreasingStartIntervalSet.StartComparator c = new StartComparator();
045
046  IncreasingStartIntervalSet() {
047    super(c /*,true*/);
048  }
049}