$List Add Unique: Difference between revisions
m (1 revision) |
mNo edit summary |
||
Line 2: | Line 2: | ||
<span class="pageSubtitle"><section begin="desc" />Conditionally add an item to a $list<section end="desc" /></span> | <span class="pageSubtitle"><section begin="desc" />Conditionally add an item to a $list<section end="desc" /></span> | ||
<p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $List_Add_Unique function is [[ | <p class="warning">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)]].</p> | ||
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. | ||
$List_Add_Unique accepts two arguments and returns one of the following: | $List_Add_Unique accepts two arguments and returns one of the following: | ||
<ul> | <ul> | ||
<li>The item number of the added string. | <li>The item number of the added string. | ||
<li>The negative of the item number that exactly matches the string being added. | <li>The negative of the item number that exactly matches the string being added. | ||
</ul> | </ul> | ||
The first argument is the $list identifier of the $list to which the string is to be added. This is a required argument. | The first argument is the $list identifier of the $list to which the string is to be added. This is a required argument. | ||
Line 19: | Line 18: | ||
$List_Add_Unique is a callable $function (:hdref refid=callfun.). | $List_Add_Unique is a callable $function (:hdref refid=callfun.). | ||
==Syntax== | ==Syntax== | ||
<p class="syntax"><section begin="syntax" /> [%RC =] $List_Add_Unique(list, string) | <p class="syntax"><section begin="syntax" /> [%RC =] $List_Add_Unique(list, string) | ||
Line 25: | Line 25: | ||
</p> | </p> | ||
<p class="caption">%RC is the item number of the added string or the negative matching item number.</p> | <p class="caption">%RC is the item number of the added string or the negative matching item number.</p> | ||
All errors in $List_Add_Unique result in request cancellation. | All errors in $List_Add_Unique result in request cancellation. | ||
Line 33: | Line 32: | ||
$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. | $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: | 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 | IF %IN GT 0 THEN | ||
%RC = $ListIns(%CLIST, %IN, 1) | |||
ELSE | ELSE | ||
%IN = -%IN | |||
%RC = $ListRep(%CLIST, %IN, $ListInf(%CLIST, %IN) +1 ) | |||
END IF | END IF | ||
</p> | </p> | ||
This $function is new in Version 6.3. | |||
<p> | |||
<ul class="smallAndTightList"> | <ul class="smallAndTightList"> | ||
<li>[[Sirius functions]]</li> | <li>[[Sirius functions]]</li> | ||
Line 54: | Line 54: | ||
<li>[[Japanese functions]]</li> | <li>[[Japanese functions]]</li> | ||
<li>[[Sir2000 Field Migration Facility]]</li> | <li>[[Sir2000 Field Migration Facility]]</li> | ||
</ul> | </ul> | ||
</p> | </p> | ||
<p class="caption">Products authorizing $List_Add_Unique | <p class="caption">Products authorizing $List_Add_Unique | ||
</p> | </p> | ||
[[Category:$Functions|$List_Add_Unique]] | [[Category:$Functions|$List_Add_Unique]] |
Revision as of 19:12, 10 February 2011
<section begin="desc" />Conditionally add an item to a $list<section end="desc" />
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 accepts two arguments and returns one of the following:
- The item number of the added string.
- The negative of the item number that exactly matches the string being added.
The first argument is the $list identifier of the $list to which the string is to be added. This is a required argument.
The second argument is the string to add to the $list. This is a required argument.
$List_Add_Unique is a callable $function (:hdref refid=callfun.).
Syntax
<section begin="syntax" /> [%RC =] $List_Add_Unique(list, string) <section end="syntax" />
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
This $function is new in Version 6.3.