Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 65769 invoked from network); 17 Feb 2006 18:31:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Feb 2006 18:31:23 -0000 Received: (qmail 84840 invoked by uid 500); 17 Feb 2006 18:31:23 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 84823 invoked by uid 500); 17 Feb 2006 18:31:23 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 84812 invoked by uid 500); 17 Feb 2006 18:31:23 -0000 Delivered-To: apmail-incubator-stdcxx-cvs@incubator.apache.org Received: (qmail 84808 invoked by uid 99); 17 Feb 2006 18:31:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2006 10:31:22 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 17 Feb 2006 10:31:22 -0800 Received: (qmail 65191 invoked by uid 65534); 17 Feb 2006 18:31:01 -0000 Message-ID: <20060217183101.65190.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r378581 - in /incubator/stdcxx/trunk/tests: include/alg_test.h src/alg_test.cpp Date: Fri, 17 Feb 2006 18:31:01 -0000 To: stdcxx-cvs@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.6 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: sebor Date: Fri Feb 17 10:30:58 2006 New Revision: 378581 URL: http://svn.apache.org/viewcvs?rev=378581&view=rev Log: 2006-02-17 Martin Sebor * alg_test.h (first_less): New helper function declaration. (from_char): Added a third argument to check that the source array is sorted in non-descending order. (ilog2, ilog10): Outlined for better compilation efficiency. (is_sorted): New helper function template. * alg_test.cpp (first_less): Defined. (from_char): Verified that the source array is sorted and returned 0 when it's not. Modified: incubator/stdcxx/trunk/tests/include/alg_test.h incubator/stdcxx/trunk/tests/src/alg_test.cpp Modified: incubator/stdcxx/trunk/tests/include/alg_test.h URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/alg_test.h?rev=378581&r1=378580&r2=378581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/include/alg_test.h (original) +++ incubator/stdcxx/trunk/tests/include/alg_test.h Fri Feb 17 10:30:58 2006 @@ -127,11 +127,22 @@ _RWSTD_SIZE_T n_op_eq, _RWSTD_SIZE_T n_op_lt); + // returns a pointer to the first element in the sequence whose value + // is less than the value of the immediately preceding element, or 0 + // when no such element exists + static const X* + first_less (const X*, _RWSTD_SIZE_T); + static void reset_totals (); // construct an array of objects of type X each initialized // from the corresponding element of the character array - static X* from_char (const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX); + // when the last argument is true and the character array + // is not sorted in ascending order the function fails by + // returning 0 + static X* + from_char (const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, + bool = false); // returns -1 when less, 0 when same, or +1 when the array // of X objects is greater than the character string @@ -156,28 +167,30 @@ // wrapper around a (possibly) extern "C" int rand() // extern "C++" -_TEST_EXPORT int gen_rnd (); +_TEST_EXPORT int gen_rnd (); // computes an integral log2 -inline unsigned ilog2 (unsigned long n) -{ - unsigned result = 0; - while (n >>= 1) - ++result; - return result; -} - +_TEST_EXPORT unsigned ilog2 (_RWSTD_SIZE_T); // computes an integral log10 -inline unsigned ilog10 (unsigned long n) +_TEST_EXPORT unsigned ilog10 (_RWSTD_SIZE_T); + + +template +inline bool +is_sorted (InputIterator first, InputIterator last, Predicate pred) { - unsigned result = 0; - while (n /= 10) - ++result; - return result; -} + if (first == last) + return true; + for (InputIterator prev (first); ++first != last; prev = first) { + if (pred (*first, *prev)) + return false; + } + + return true; +} // returns true iff a sequence of (not necessarily unique) values // is sorted in an ascending order Modified: incubator/stdcxx/trunk/tests/src/alg_test.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/alg_test.cpp?rev=378581&r1=378580&r2=378581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/src/alg_test.cpp (original) +++ incubator/stdcxx/trunk/tests/src/alg_test.cpp Fri Feb 17 10:30:58 2006 @@ -306,6 +306,22 @@ } +/* static */ const X* +X::first_less (const X *xarray, size_t nelems) +{ + size_t inx = nelems; + + if (1 < nelems) { + for (inx = 1; inx != nelems; ++inx) { + if (xarray [inx] < xarray [inx - 1]) + break; + } + } + + return inx < nelems ? xarray + inx : 0; +} + + /* static */ void X::reset_totals () { @@ -333,7 +349,7 @@ /* static */ X* -X::from_char (const char *str, size_t len /* = -1 */) +X::from_char (const char *str, size_t len /* = -1 */, bool sorted /* = false */) { // handle null pointers if (!str) @@ -343,6 +359,15 @@ if (size_t (-1) == len) len = strlen (str); + if (sorted) { + // verify that the sequence is sorted + for (size_t i = 1; i < len; ++i) { + if (str [i] < str [i - 1]) { + return 0; + } + } + } + // set the global pointer to point to the beginning of `str' xinit_begin = str; @@ -545,6 +570,30 @@ _TEST_EXPORT int gen_rnd () { return rand (); +} + + +_TEST_EXPORT unsigned +ilog2 (size_t n) +{ + unsigned result = 0; + + while (n >>= 1) + ++result; + + return result; +} + + +_TEST_EXPORT unsigned +ilog10 (size_t n) +{ + unsigned result = 0; + + while (n /= 10) + ++result; + + return result; }