IntervalTree is now support multiple intervals with same lower bound.
* New: Interval::CompareByMinMax, lexicographical comparison of Intervals, first compare the lower bound (VMin) then the upper bound (VMax). Needed for IntervalTree. * Change: In IntervalTree, the key comparison was only based on the lower bound (VMin). That means that the tree would accept only one interval for a given VMin. You couldn't store both [1:4] and [1:5]. Now use CompareByMinMax that allows it.
This commit is contained in:
parent
a0911be50a
commit
e22e7f7476
|
@ -1,6 +1,6 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
//
|
//
|
||||||
// Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
|
// Copyright (c) BULL S.A. 2000-2023, All Rights Reserved
|
||||||
//
|
//
|
||||||
// This file is part of Hurricane.
|
// This file is part of Hurricane.
|
||||||
//
|
//
|
||||||
|
@ -29,9 +29,7 @@
|
||||||
// +-----------------------------------------------------------------+
|
// +-----------------------------------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
#ifndef HURRICANE_INTERVAL_H
|
#pragma once
|
||||||
#define HURRICANE_INTERVAL_H
|
|
||||||
|
|
||||||
#include "hurricane/DbU.h"
|
#include "hurricane/DbU.h"
|
||||||
|
|
||||||
namespace Hurricane {
|
namespace Hurricane {
|
||||||
|
@ -48,6 +46,11 @@ namespace Hurricane {
|
||||||
inline bool operator() ( const Interval& rhs, const Interval& lhs ) const;
|
inline bool operator() ( const Interval& rhs, const Interval& lhs ) const;
|
||||||
inline bool operator() ( const Interval* rhs, const Interval* lhs ) const;
|
inline bool operator() ( const Interval* rhs, const Interval* lhs ) const;
|
||||||
};
|
};
|
||||||
|
class CompareByMinMax {
|
||||||
|
public:
|
||||||
|
inline bool operator() ( const Interval& rhs, const Interval& lhs ) const;
|
||||||
|
inline bool operator() ( const Interval* rhs, const Interval* lhs ) const;
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
Interval ( bool makeEmpty=true );
|
Interval ( bool makeEmpty=true );
|
||||||
Interval ( const DbU::Unit& );
|
Interval ( const DbU::Unit& );
|
||||||
|
@ -124,6 +127,20 @@ namespace Hurricane {
|
||||||
{ return lhs->getVMin() < rhs->getVMin(); }
|
{ return lhs->getVMin() < rhs->getVMin(); }
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Interval::CompareByMinMax::operator() ( const Interval& lhs, const Interval& rhs ) const
|
||||||
|
{
|
||||||
|
if (lhs.getVMin() != rhs.getVMin()) return lhs.getVMin() < rhs.getVMin();
|
||||||
|
return lhs.getVMax() < rhs.getVMax();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Interval::CompareByMinMax::operator() ( const Interval* lhs, const Interval* rhs ) const
|
||||||
|
{
|
||||||
|
if (lhs->getVMin() != rhs->getVMin()) return lhs->getVMin() < rhs->getVMin();
|
||||||
|
return lhs->getVMax() < rhs->getVMax();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // Hurricane namespace.
|
} // Hurricane namespace.
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,7 +153,5 @@ inline void jsonWrite ( JsonWriter* w, const std::string& key, const Hurricane:
|
||||||
w->endArray();
|
w->endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INSPECTOR_PR_SUPPORT(Hurricane::Interval);
|
INSPECTOR_PR_SUPPORT(Hurricane::Interval);
|
||||||
|
|
||||||
|
|
||||||
#endif // HURRICANE_INTERVAL_H
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
//
|
//
|
||||||
// Copyright (c) BULL S.A. 2018-2018, All Rights Reserved
|
// Copyright (c) BULL S.A. 2018-2023, All Rights Reserved
|
||||||
//
|
//
|
||||||
// This file is part of Hurricane.
|
// This file is part of Hurricane.
|
||||||
//
|
//
|
||||||
|
@ -34,9 +34,7 @@
|
||||||
// Third edition, MIT press, 2011, p. 348.
|
// Third edition, MIT press, 2011, p. 348.
|
||||||
|
|
||||||
|
|
||||||
#ifndef HURRICANE_INTERVAL_TREE_H
|
#pragma once
|
||||||
#define HURRICANE_INTERVAL_TREE_H
|
|
||||||
|
|
||||||
#include "hurricane/Interval.h"
|
#include "hurricane/Interval.h"
|
||||||
#include "hurricane/RbTree.h"
|
#include "hurricane/RbTree.h"
|
||||||
|
|
||||||
|
@ -117,14 +115,14 @@ namespace Hurricane {
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Class : "Hurricane::IntervalTree".
|
// Class : "Hurricane::IntervalTree".
|
||||||
|
|
||||||
|
|
||||||
template< typename Data >
|
template< typename Data >
|
||||||
class IntervalTree : public RbTree< IntervalData<Data>, Interval::CompareByMin > {
|
class IntervalTree : public RbTree< IntervalData<Data>, Interval::CompareByMinMax > {
|
||||||
public:
|
public:
|
||||||
typedef RbTree< IntervalData<Data>, Interval::CompareByMin > Super;
|
typedef RbTree< IntervalData<Data>, Interval::CompareByMinMax > Super;
|
||||||
public:
|
public:
|
||||||
class overlap_iterator : public Super::iterator {
|
class overlap_iterator : public Super::iterator {
|
||||||
public:
|
public:
|
||||||
|
@ -414,5 +412,3 @@ namespace Hurricane {
|
||||||
|
|
||||||
|
|
||||||
} // HUrricane namespace.
|
} // HUrricane namespace.
|
||||||
|
|
||||||
#endif // HURRICANE_INTERVAL_TREE_H
|
|
||||||
|
|
|
@ -557,10 +557,10 @@ namespace Hurricane {
|
||||||
|
|
||||||
Node* current = root_;
|
Node* current = root_;
|
||||||
while ( current ) {
|
while ( current ) {
|
||||||
cdebug_log(0,0) << "| " << current << std::endl;
|
cdebug_log(0,0) << "| " << current->getValue() << std::endl;
|
||||||
|
|
||||||
if (current->getValue() == value) {
|
if (current->getValue() == value) {
|
||||||
cdebug_log(0,-1) << "> Value found: " << current <<std::endl;
|
cdebug_log(0,-1) << "> Value found: " << current->getValue() <<std::endl;
|
||||||
return iterator(current);
|
return iterator(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue