Set Utilities #19

Parent #72Owner #29Flags readSource hellcore/hellcore.db

Aliases: Set Utilities, set_utilities

9 verbs · 11 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
unionthis none thisrxd#1911
intersectionthis none thisrxd#1922
diff*erencethis none thisrxd#199
containsthis none thisrxd#1912
exclusive_or xorthis none thisrxd#1919
difference_suspended diff_suspendedthis none thisrxd#1911
equalthis none thisrxd#1922
intersection_preserve_casethis none thisrxd#1914
subtractthis none thisrxd#196

Properties

PropertyDefinerFlagsOwnerValue
help_msg#72rc#29
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"}
aliases#1rc#29{"Set Utilities", "set_utilities"}
description#1rc#29{"This is the Set Utilities utility package. See `help $set_utils' for more details."}
object_size#1r#29{6097, 1298433815}
hidden_verbs#1rc#29<clear>
phelp_msg#1rc#29<clear>
weight#1rc#29<clear>
owner_verbs#1rc#29<clear>
plural_name#1rc#29<clear>
client_image#1rc#29<clear>
listening#1rc#29<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n19_5 #19:difference_suspended n48_8 #48:suspend_if_needed n19_5->n48_8

Source

union

Spec this none thisFlags rxdOwner #29Definer #19

Referenced by

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

Spec this none thisFlags rxdOwner #29Definer #19

Referenced by

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

Spec this none thisFlags rxdOwner #29Definer #19

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

Spec this none thisFlags rxdOwner #29Definer #19

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

Spec this none thisFlags rxdOwner #29Definer #19

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

Spec this none thisFlags rxdOwner #29Definer #19

Referenced by

none

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$command_utils:suspend_if_needed(0);
9endfor
10endfor
11return set;

equal

Spec this none thisFlags rxdOwner #29Definer #19

Referenced by

none

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

Spec this none thisFlags rxdOwner #29Definer #19

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;

subtract

Spec this none thisFlags rxdOwner #361Definer #19

Referenced by

none

Source

1set1 = args[1];
2set2 = args[2];
3for x in (set2)
4set1 = setremove(set1, x);
5endfor
6return set1;