Re: My first program: sublime (reverse of "extract" function)

new topic     » goto parent     » topic index » view thread      » older message » newer message
SocIoDim said...
jimcbrown said...

I think I get it. Your example can still be implemented as:

sequence InputData = {0.01, 0.05, 0.08, 0.03, 0.02} 
sequence OutputData = 1 - InputData[2..$] 

NO

I just meant that particular example. This won't help your real code though, so it's not worth delving into.

SocIoDim said...

I think, most optimal way is implement my own sorting function, that will output the sorted data and unsorted indexes. I wrote such function, but erase, because it turned ugly. This is wrong way: replacing the standard language features. This is called the invention of bicycles.

You can do this within the stdlib.

function compare_saving_index(object x, object y) 
	return compare(x[2], y[2]) 
end function 
 
public function sort_with_index(sequence s, integer order = NORMAL_ORDER) 
	sequence x = repeat(0, length(s)) 
	for i = 1 to length(x) do 
		x[i] = {i, s[i]} 
	end for 
	return custom_sort(routine_id("compare_saving_index"), s, order) 
end function 
 
public function get_indexes_from_sorted(sequence s) 
	return vslice(s, 1) 
end function 
 
public function get_values_from_sorted(sequence s) 
	return vslice(s, 2) 
end function 
 
sequence unsortedinput = ... 
sequence sortedandindex = sort_with_index(unsortedinput) 
sequence sortedinput = get_values_from_sorted(sortedandindex) 
sequence idx = get_indexes_from_sorted(sortedandindex) 
sequence sortedoutput = ... sortedinput ... 
sequence unsortedoutput = extract(sortedoutput,idx) 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu