uf_add_unique_element_to_array()


Link to this posting

Postby Ursego » 16 Apr 2013, 14:16

The function adds new value to a string array but only if that value doesn't exist in it yet. So, if the whole array is populated using this function only, then, finally, all its elements will be unique. You need to have the function uf_value_exists_in_array() prior to adding uf_add_unique_element_to_array(). It has 2 overloads - for string and long data types:

String:

Code: Select all
/**********************************************************************************************************************
Dscr:         Adds new value to a STRING array but only if that value doesn't exist in it yet. So, if the array
            is populated using this function only, then, finally, all its elements will be unique.
            Another overload does the same for LONG array.
***********************************************************************************************************************
Arg:         as_val - added value
            rs_arr[] (ref) - array to add value to
***********************************************************************************************************************
Developer:   Michael Zuskin -  http://linkedin.com/in/zuskin | http://code.intfast.ca/
**********************************************************************************************************************/
long         ll_new_upper_bound
DataStore   lds_temp

if this.uf_value_exists_in_array(as_val, rs_arr[]) then // uf_value_exists_in_array(): http://code.intfast.ca/viewtopic.php?f=4&t=93
   return
end if

ll_new_upper_bound = UpperBound(rs_arr[]) + 1
rs_arr[ll_new_upper_bound] = as_val

return

Long:

Code: Select all
/**********************************************************************************************************************
Dscr:         Adds new value to a LONG array but only if that value doesn't exist in it yet. So, if the array
            is populated using this function only, then, finally, all its elements will be unique.
            Another overload does the same for STRING array.
***********************************************************************************************************************
Arg:         al_val - added value
            rl_arr[] (ref) - array to add value to
***********************************************************************************************************************
Developer:   Michael Zuskin -  http://linkedin.com/in/zuskin | http://code.intfast.ca/
**********************************************************************************************************************/
long         ll_new_upper_bound
DataStore   lds_temp

if this.uf_value_exists_in_array(al_val, rl_arr[]) then // uf_value_exists_in_array(): http://code.intfast.ca/viewtopic.php?f=4&t=93
   return
end if

ll_new_upper_bound = UpperBound(rs_arr[]) + 1
rl_arr[ll_new_upper_bound] = al_val

return
User avatar
Ursego
Site Admin
 
Posts: 143
Joined: 19 Feb 2013, 20:33



Ketones are a more high-octane fuel for your brain than glucose. Become a biohacker and upgrade yourself to version 2.0!



cron
Traffic Counter

eXTReMe Tracker