struct::set(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– struct::set β€” bestie edition πŸ’–

okay so this is the page for struct::set from the Tcl Data Structures corner of the tcllib world, and it's genuinely one of my faves. like yes we are doing set theory today and we are going to slay it. it's giving finite sets. it's giving math but make it Tcl. πŸŽ€


✨ NAME ✨

struct::set β€” procedures for manipulating sets. that's it, that's the whole job, and she does it beautifully. πŸ’…


🌸 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 πŸ¦‹

the ::struct::set namespace is literally a whole little friend group of super useful commands for processing finite sets. no cap.

she exports exactly one command, struct::set, and all the functionality lives in there as subcommands. one command to rule them all, main character energy fr fr. πŸ‘‘

Note: as of version 2.2 of this package there's a critcl-based C implementation available πŸš€ β€” but heads up bestie, that implementation requires Tcl 8.4 to run. iykyk.

πŸ’– COMMANDS πŸ’–

  • ::struct::set empty set β€” hands you a boolean, and it's telling you whether the set is empty (true) or not (false). vibe check on the void. 🌈
  • ::struct::set size set β€” returns an integer that's >= 0, aka how many elements are chillin' in the set. this is its cardinality, if you wanna be fancy about it. ✨
  • ::struct::set contains set item β€” boolean time again: does the set contain the element item (true) or nah (false)? membership check, iconic. πŸŽ€
  • ::struct::set union ?set1...? β€” computes the set holding the union of set1, set2, etc., i.e. "set1 + set2 + ...", and returns that set as the result of the command. everybody's invited, no one gets left out. 🫢
  • ::struct::set intersect ?set1...? β€” computes the set with the intersection of set1, set2, etc., i.e. "set1 * set2 * ...", and returns that set. only the ones that show up for everyone. πŸ’…
  • ::struct::set difference set1 set2 β€” computes the set with the difference of set1 and set2, i.e. ("set1 - set2"), and returns that set as the result of the command. it's set1 minus whoever's also in set2. πŸ’€
  • ::struct::set symdiff set1 set2 β€” computes the set with the symmetric difference of set1 and set2, i.e. ("(set1 - set2) + (set2 - set1)"), and returns that set as the result of the command. yes bestie, both differences, combined. the "you can't sit with us unless you're exclusively ours" of set ops. 😭
  • ::struct::set intersect3 set1 set2 β€” this one is a combo move 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-one deal, we love to see it. πŸ“
  • ::struct::set equal set1 set2 β€” boolean, as always: are the two sets equal (true) or not (false)? πŸ¦‹
  • ::struct::set include svar item β€” adds the element item to the set specified by the variable name in svar. the return value of the command is empty. this is the equivalent of lappend but for sets. if the variable named by svar doesn't exist, it gets created. πŸ’œ
  • ::struct::set exclude svar item β€” removes the element item from the set specified by the variable name in svar. return value is empty. this is a near-equivalent of lreplace for sets. πŸ™ˆ
  • ::struct::set add svar set β€” all the elements of set get added to the set specified by the variable name in svar. return value is empty. this is like include but for adding a whole entire set at once. if the variable named by svar doesn't exist, it will be created. 🌸
  • ::struct::set subtract svar set β€” all the elements of set get removed from the set specified by the variable name in svar. return value is empty. like exclude, but for removing a whole set in one go. πŸ”₯
  • ::struct::set subsetof A B β€” boolean check: is the set A a true subset of, or equal to, the set B (true), or not (false)? 🌈

⭐ REFERENCES ⭐

(this one's just vibes and empty space, bestie β€” nothing listed here. moving on! πŸ’–)


πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

okay real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. like, for sure. it's giving "trust but verify." 😭

please report such things in the category struct :: set of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. 🫢

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

when proposing code changes, please provide unified diffs, i.e. the output of diff -u. this is not a suggestion, it's the way. πŸ’…

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. yes, that specific button. you got this. πŸŽ€

πŸ”‘ 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 one shipped as part of tcllib 2.2.5, dated with the struct::set(3tcl) footer vibe, and honestly? she ate. go forth and manipulate your finite sets. periodt. πŸ’…βœ¨πŸ’–

πŸ“¦ where this page comes from