struct::set(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– struct::set(n) β€” Tcl Data Structures πŸ’–

okay bestie, gather round, because we're talking about struct::set, the Tcl Data Structures era of your life that you didn't know you needed. it's giving math class but make it cute. it's giving finite sets and zero drama. let's GO. πŸŽ€


✨ NAME ✨

struct::set β€” procedures for manipulating sets πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

package require Tcl 8.5 9

package require struct::set ?2.2.4?

::struct::set empty set

::struct::set size set

::struct::set contains set item

::struct::set union ?set1...?

::struct::set intersect ?set1...?

::struct::set difference set1 set2

::struct::set symdiff set1 set2

::struct::set intersect3 set1 set2

::struct::set equal set1 set2

::struct::set include svar item

::struct::set exclude svar item

::struct::set add svar set

::struct::set subtract svar set

::struct::set subsetof A B

🌸 DESCRIPTION 🌸

so the ::struct::set namespace is literally just a little home for several genuinely useful commands that process finite sets. that's it. that's the vibe. no cap. ✨

it exports exactly one command, struct::set, and all the functionality lives as subcommands under it. one command, many talents. main character energy fr fr. πŸ‘‘

note bestie: as of version 2.2 of this package, a critcl-based C implementation is available. HOWEVER (and this is important) that implementation requires Tcl 8.4 to run. so, like, keep that in mind. 🫢

πŸ’… COMMANDS πŸ’…

  • ::struct::set empty set β€” returns a boolean telling you if the set is empty (true) or not (false). it's the vibe check for "is there literally anything in here". πŸ•³οΈ
  • ::struct::set size set β€” returns an integer greater than or equal to zero. it's the number of elements in the set β€” in other words, its cardinality. it's the headcount. the census. the "how many of us are here". πŸ“Š
  • ::struct::set contains set item β€” returns a boolean telling you if the set contains item (true) or not (false). are they on the list or are they not on the list. 🎟️
  • ::struct::set union ?set1...? β€” computes the set containing the union of set1, set2, etc., i.e. "set1 + set2 + ...", and returns that set as the result of the command. everyone's invited, it's a group chat. πŸ«‚
  • ::struct::set intersect ?set1...? β€” computes the set containing the intersection of set1, set2, etc., i.e. "set1 * set2 * ...", and returns that set as the result of the command. only the ones that showed up to every hangout. πŸ”₯
  • ::struct::set difference set1 set2 β€” computes the set containing the difference of set1 and set2, i.e. ("set1 - set2"), and returns that set as the result of the command. it's who's in set1 that is not in set2. 😌
  • ::struct::set symdiff set1 set2 β€” computes the set containing the symmetric difference of set1 and set2, i.e. ("(set1 - set2) + (set2 - set1)"), and returns that set as the result of the command. the ones who are exclusive to exactly one side. it's giving "we don't overlap and that's fine". πŸ¦‹
  • ::struct::set intersect3 set1 set2 β€” this one is a combo of intersect and difference. it returns a three-element list containing "set1*set2", "set1-set2", and "set2-set1", in this order. in other words: the intersection of the two parameter sets, and their differences. three for the price of one, ate. πŸ“
  • ::struct::set equal set1 set2 β€” returns a boolean telling you if the two sets are equal (true) or not (false). same energy, same contents. ⭐
  • ::struct::set include svar item β€” the element item is added to the set specified by the variable name in svar. the return value of the command is empty. this is the equivalent of lappend for sets. if the variable named by svar does not exist, it will be created. ✨
  • ::struct::set exclude svar item β€” the element item is removed from the set specified by the variable name in svar. the return value of the command is empty. this is a near-equivalent of lreplace for sets. bye bestie πŸ‘‹
  • ::struct::set add svar set β€” all the elements of set are added to the set specified by the variable name in svar. the return value of the command is empty. this is like the include method, but for adding a whole set at once. if the variable named by svar does not exist, it will be created. πŸŽ‰
  • ::struct::set subtract svar set β€” all the elements of set are removed from the set specified by the variable name in svar. the return value of the command is empty. this is like the exclude method, but for removing a whole set. mass unfollow, but for math. πŸ’€
  • ::struct::set subsetof A B β€” returns a boolean telling you if the set A is a true subset of, or equal to, the set B (true) or not (false). is A fully contained in B's world? πŸ‘‘

πŸ”— REFERENCES πŸ”—

(this section is empty in the original β€” even icons need a breather) 🧚


πŸ™ˆ BUGS, IDEAS, FEEDBACK πŸ™ˆ

ngl, this document and the package it describes will undoubtedly contain bugs and other problems. it's fine. it's fine!! 😭 please report such in the category struct :: set of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist.

please also report any ideas for enhancements you may have for either the package and/or the documentation. we want the glow-up. 🫢

when proposing code changes, please provide unified diffs, i.e. the output of diff -u. no vibes-only patches, bestie.

note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. periodt. πŸ’…


πŸ‘‘ KEYWORDS πŸ‘‘

cardinality, difference, emptiness, exclusion, inclusion, intersection, membership, set, symmetric difference, union


🌈 CATEGORY 🌈

Data structures


Copyright (c) 2004-2008 Andreas Kupries <andreas_kupries@users.sourceforge.net>


and that's the whole page, bestie!! this was brought to you by tcllib, version 2.2.5, under the name struct::set(n) β€” from the Tcl Data Structures section. mwah. stay set-theoretic. πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from