From 2fdf67af4feab2913981bb7be121bb321a628e43 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 11 Feb 2013 12:08:20 +0000 Subject: [PATCH] Core: Developing SortedIndex git-svn-id: svn://ultimatepp.org/upp/trunk@5793 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/InVector.h | 9 ++------- uppsrc/Core/InVector.hpp | 6 +++--- uppsrc/Core/Topt.h | 12 ++++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/uppsrc/Core/InVector.h b/uppsrc/Core/InVector.h index d6faf6b66..0d257f37b 100644 --- a/uppsrc/Core/InVector.h +++ b/uppsrc/Core/InVector.h @@ -377,7 +377,7 @@ public: }; template > -class SortedIndex : MoveableAndDeepCopyOption< SortedIndex >{ +class SortedIndex : MoveableAndDeepCopyOption< SortedIndex > { InVector iv; Less less; @@ -409,7 +409,6 @@ public: void Shrink() { iv.Shrink(); } - typedef typename InVector::Iterator Iterator; typedef typename InVector::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) + STL_SINDEX_COMPATIBILITY(SortedIndex) }; #define LLOG(x) // DLOG(x) diff --git a/uppsrc/Core/InVector.hpp b/uppsrc/Core/InVector.hpp index 2e823ebb7..2a5979c4f 100644 --- a/uppsrc/Core/InVector.hpp +++ b/uppsrc/Core/InVector.hpp @@ -725,9 +725,9 @@ template int SortedIndex::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 diff --git a/uppsrc/Core/Topt.h b/uppsrc/Core/Topt.h index 84e270e0b..58a31614b 100644 --- a/uppsrc/Core/Topt.h +++ b/uppsrc/Core/Topt.h @@ -426,6 +426,18 @@ template 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; \