Set Utilities #27
Aliases: Set Utilities, set_utilities
8 verbs · 6 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
union | this none this | rxd | #27 | 11 |
intersection | this none this | rxd | #27 | 22 |
diff*erence | this none this | rxd | #27 | 9 |
contains | this none this | rxd | #27 | 12 |
exclusive_or xor | this none this | rxd | #27 | 19 |
difference_suspended diff_suspended | this none this | rxd | #27 | 11 |
equal | this none this | rxd | #27 | 22 |
intersection_preserve_case | this none this | rxd | #27 | 14 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
help_msg | #79 | rc | #36 | list of 22{"This object is useful for operations that treat lists as sets (i.e.,", "without concern about order and assuming no duplication).", "", " union(set, set, ...) => union", " intersection(set, set, ...) => intersection", " intersection_preserve_case(base set, set, set, ...)", " => intersection with the case of the base set's elements preserved", "", " diff*erence(set1, set2, ..., setn)", " => result of removing all elements of sets 2..n from set 1.", "", " difference_suspended(set1, set2, ..., setn)", " => same as above except it suspends as needed.", "", " exclusive_or(set, set, set, ...)", " => all elements that are contained in exactly one of the sets", "", " contains(set1, set2, ..., setn)", " => true if and only if all of sets 2..n are subsets of set 1", "", " equal(set1, set2)", " => true if and only if set1 and set2 are equal"} |
key | #1 | c | #36 | <clear> |
aliases | #1 | rc | #36 | {"Set Utilities", "set_utilities"} |
description | #1 | rc | #36 | {"This is the Set Utilities utility package. See `help $set_utils' for more details."} |
object_size | #1 | r | #36 | {5984, -1090650497} |
html | #1 | rc | #36 | <clear> |
Ancestry
Ancestors (nearest first): #79 Generic Utilities Package → #1 Root Class
Children: none
Source
union
Referenced by
- #32:@ansi-setup line 94:
$set_utils:union - #90:parse_refuse_arguments line 18:
$set_utils:union - #104:loot line 24:
$set_utils:union - #109:load line 5:
$set_utils:union - #109:load line 6:
$set_utils:union
Source
1"Returns the set union of all of the lists provided as arguments."; 2if (!args) 3return {}; 4endif 5{set, @rest} = args; 6for l in (rest) 7for x in (l) 8set = setadd(set, x); 9endfor 10endfor 11return set;
intersection
Referenced by
- #4:classes_2 line 10:
$set_utils:intersection - #10:w*ho line 18:
$set_utils:intersection - #83:help_msg line 16:
$set_utils:intersection - #91:follow line 55:
$set_utils:intersection - #91:capture line 2:
$set_utils:intersection - #91:capture line 4:
$set_utils:intersection - #91:_leash line 18:
$set_utils:intersection - #91:release line 10:
$set_utils:intersection - #104:do_attack line 27:
$set_utils:intersection - #107:g*et line 2:
$set_utils:intersection - #107:capture line 1:
$set_utils:intersection - #107:capture line 3:
$set_utils:intersection - #107:release line 10:
$set_utils:intersection - #134:sell_product line 40:
$set_utils:intersection
Source
1"Returns the set intersection of all the lists provided as arguments."; 2if (!args) 3return {}; 4endif 5max = 0; 6{result, @rest} = args; 7for set in (rest) 8if (length(result) < length(set)) 9set1 = result; 10set2 = set; 11else 12set1 = set; 13set2 = result; 14endif 15for x in (set1) 16if (!(x in set2)) 17set1 = setremove(set1, x); 18endif 19endfor 20result = set1; 21endfor 22return result;
diff*erence
Referenced by
none
Source
1"Usage: diff(set 1, set 2, ..., set n)"; 2"Returns all elements of set 1 that are not in sets 2..n"; 3{set, @rest} = args; 4for l in (rest) 5for x in (l) 6set = setremove(set, x); 7endfor 8endfor 9return set;
contains
Referenced by
none
Source
1"True if the first list given is a superset of all subsequent lists."; 2"False otherwise. {} is a superset of {} and nothing else; anything is"; 3"a superset of {}. If only one list is given, return true."; 4{?super = {}, @rest} = args; 5for l in (rest) 6for x in (l) 7if (!(x in super)) 8return 0; 9endif 10endfor 11endfor 12return 1;
exclusive_or xor
Referenced by
none
Source
1"Usage: exclusive_or(set, set, ...)"; 2"Return the set of all elements that are in exactly one of the input sets"; 3"For two sets, this is the equivalent of (A u B) - (A n B)."; 4if (!args) 5return {}; 6endif 7{set, @rest} = args; 8so_far = set; 9for l in (rest) 10for x in (l) 11if (x in so_far) 12set = setremove(set, x); 13else 14set = setadd(set, x); 15endif 16endfor 17so_far = {@so_far, @l}; 18endfor 19return set;
difference_suspended diff_suspended
Referenced by
- #71:find_duplicate_verbs line 10:
$set_utils:difference_suspended
Source
1"Usage: diff_suspended(set 1, set 2, ..., set n)"; 2"Returns all elements of set 1 that are not in sets 2..n"; 3"Suspends as needed if the lists are large."; 4{set, @rest} = args; 5for l in (rest) 6for x in (l) 7set = setremove(set, x); 8(ticks_left() < 4000) && suspend(0); 9endfor 10endfor 11return set;
equal
Referenced by
- #116:l*ook line 29:
$set_utils:equal - #119:tell_exits line 9:
$set_utils:equal
Source
1"True if the two lists given contain the same elements."; 2"False otherwise."; 3{set1, set2} = args; 4while (set1) 5{elt, @set1} = set1; 6if (elt in set2) 7set2 = setremove(set2, elt); 8while (elt in set2) 9set2 = setremove(set2, elt); 10endwhile 11while (elt in set1) 12set1 = setremove(set1, elt); 13endwhile 14else 15return 0; 16endif 17endwhile 18if (set2) 19return 0; 20else 21return 1; 22endif
intersection_preserve_case
Referenced by
none
Source
1"Copied from Fox (#54902):intersection Mon Dec 27 17:02:57 1993 PST"; 2"a version of $set_utils:intersection that maintains the property that everything in the return value is in the first argument, even considering case"; 3if (!args) 4return {}; 5endif 6{result, @rest} = args; 7for s in (rest) 8for x in (result) 9if (!(x in s)) 10result = setremove(result, x); 11endif 12endfor 13endfor 14return result;