Returns the first valid index that has a data-value larger or equal to @p data. Returns -1 if nothing is found.
| 141 | ///Returns the first valid index that has a data-value larger or equal to @p data. |
| 142 | ///Returns -1 if nothing is found. |
| 143 | int lowerBound(const Data& data, int start, int end) |
| 144 | { |
| 145 | int currentBound = -1; |
| 146 | while (1) { |
| 147 | if (start >= end) |
| 148 | return currentBound; |
| 149 | |
| 150 | int center = (start + end) / 2; |
| 151 | |
| 152 | //Skip free items, since they cannot be used for ordering |
| 153 | for (; center < end;) { |
| 154 | if (!ItemHandler::isFree(m_items[center])) |
| 155 | break; |
| 156 | ++center; |
| 157 | } |
| 158 | |
| 159 | if (center == end) { |
| 160 | end = (start + end) / 2; //No non-free items found in second half, so continue search in the other |
| 161 | } else { |
| 162 | if (ItemHandler::equals(data, m_items[center])) { |
| 163 | return center; |
| 164 | } else if (data < m_items[center]) { |
| 165 | currentBound = center; |
| 166 | end = (start + end) / 2; |
| 167 | } else { |
| 168 | //Continue search in second half |
| 169 | start = center + 1; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | uint countFreeItems() const |
| 176 | { |
no outgoing calls