struct::set

Documentation is at

This part of the struct (data structures) submodule of tcllib provides procedures for manipulating sets.


escargo 16 Feb 2007 - The documentation assumes that you can guess how sets are implemented.

For example, there are no examples. The published interface does not say how to create a set, nor how to determine the value of a set.

Apparently these sets are built on top of lists; wherever a set argument is used by a ::struct::set subcommand, a list will work.

Therefore, there is no need to have a set constructor (since you can just use a list). There is also no need for a separate iterator over a set, since a set is a list.

But the documentation does not make that clear.


LV So, then, let's provide some examples.

  package require Tcl
  package require struct::set

 ::struct::set include set1 1
 ::struct::set include set2 a
 ::struct::set include set2 b
 ::struct::set include set2 c
 ::struct::set include set3 dog

 ::struct::set add set1 $set2

 set mt [::struct::set empty $set1]
 puts $mt

 puts [::struct::set size $set1]

 puts [::struct::set contains $set1 a]
 puts [::struct::set contains $set1 z]

 puts [::struct::set union $set1 $set2 $set3] 
 puts [::struct::set intersect $set1 $set2 $set3] 
 puts [::struct::set intersect $set1 $set2 ] 

See struct / tcllib