[Scummvm-cvs-logs] scummvm master -> 603fccf74b9710ce542dfb2745475a530173d96e

sev- sev at scummvm.org
Sat Jun 4 13:50:40 CEST 2016


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e0d445bb74 TESTS: Fix SortedArray test
603fccf74b COMMON: Fixed SortedArray implementation


Commit: e0d445bb74d6081c6e0dbbd6fe790acf3e61b7cb
    https://github.com/scummvm/scummvm/commit/e0d445bb74d6081c6e0dbbd6fe790acf3e61b7cb
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-06-04T13:49:55+02:00

Commit Message:
TESTS: Fix SortedArray test

Changed paths:
    test/common/array.h



diff --git a/test/common/array.h b/test/common/array.h
index 7473398..2dc6783 100644
--- a/test/common/array.h
+++ b/test/common/array.h
@@ -362,7 +362,7 @@ struct ListElement {
 };
 
 static int compareInts(const void *a, const void *b) {
-	return ((ListElement *)a)->value - ((ListElement *)a)->value;
+	return ((ListElement *)a)->value - ((ListElement *)b)->value;
 }
 
 class SortedArrayTestSuite : public CxxTest::TestSuite {
@@ -373,8 +373,6 @@ public:
 
 		// Fill the container with some random data
 		container.insert(new ListElement(1));
-		return;
-
 		container.insert(new ListElement(7));
 		container.insert(new ListElement(8));
 		container.insert(new ListElement(3));
@@ -390,8 +388,9 @@ public:
 		for (int i = 1; i < 10; i++) {
 			TS_ASSERT_EQUALS((*iter)->value, i);
 			++iter;
-			TS_ASSERT_DIFFERS(iter, container.end());
 		}
+
+		TS_ASSERT_EQUALS(iter, container.end());
 	}
 
 };


Commit: 603fccf74b9710ce542dfb2745475a530173d96e
    https://github.com/scummvm/scummvm/commit/603fccf74b9710ce542dfb2745475a530173d96e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-06-04T13:50:15+02:00

Commit Message:
COMMON: Fixed SortedArray implementation

Changed paths:
    common/array.h



diff --git a/common/array.h b/common/array.h
index e9b97aa..04ec9f9 100644
--- a/common/array.h
+++ b/common/array.h
@@ -383,56 +383,59 @@ public:
 			return;
 		}
 
-		T *where = (T *)bsearchMin(element, this->front(), this->_size, sizeof(T), _comparator);
-		insert(where, element);
+		T *where = bsearchMin(element);
+
+		if (where > this->_storage + this->_size)
+			Array<T>::push_back(element);
+		else
+			Array<T>::insert(where, element);
 	}
 
 	T &operator[](size_type idx) {
-		error("Operation not allowed with SortedArray");
+		error("Operation []= not allowed with SortedArray");
 	}
 
 	void insert_at(size_type idx, const T &element) {
-		error("Operation not allowed with SortedArray");
+		error("Operation insert_at(idx, element) not allowed with SortedArray");
 	}
 
 	void insert_at(size_type idx, const Array<T> &array) {
-		error("Operation not allowed with SortedArray");
+		error("Operation insert_at(idx, array) not allowed with SortedArray");
 	}
 
 	void insert(iterator pos, const T &element) {
-		error("Operation not allowed with SortedArray");
+		error("Operation insert(pos, elemnet) not allowed with SortedArray");
 	}
 
 	void push_back(const T &element) {
-		error("Operation not allowed with SortedArray");
+		error("Operation push_back(element) not allowed with SortedArray");
 	}
 
 	void push_back(const Array<T> &array) {
-		error("Operation not allowed with SortedArray");
+		error("Operation push_back(array) not allowed with SortedArray");
 	}
 
 private:
 	// Based on code Copyright (C) 2008-2009 Ksplice, Inc.
 	// Author: Tim Abbott <tabbott at ksplice.com>
 	// Licensed under GPLv2+
-	void *bsearchMin(void *key, void *base, uint num, uint size_,
-					int (*cmp)(const void *key, const void *elt)) {
-		uint start_ = 0, end_ = num;
+	T *bsearchMin(void *key) {
+		uint start_ = 0, end_ = this->_size;
 		int result;
 
 		while (start_ < end_) {
 			uint mid = start_ + (end_ - start_) / 2;
 
-			result = cmp(key, (byte *)base + mid * size_);
+			result = this->_comparator(key, this->_storage[mid]);
 			if (result < 0)
 				end_ = mid;
 			else if (result > 0)
 				start_ = mid + 1;
 			else
-				return (void *)((byte *)base + mid * size_);
+				return &this->_storage[mid];
 		}
 
-		return (void *)((byte *)base + start_ * size_);
+		return &this->_storage[start_];
 	}
 
 private:






More information about the Scummvm-git-logs mailing list