Set Utilities #27

Parent #79Owner #36Flags readSource RPG Core/rpgcore-patched.db

Aliases: Set Utilities, set_utilities

8 verbs · 6 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
unionthis none thisrxd#2711
intersectionthis none thisrxd#2722
diff*erencethis none thisrxd#279
containsthis none thisrxd#2712
exclusive_or xorthis none thisrxd#2719
difference_suspended diff_suspendedthis none thisrxd#2711
equalthis none thisrxd#2722
intersection_preserve_casethis none thisrxd#2714

Properties

PropertyDefinerFlagsOwnerValue
help_msg#79rc#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#1c#36<clear>
aliases#1rc#36{"Set Utilities", "set_utilities"}
description#1rc#36{"This is the Set Utilities utility package. See `help $set_utils' for more details."}
object_size#1r#36{5984, -1090650497}
html#1rc#36<clear>

Ancestry

Ancestors (nearest first): #79 Generic Utilities Package#1 Root Class

Children: none

Source

union

Spec this none thisFlags rxdOwner #36Definer #27

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 #36Definer #27

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 #36Definer #27

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 #36Definer #27

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 #36Definer #27

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 #36Definer #27

Referenced by

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

Spec this none thisFlags rxdOwner #36Definer #27

Referenced by

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 #36Definer #27

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;