diff options
author | Sebastian Geerken <devnull@localhost> | 2013-04-10 22:52:55 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-04-10 22:52:55 +0200 |
commit | 812d9f27982903650a0f5497cd67c1602efc1ce7 (patch) | |
tree | b259bde8c9159aa5128da469944a699ff11f8f47 /lout/container.cc | |
parent | f28fb7335e1e47a82c9b869bf6b6f44e60372f19 (diff) |
Introduced Comparator.
Diffstat (limited to 'lout/container.cc')
-rw-r--r-- | lout/container.cc | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lout/container.cc b/lout/container.cc index de36a6f7..77f0e710 100644 --- a/lout/container.cc +++ b/lout/container.cc @@ -188,9 +188,10 @@ void Vector::remove(int pos) /** * Sort the elements in the vector. Assumes that all elements are Comparable's. */ -void Vector::sort() +void Vector::sort(Comparator *comparator) { - qsort (array, numElements, sizeof(Object*), Comparable::compareFun); + Comparator::compareFunComparator = comparator; + qsort (array, numElements, sizeof(Object*), Comparator::compareFun); } /** @@ -202,7 +203,7 @@ void Vector::sort() * size of the array. (This is the value which can be used for * insertion; see insertSortet()). */ -int Vector::bsearch(Object *key, bool mustExist) +int Vector::bsearch(Object *key, bool mustExist, Comparator *comparator) { // The case !mustExist is not handled by bsearch(3), so here is a // new implementation. @@ -213,7 +214,7 @@ int Vector::bsearch(Object *key, bool mustExist) while (true) { int index = (low + high) / 2; - int c = ((Comparable*) key)->compareTo ((Comparable*)array[index]); + int c = comparator->compare (key, array[index]); if (c == 0) return index; else { @@ -233,6 +234,7 @@ int Vector::bsearch(Object *key, bool mustExist) /* + Comparator::compareFunComparator = comparator; void *result = ::bsearch (&key, array, numElements, sizeof (Object*), Comparable::compareFun); if (result) |