是否有类似于TCL中的std :: set的数据结构?

时间:2012-01-07 17:29:07

标签: list data-structures dictionary set tcl

TCL有一个名为dict的数据结构,它维护一组键值对。

是否有其他数据结构维护一组密钥(没有值)?

如果不是,那么也许某人已经在dict上用空值写了一个简单的适配器?

3 个答案:

答案 0 :(得分:4)

您可以使用tcllib包::struct::set

http://tcllib.sourceforge.net/doc/struct_set.html

答案 1 :(得分:1)

只需使用一个列表。

set example [list "key1" "key2" "key3"]
if {[lsearch -exact $example "key3"] != -1} {
    puts "found your key!"
} else {
    puts "your key is not in the list"
}

也许您应该提出更具体的问题以获得更准确的答案。 dict的替代方法是array,它不保留密钥的顺序。

答案 2 :(得分:0)

另一种方法是将所有内容累积为$bucket

然后做:

set uniqueItems [lsort -unique $bucket]