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 » stable sort bug.. or looks like it
stable sort bug.. or looks like it [message #48123] Sun, 21 May 2017 22:30 Go to next message
aftershock is currently offline  aftershock
Messages: 143
Registered: May 2008
Experienced Member
Have a look
VectorMap<String, int> involved_nodes;

DUMPM ( involved_nodes );
StableSort ( involved_nodes.Begin(), involved_nodes.End(), lip );

DUMPM ( involved_nodes );

Stable sort does not seem copy key value pairs correctly for maps.


before
involved_nodes:
[0] = (tester_withdraw_when) 0
[1] = (tester_withdraw_amount) 2
[2] = (tester_balance) 3
[3] = (trading_buy_open_start_hour) 12
[4] = (trading_buy_open_end_hour) 13
[5] = (trading_sell_open_start_hour) 18
[6] = (trading_sell_open_end_hour) 19
[7] = (buy_closewhenprofit) 38
[8] = (buy_stepsize) 43
[9] = (buy_stopdistance) 47
[10] = (sell_stepsize) 51
[11] = (sell_closewhenprofit) 52
[12] = (buy_close_after_minutes) 180
[13] = (sell_close_after_minutes) 181
[14] = (sell_stopdistance) 216
[15] = (buy_stop_fallback) 221
[16] = (sell_stop_fallback) 225
[17] = (buy_rsi_timeframe) 229
[18] = (sell_rsi_timeframe) 230
[19] = (buy_rsi_upper_limit) 367
[20] = (sell_rsi_lower_limit) 368
after incorrect result
involved_nodes:
[0] = (tester_withdraw_when) 3
[1] = (tester_withdraw_amount) 0
[2] = (tester_balance) 2
[3] = (trading_buy_open_start_hour) 19
[4] = (trading_buy_open_end_hour) 13
[5] = (trading_sell_open_start_hour) 18
[6] = (trading_sell_open_end_hour) 12
[7] = (buy_closewhenprofit) 38
[8] = (buy_stepsize) 47
[9] = (buy_stopdistance) 51
[10] = (sell_stepsize) 216
[11] = (sell_closewhenprofit) 221
[12] = (buy_close_after_minutes) 229
[13] = (sell_close_after_minutes) 43
[14] = (sell_stopdistance) 52
[15] = (buy_stop_fallback) 180
[16] = (sell_stop_fallback) 181
[17] = (buy_rsi_timeframe) 225
[18] = (sell_rsi_timeframe) 230
[19] = (buy_rsi_upper_limit) 367
[20] = (sell_rsi_lower_limit) 368

This is what it should be.....
involved_nodes:
[0] = (tester_withdraw_when) 0
[1] = (tester_withdraw_amount) 2
[2] = (tester_balance) 3
[3] = (trading_buy_open_start_hour) 12
[4] = (trading_buy_open_end_hour) 13
[5] = (trading_sell_open_start_hour) 18
[6] = (trading_sell_open_end_hour) 19
[7] = (buy_closewhenprofit) 38
[8] = (buy_stepsize) 43
[9] = (buy_stopdistance) 47
[10] = (sell_stepsize) 51
[11] = (sell_closewhenprofit) 52
[12] = (buy_close_after_minutes) 180
[13] = (sell_close_after_minutes) 181
[14] = (sell_stopdistance) 216
[15] = (buy_stop_fallback) 221
[16] = (sell_stop_fallback) 225
[17] = (buy_rsi_timeframe) 229
[18] = (sell_rsi_timeframe) 230
[19] = (buy_rsi_upper_limit) 367
[20] = (sell_rsi_lower_limit) 368

Thanks.. Can you fix this?

A.

Re: stable sort bug.. or looks like it [message #48130 is a reply to message #48123] Mon, 22 May 2017 12:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
aftershock wrote on Sun, 21 May 2017 22:30
Have a look
VectorMap<String, int> involved_nodes;

DUMPM ( involved_nodes );
StableSort ( involved_nodes.Begin(), involved_nodes.End(), lip );

DUMPM ( involved_nodes );

Stable sort does not seem copy key value pairs correctly for maps.


All Sorts, when used like this, only sort values, as begin/end here return iterators to values only (the value subvector).

I think that to do what you need, you can use [Stable]SortByValues and then StableSortByKeys.

(Perhaps we might add [Stable]SortBy[KeysAndValues|ValuesAndKeys] in future...)

Mirek

[Updated on: Mon, 22 May 2017 12:02]

Report message to a moderator

Re: stable sort bug.. or looks like it [message #48131 is a reply to message #48130] Mon, 22 May 2017 20:45 Go to previous messageGo to next message
aftershock is currently offline  aftershock
Messages: 143
Registered: May 2008
Experienced Member
stablesortbykey is better... but then value information is lost..
Only a new function would help.
in this case [Stable]SortBy[KeysAndValues| could help as I have custom comparison function..
The aim is to keep pair/value relationship..





[Updated on: Mon, 22 May 2017 20:50]

Report message to a moderator

Re: stable sort bug.. or looks like it [message #48132 is a reply to message #48131] Tue, 23 May 2017 01:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
aftershock wrote on Mon, 22 May 2017 20:45
stablesortbykey is better... but then value information is lost..


What do you mean by "lost"? Not sorted by, or damaged by SortByKeys? (that would be a bug).
Re: stable sort bug.. or looks like it [message #48135 is a reply to message #48132] Tue, 23 May 2017 11:18 Go to previous messageGo to next message
aftershock is currently offline  aftershock
Messages: 143
Registered: May 2008
Experienced Member
I mean
before the operation stablesortbykey

we have key/value pair
(tester_withdraw_when) 0

after the operation

(tester_withdraw_when) 3

So the unity of key/pair is not kept... the key loses its value to something else.
Re: stable sort bug.. or looks like it [message #48136 is a reply to message #48135] Tue, 23 May 2017 14:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
aftershock wrote on Tue, 23 May 2017 11:18
I mean
before the operation stablesortbykey

we have key/value pair
(tester_withdraw_when) 0

after the operation

(tester_withdraw_when) 3

So the unity of key/pair is not kept... the key loses its value to something else.


That is really weird. I have just tested with this code:

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	VectorMap<int, String> map;

	for(int i = 0; i < 100; i++) {
		int n = Random(200);
		map.Add(n, FormatIntRoman(n) + " " + AsString(n) + " " + AsString(i));
	}
	
	DUMPM(map);
	
	StableSortByKey(map);
	
	DUMPM(map);
}


and everything seems 100% fine.

Can you post your testcase please?

Mirek
Re: stable sort bug.. or looks like it [message #48137 is a reply to message #48136] Wed, 24 May 2017 11:46 Go to previous message
aftershock is currently offline  aftershock
Messages: 143
Registered: May 2008
Experienced Member
I reexamined the data.

You are right , it works.. there is nothing to do.
I must have misread the data.
Previous Topic: Writing Bits object to disk
Next Topic: How to distribute some parts of Core in another library?
Goto Forum:
  


Current Time: Fri Mar 29 09:25:42 CET 2024

Total time taken to generate the page: 0.01856 seconds