1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// Common/Vector.h
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __COMMON_VECTOR_H
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __COMMON_VECTOR_H
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Defs.h"
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
8baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CBaseRecordVector
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void MoveItems(int destIndex, int srcIndex);
11baa3858d3f5d128a5c8466b700098109edcad5f2repo syncprotected:
12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int _capacity;
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int _size;
14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void *_items;
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  size_t _itemSize;
16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void ReserveOnePosition();
18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void InsertOneItem(int index);
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void TestIndexAndCorrectNum(int index, int &num) const
20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { if (index + num > _size) num = _size - index; }
21baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic:
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  virtual ~CBaseRecordVector();
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void ClearAndFree();
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int Size() const { return _size; }
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsEmpty() const { return (_size == 0); }
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Reserve(int newCapacity);
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void ReserveDown();
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  virtual void Delete(int index, int num = 1);
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Clear();
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void DeleteFrom(int index);
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void DeleteBack();
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
35baa3858d3f5d128a5c8466b700098109edcad5f2repo synctemplate <class T>
36baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CRecordVector: public CBaseRecordVector
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
38baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic:
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CRecordVector(): CBaseRecordVector(sizeof(T)){};
40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v; }
41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CRecordVector& operator=(const CRecordVector &v)
42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Clear();
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return (*this += v);
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CRecordVector& operator+=(const CRecordVector &v)
47baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int size = v.Size();
49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Reserve(Size() + size);
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < size; i++)
51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      Add(v[i]);
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return *this;
53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int Add(T item)
55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ReserveOnePosition();
57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ((T *)_items)[_size] = item;
58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return _size++;
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Insert(int index, T item)
61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    InsertOneItem(index);
63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ((T *)_items)[index] = item;
64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  // T* GetPointer() const { return (T*)_items; }
66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  // operator const T *() const { return _items; };
67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const T& operator[](int index) const { return ((T *)_items)[index]; }
68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  T& operator[](int index) { return ((T *)_items)[index]; }
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const T& Front() const { return operator[](0); }
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  T& Front() { return operator[](0); }
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const T& Back() const { return operator[](_size - 1); }
72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  T& Back() { return operator[](_size - 1); }
73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Swap(int i, int j)
75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    T temp = operator[](i);
77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    operator[](i) = operator[](j);
78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    operator[](j) = temp;
79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int FindInSorted(const T& item, int left, int right) const
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    while (left != right)
84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int mid = (left + right) / 2;
86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const T& midValue = (*this)[mid];
87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item == midValue)
88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return mid;
89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item < midValue)
90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        right = mid;
91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        left = mid + 1;
93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int FindInSorted(const T& item) const
98baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int left = 0, right = Size();
100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    while (left != right)
101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int mid = (left + right) / 2;
103baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const T& midValue = (*this)[mid];
104baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item == midValue)
105baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return mid;
106baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item < midValue)
107baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        right = mid;
108baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
109baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        left = mid + 1;
110baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
111baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
112baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
113baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
114baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int AddToUniqueSorted(const T& item)
115baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
116baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int left = 0, right = Size();
117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    while (left != right)
118baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
119baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int mid = (left + right) / 2;
120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const T& midValue = (*this)[mid];
121baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item == midValue)
122baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return mid;
123baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item < midValue)
124baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        right = mid;
125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
126baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        left = mid + 1;
127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Insert(right, item);
129baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return right;
130baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
131baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
132baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)
133baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
134baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    T temp = p[k];
135baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (;;)
136baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
137baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int s = (k << 1);
138baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (s > size)
139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        break;
140baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (s < size && compare(p + s + 1, p + s, param) > 0)
141baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        s++;
142baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (compare(&temp, p + s, param) >= 0)
143baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        break;
144baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      p[k] = p[s];
145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      k = s;
146baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
147baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    p[k] = temp;
148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
149baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Sort(int (*compare)(const T*, const T*, void *), void *param)
151baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
152baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int size = _size;
153baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (size <= 1)
154baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return;
155baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    T* p = (&Front()) - 1;
156baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
157baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int i = size / 2;
158baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      do
159baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        SortRefDown(p, i, size, compare, param);
160baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      while (--i != 0);
161baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    do
163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      T temp = p[size];
165baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      p[size--] = p[1];
166baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      p[1] = temp;
167baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      SortRefDown(p, 1, size, compare, param);
168baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    while (size > 1);
170baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
171baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
173baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CRecordVector<int> CIntVector;
174baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CRecordVector<unsigned int> CUIntVector;
175baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CRecordVector<bool> CBoolVector;
176baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CRecordVector<unsigned char> CByteVector;
177baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CRecordVector<void *> CPointerVector;
178baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
179baa3858d3f5d128a5c8466b700098109edcad5f2repo synctemplate <class T>
180baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CObjectVector: public CPointerVector
181baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
182baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic:
183baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CObjectVector() {};
184baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  ~CObjectVector() { Clear(); };
185baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CObjectVector(const CObjectVector &v): CPointerVector() { *this = v; }
186baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CObjectVector& operator=(const CObjectVector &v)
187baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
188baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Clear();
189baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return (*this += v);
190baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
191baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CObjectVector& operator+=(const CObjectVector &v)
192baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
193baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int size = v.Size();
194baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Reserve(Size() + size);
195baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < size; i++)
196baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      Add(v[i]);
197baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return *this;
198baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
199baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }
200baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }
201baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  T& Front() { return operator[](0); }
202baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const T& Front() const { return operator[](0); }
203baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  T& Back() { return operator[](_size - 1); }
204baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const T& Back() const { return operator[](_size - 1); }
205baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int Add(const T& item) { return CPointerVector::Add(new T(item)); }
206baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Insert(int index, const T& item) { CPointerVector::Insert(index, new T(item)); }
207baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  virtual void Delete(int index, int num = 1)
208baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
209baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    TestIndexAndCorrectNum(index, num);
210baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < num; i++)
211baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      delete (T *)(((void **)_items)[index + i]);
212baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CPointerVector::Delete(index, num);
213baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
214baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int Find(const T& item) const
215baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
216baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < Size(); i++)
217baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item == (*this)[i])
218baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return i;
219baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
220baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
221baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int FindInSorted(const T& item) const
222baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
223baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int left = 0, right = Size();
224baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    while (left != right)
225baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
226baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int mid = (left + right) / 2;
227baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const T& midValue = (*this)[mid];
228baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item == midValue)
229baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return mid;
230baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item < midValue)
231baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        right = mid;
232baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
233baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        left = mid + 1;
234baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
235baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
236baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
237baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int AddToSorted(const T& item)
238baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
239baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int left = 0, right = Size();
240baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    while (left != right)
241baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
242baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int mid = (left + right) / 2;
243baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const T& midValue = (*this)[mid];
244baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item == midValue)
245baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
246baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        right = mid + 1;
247baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        break;
248baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
249baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (item < midValue)
250baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        right = mid;
251baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
252baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        left = mid + 1;
253baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
254baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Insert(right, item);
255baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return right;
256baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
257baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
258baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Sort(int (*compare)(void *const *, void *const *, void *), void *param)
259baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { CPointerVector::Sort(compare, param); }
260baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
261baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)
262baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }
263baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }
264baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
265baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
266baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
267