mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-17 06:06:00 -06:00
Core: Developing SortedIndex
git-svn-id: svn://ultimatepp.org/upp/trunk@5793 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
b59e9959ed
commit
2fdf67af4f
3 changed files with 17 additions and 10 deletions
|
|
@ -377,7 +377,7 @@ public:
|
|||
};
|
||||
|
||||
template <class T, class Less = StdLess<T> >
|
||||
class SortedIndex : MoveableAndDeepCopyOption< SortedIndex<T, Less> >{
|
||||
class SortedIndex : MoveableAndDeepCopyOption< SortedIndex<T, Less> > {
|
||||
InVector<T> iv;
|
||||
Less less;
|
||||
|
||||
|
|
@ -409,7 +409,6 @@ public:
|
|||
|
||||
void Shrink() { iv.Shrink(); }
|
||||
|
||||
typedef typename InVector<T>::Iterator Iterator;
|
||||
typedef typename InVector<T>::ConstIterator ConstIterator;
|
||||
|
||||
typedef T ValueType;
|
||||
|
|
@ -418,10 +417,6 @@ public:
|
|||
ConstIterator End() const { return iv.End(); }
|
||||
ConstIterator GetIter(int pos) const { return iv.GetIter(pos); }
|
||||
|
||||
Iterator Begin() { return iv.Begin(); }
|
||||
Iterator End() { return iv.End(); }
|
||||
Iterator GetIter(int pos) { return iv.GetIter(pos); }
|
||||
|
||||
SortedIndex() {}
|
||||
SortedIndex(const SortedIndex& s, int) : iv(s.iv, 1) {}
|
||||
|
||||
|
|
@ -429,7 +424,7 @@ public:
|
|||
|
||||
friend void Swap(SortedIndex& a, SortedIndex& b){ a.Swap(b); }
|
||||
|
||||
STL_VECTOR_COMPATIBILITY(SortedIndex<T _cm_ Less>)
|
||||
STL_SINDEX_COMPATIBILITY(SortedIndex<T _cm_ Less>)
|
||||
};
|
||||
|
||||
#define LLOG(x) // DLOG(x)
|
||||
|
|
|
|||
|
|
@ -725,9 +725,9 @@ template <class T, class Less>
|
|||
int SortedIndex<T, Less>::FindAdd(const T& key)
|
||||
{
|
||||
int i = FindLowerBound(key);
|
||||
if(!less(key, iv[i]))
|
||||
return i;
|
||||
return Add(key);
|
||||
if(i == GetCount() || less(key, iv[i]))
|
||||
iv.Insert(i, key);
|
||||
return i;
|
||||
}
|
||||
|
||||
template <class T, class Less>
|
||||
|
|
|
|||
|
|
@ -426,6 +426,18 @@ template <class T> inline const T& ntl_max(const T& a, const T& b) { return a >
|
|||
size_type size() { return B::GetCount(); } \
|
||||
bool empty() const { return B::IsEmpty(); } \
|
||||
|
||||
#define STL_SINDEX_COMPATIBILITY(C) \
|
||||
typedef T value_type; \
|
||||
typedef ConstIterator const_iterator; \
|
||||
typedef const T& const_reference; \
|
||||
typedef int size_type; \
|
||||
typedef int difference_type; \
|
||||
const_iterator begin() const { return Begin(); } \
|
||||
const_iterator end() const { return End(); } \
|
||||
void clear() { Clear(); } \
|
||||
size_type size() { return GetCount(); } \
|
||||
bool empty() const { return IsEmpty(); } \
|
||||
|
||||
#define STL_BI_COMPATIBILITY(C) \
|
||||
typedef T value_type; \
|
||||
typedef ConstIterator const_iterator; \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue