RedKnight91

map_to_value_sorted_key_list

Jun 5th, 2020
1,396
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///@param map
  2. ///@param ascending
  3.  
  4. var map = argument0
  5. var ascending = argument1
  6.  
  7. var keys = ds_list_create()
  8. var values = ds_list_create()   //Helper structure
  9.  
  10. var key = map_first(map)
  11. while (!is_undefined(key)) {
  12.     var value = map[? key]
  13.     var size = ds_list_size(keys)
  14.    
  15.     for (var i = 0; i < size; ++i) {
  16.         var lesser = (value < values[| i])
  17.         if (ascending == lesser)    //XNOR (true if both true or both false)
  18.             break
  19.     }
  20.    
  21.     ds_list_insert(values, i, value)
  22.     ds_list_insert(keys, i, key)
  23.    
  24.     key = map_next(map, key)
  25. }
  26.  
  27. ds_list_destroy(values)
  28.  
  29. return keys
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×