Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/Common/MyVector.h')
-rwxr-xr-xCPP/Common/MyVector.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h
index 1bb67a1d..ce370a53 100755
--- a/CPP/Common/MyVector.h
+++ b/CPP/Common/MyVector.h
@@ -96,6 +96,23 @@ public:
return -1;
}
+ int AddToUniqueSorted(const T& item)
+ {
+ int left = 0, right = Size();
+ while (left != right)
+ {
+ int mid = (left + right) / 2;
+ const T& midValue = (*this)[mid];
+ if (item == midValue)
+ return mid;
+ if (item < midValue)
+ right = mid;
+ else
+ left = mid + 1;
+ }
+ Insert(right, item);
+ return right;
+ }
static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)
{