mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-04 08:17:40 +00:00
COMMON: Implement SortedArray
This commit is contained in:
parent
0ff9e79127
commit
cc54c7723c
@ -361,6 +361,57 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Double linked list with sorted nodes.
|
||||
*/
|
||||
template<class T>
|
||||
class SortedArray : public Array<T> {
|
||||
public:
|
||||
typedef T *iterator;
|
||||
typedef uint size_type;
|
||||
|
||||
SortedArray(int (*comparator)(const void *, const void *)) {
|
||||
_comparator = comparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts element at the sorted position.
|
||||
*/
|
||||
void insert(const T &element) {
|
||||
T *where = (T *)bsearch(element, this->front(), this->_size, sizeof(T), _comparator);
|
||||
insert(where, element);
|
||||
}
|
||||
|
||||
T &operator[](size_type idx) {
|
||||
error("Operation not allowed with SortedArray");
|
||||
}
|
||||
|
||||
void insert_at(size_type idx, const T &element) {
|
||||
error("Operation not allowed with SortedArray");
|
||||
}
|
||||
|
||||
void insert_at(size_type idx, const Array<T> &array) {
|
||||
error("Operation not allowed with SortedArray");
|
||||
}
|
||||
|
||||
void insert(iterator pos, const T &element) {
|
||||
error("Operation not allowed with SortedArray");
|
||||
}
|
||||
|
||||
void push_back(const T &element) {
|
||||
error("Operation not allowed with SortedArray");
|
||||
}
|
||||
|
||||
void push_back(const Array<T> &array) {
|
||||
error("Operation not allowed with SortedArray");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
int (*_comparator)(const void *, const void *);
|
||||
};
|
||||
|
||||
} // End of namespace Common
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user