bool HReorderingForwardState::operator==(const FFState& o) const
{
  if (&o == this) return true;

  HReorderingForwardState const& other
  = static_cast<HReorderingForwardState const&>(o);

  int compareScores = ((m_prevRange == other.m_prevRange)
                       ? ComparePrevScores(other.m_prevOption)
                       : (m_prevRange < other.m_prevRange) ? -1 : 1);
  return compareScores == 0;
}
int HierarchicalReorderingForwardState::Compare(const FFState& o) const {
  if (&o == this)
      return 0;

  const HierarchicalReorderingForwardState* other = dynamic_cast<const HierarchicalReorderingForwardState*>(&o);
  assert(other != NULL);
  if (m_prevRange == other->m_prevRange) {
    return ComparePrevScores(other->m_prevScore);
  } else if (m_prevRange < other->m_prevRange) {
    return -1;
  }
  return 1;
}
int HierarchicalReorderingForwardState::Compare(const FFState& o) const
{
  if (&o == this)
    return 0;

  const HierarchicalReorderingForwardState* other = dynamic_cast<const HierarchicalReorderingForwardState*>(&o);
  UTIL_THROW_IF2(other == NULL, "Wrong state type");

  if (m_prevRange == other->m_prevRange) {
    return ComparePrevScores(other->m_prevScore);
  } else if (m_prevRange < other->m_prevRange) {
    return -1;
  }
  return 1;
}
bool PhraseBasedReorderingState::operator==(const FFState& o) const
{
  if (&o == this) return true;

  const PhraseBasedReorderingState &other = static_cast<const PhraseBasedReorderingState&>(o);
  if (m_prevRange == other.m_prevRange) {
    if (m_direction == LRModel::Forward) {
      int compareScore = ComparePrevScores(other.m_prevOption);
      return compareScore == 0;
    } else {
      return true;
    }
  } else {
    return false;
  }
}
int PhraseBasedReorderingState::Compare(const FFState& o) const {
  if (&o == this)
      return 0;

  const PhraseBasedReorderingState* other = dynamic_cast<const PhraseBasedReorderingState*>(&o);
  assert(other != NULL);
  if (m_prevRange == other->m_prevRange) {
    if (m_direction == LexicalReorderingConfiguration::Forward) {
      return ComparePrevScores(other->m_prevScore);
    } else {
      return 0;
    }
  } else if (m_prevRange < other->m_prevRange) {
    return -1;
  }
  return 1;
}