$List Add Unique: Difference between revisions
Jump to navigation
Jump to search
m (1 revision) |
mNo edit summary |
||
Line 5: | Line 5: | ||
This function adds an item to a $list if an identical item isn't already there, adding the item to the end of the $list. | This function adds an item to a $list if an identical item isn't already there, adding the item to the end of the $list. | ||
<var>$List_Add_Unique</var> is a [[Calling Sirius Mods $functions|callable]] $function. | <var>$List_Add_Unique</var> is a [[Calling Sirius Mods $functions|callable]] $function. | ||
Line 22: | Line 11: | ||
<p class="syntax"><section begin="syntax" />[%RC =] $List_Add_Unique(list, string) | <p class="syntax"><section begin="syntax" />[%RC =] $List_Add_Unique(list, string) | ||
<section end="syntax" /></p> | <section end="syntax" /></p> | ||
All errors in <var>$List_Add_Unique</var> result in request cancellation. | ===Syntax terms=== | ||
<table class="syntaxTable"> | |||
<tr><th>%rc</th> | |||
<td>A numeric variable that is the item number of the added string, or it is the negative of the item number that exactly matches the string being added.</td></tr> | |||
<tr><th>list</th> | |||
<td>The $list identifier of the $list to which the string is to be added. This is a required argument. </td></tr> | |||
<tr><th>string</th> | |||
<td>The string to add to the $list. This is a required argument. </td></tr> | |||
</table> | |||
==Usage notes== | |||
<ul> | |||
<li>All errors in <var>$List_Add_Unique</var> result in request cancellation. | |||
<var>$List_Add_Unique</var> always adds the indicated string to the end of the $list but does not add it if there's already an identical $list item on the $list. <var>$List_Add_Unique</var> does not assume any order for the $list so sequentially scans the entire $list for matches to the string being added. Because of this, it will generally be more expensive to use than <var>$List_Add_Unique_Ordered</var> for very large $lists though this latter function might not be usable in all cases — say, if the target $list starts out unordered. | <li><var>$List_Add_Unique</var> always adds the indicated string to the end of the $list but does not add it if there's already an identical $list item on the $list. <var>$List_Add_Unique</var> does not assume any order for the $list so sequentially scans the entire $list for matches to the string being added. Because of this, it will generally be more expensive to use than <var>$List_Add_Unique_Ordered</var> for very large $lists though this latter function might not be usable in all cases — say, if the target $list starts out unordered. | ||
<var>$List_Add_Unique</var> returns the either the item number added if no match was found or the negative item number of the matching item if one was found. This return code makes it easy to maintain a parallel $list that contains say a count of the number of times a given value occurred, that is was passed as a string to <var>$List_Add_Unique</var>. | <li><var>$List_Add_Unique</var> returns the either the item number added if no match was found or the negative item number of the matching item if one was found. This return code makes it easy to maintain a parallel $list that contains say a count of the number of times a given value occurred, that is was passed as a string to <var>$List_Add_Unique</var>. | ||
The following illustrates such an approach: | The following illustrates such an approach: | ||
<p class="code"> %IN = $List_Add_Unique(%OLIST, %DATA) | <p class="code">%IN = $List_Add_Unique(%OLIST, %DATA) | ||
IF %IN GT 0 THEN | |||
%RC = $ListIns(%CLIST, %IN, 1) | |||
ELSE | |||
%IN = -%IN | |||
%RC = $ListRep(%CLIST, %IN, $ListInf(%CLIST, %IN) +1 ) | |||
END IF | |||
</p> | </p> | ||
</ul> | |||
<h2>Products authorizing {{PAGENAMEE}}</h2><ul class="smallAndTightList"> | <h2>Products authorizing {{PAGENAMEE}}</h2><ul class="smallAndTightList"> | ||
<li>[[Sirius functions]]</li> | <li>[[Sirius functions]]</li> | ||
Line 55: | Line 54: | ||
<li>[[Sir2000 Field Migration Facility]]</li> | <li>[[Sir2000 Field Migration Facility]]</li> | ||
</ul> | </ul> | ||
[[Category:$Functions|$List_Add_Unique]] | [[Category:$Functions|$List_Add_Unique]] |
Revision as of 19:48, 29 October 2012
Conditionally add an item to a $list
Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $List_Add_Unique function is the AddUnique (Stringlist function).
This function adds an item to a $list if an identical item isn't already there, adding the item to the end of the $list.
$List_Add_Unique is a callable $function.
Syntax
<section begin="syntax" />[%RC =] $List_Add_Unique(list, string) <section end="syntax" />
Syntax terms
%rc | A numeric variable that is the item number of the added string, or it is the negative of the item number that exactly matches the string being added. |
---|---|
list | The $list identifier of the $list to which the string is to be added. This is a required argument. |
string | The string to add to the $list. This is a required argument. |
Usage notes
- All errors in $List_Add_Unique result in request cancellation.
- $List_Add_Unique always adds the indicated string to the end of the $list but does not add it if there's already an identical $list item on the $list. $List_Add_Unique does not assume any order for the $list so sequentially scans the entire $list for matches to the string being added. Because of this, it will generally be more expensive to use than $List_Add_Unique_Ordered for very large $lists though this latter function might not be usable in all cases — say, if the target $list starts out unordered.
- $List_Add_Unique returns the either the item number added if no match was found or the negative item number of the matching item if one was found. This return code makes it easy to maintain a parallel $list that contains say a count of the number of times a given value occurred, that is was passed as a string to $List_Add_Unique.
The following illustrates such an approach:
%IN = $List_Add_Unique(%OLIST, %DATA) IF %IN GT 0 THEN %RC = $ListIns(%CLIST, %IN, 1) ELSE %IN = -%IN %RC = $ListRep(%CLIST, %IN, $ListInf(%CLIST, %IN) +1 ) END IF