mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
Core: SortedIndex
git-svn-id: svn://ultimatepp.org/upp/trunk@5791 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
1eb7339f0f
commit
0fde48a364
2 changed files with 97 additions and 0 deletions
|
|
@ -109,6 +109,8 @@ public:
|
|||
InVector(const InVector& v, int);
|
||||
|
||||
void Swap(InVector& b);
|
||||
|
||||
friend void Swap(InVector& a, InVector& b) { a.Swap(b); }
|
||||
|
||||
STL_VECTOR_COMPATIBILITY(InVector<T>)
|
||||
|
||||
|
|
@ -301,6 +303,8 @@ public:
|
|||
|
||||
void Swap(InArray& b) { iv.Swap(b.iv); }
|
||||
|
||||
friend void Swap(InArray& a, InArray& b) { a.Swap(b); }
|
||||
|
||||
STL_VECTOR_COMPATIBILITY(InArray<T>)
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
|
@ -372,6 +376,62 @@ public:
|
|||
const T& operator[](int i) const { Iterator h = *this; h += i; return *h; }
|
||||
};
|
||||
|
||||
template <class T, class Less = StdLess<T> >
|
||||
class SortedIndex : MoveableAndDeepCopyOption< SortedIndex<T, Less> >{
|
||||
InVector<T> iv;
|
||||
Less less;
|
||||
|
||||
public:
|
||||
int Add(const T& x) { return iv.InsertUpperBound(x, less); }
|
||||
int FindAdd(const T& key);
|
||||
SortedIndex& operator<<(const T& x) { Add(x); return *this; }
|
||||
|
||||
int FindLowerBound(const T& x) const { return iv.FindLowerBound(x, less); }
|
||||
int FindUpperBound(const T& x) const { return iv.FindUpperBound(x, less); }
|
||||
|
||||
int Find(const T& x) const { return iv.Find(x, less); }
|
||||
int FindNext(int i) const;
|
||||
int FindLast(const T& x) const;
|
||||
int FindPrev(int i) const;
|
||||
|
||||
void Remove(int i) { iv.Remove(i); }
|
||||
void Remove(int i, int count) { iv.Remove(i, count); }
|
||||
int RemoveKey(const T& x);
|
||||
|
||||
const T& operator[](int i) const { return iv[i]; }
|
||||
int GetCount() const { return iv.GetCount(); }
|
||||
bool IsEmpty() const { return iv.IsEmpty(); }
|
||||
void Clear() { iv.Clear(); }
|
||||
|
||||
void Trim(int n) { return iv.Trim(n); }
|
||||
void Drop(int n = 1) { iv.Drop(n); }
|
||||
const T& Top() const { return iv.Top(); }
|
||||
|
||||
void Shrink() { iv.Shrink(); }
|
||||
|
||||
typedef typename InVector<T>::Iterator Iterator;
|
||||
typedef typename InVector<T>::ConstIterator ConstIterator;
|
||||
|
||||
typedef T ValueType;
|
||||
|
||||
ConstIterator Begin() const { return iv.Begin(); }
|
||||
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) {}
|
||||
|
||||
void Swap(SortedIndex& a) { iv.Swap(a.iv); }
|
||||
|
||||
friend void Swap(SortedIndex& a, SortedIndex& b){ a.Swap(b); }
|
||||
|
||||
STL_VECTOR_COMPATIBILITY(SortedIndex<T _cm_ Less>)
|
||||
};
|
||||
|
||||
#define LLOG(x) // DLOG(x)
|
||||
#include "InVector.hpp"
|
||||
#undef LLOG
|
||||
|
|
|
|||
Loading…
Reference in a new issue