Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Change in <Core/Sort.h> breaks my code
Change in <Core/Sort.h> breaks my code [message #55410] Sun, 08 November 2020 19:12 Go to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
I recently updated to 20111108 from a version that's about half year old, and encountered a compilation error. As I ponder about the error, it appears the new implementation of Sort__ in <Core/Sort.h> requires the Iterator class to supply a <= operator. While I don't know how the Iterator specification says, I believe it's probably better to revise the Sort__ code slightly to relieve the library user of the obligation to supply a <=, however trial it is.
void Sort__(I l, I h, const Less& less)
{
	int count = int(h - l);
	I middle = l + (count >> 1);        // get the middle element
	for(;;) {
		switch(count) {
		case 0:
		case 1: return;
		case 2: OrderIter2__(l, l + 1, less); return;
		case 3: OrderIter3__(l, l + 1, l + 2, less); return;
		case 4: OrderIter4__(l, l + 1, l + 2, l + 3, less); return;
		case 5: OrderIter5__(l, l + 1, l + 2, l + 3, l + 4, less); return;
		case 6: OrderIter6__(l, l + 1, l + 2, l + 3, l + 4, l + 5, less); return;
		case 7: OrderIter7__(l, l + 1, l + 2, l + 3, l + 4, l + 5, l + 6, less); return;
		}
		if(count > 1000) {
			middle = l + (count >> 1); // iterators cannot point to the same object!
			I q = l + 1 + (int)Random((count >> 1) - 2);
			I w = middle + 1 + (int)Random((count >> 1) - 2);
			OrderIter5__(l, q, middle, w, h - 1, less);
		}
		else
			OrderIter3__(l, middle, h - 1, less);

		I pivot = h - 2;
		IterSwap(pivot, middle); // move median pivot to h - 2
		I i = l;
		I j = h - 2; // l, h - 2, h - 1 already sorted above
		for(;;) { // Hoare's partition (modified):
			while(less(*++i, *pivot));
			do
				if(j <= i) goto done;
***************************************************************
*****SHOULD BE*************************************************
				if(!(i<j) ) goto done;
***************************************************************

			while(!less(*--j, *pivot));
			IterSwap(i, j);
		}
	done:


Thank you!
Re: Change in <Core/Sort.h> breaks my code [message #55413 is a reply to message #55410] Mon, 09 November 2020 12:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sorry about that, not sure what I was thinking... Smile

Now in trunk.

Mirek
Re: Change in <Core/Sort.h> breaks my code [message #55416 is a reply to message #55413] Mon, 09 November 2020 16:43 Go to previous message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Thank you, Mirek!
Previous Topic: Creating a com object
Next Topic: SetConfigGroup
Goto Forum:
  


Current Time: Tue Apr 16 07:36:36 CEST 2024

Total time taken to generate the page: 0.03820 seconds