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

List TCL中是否有类似于std::set的数据结构?,list,data-structures,dictionary,set,tcl,List,Data Structures,Dictionary,Set,Tcl,TCL有一个名为的数据结构,它维护一组键值对 是否有另一个数据结构维护键的集合(没有值) 如果没有,那么可能有人已经用空值编写了一个简单的适配器?只需使用一个列表即可 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" } 也许

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

是否有另一个数据结构维护键的集合(没有值)


如果没有,那么可能有人已经用空值编写了一个简单的适配器?

只需使用一个列表即可

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
,它不保留键的顺序。

只需使用一个列表即可

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
,它不保留键的顺序。

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


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


另一种方法是将所有内容累积到例如,
$bucket

然后做:

set uniqueItems [lsort -unique $bucket]

另一种方法是将所有内容累积到例如,
$bucket

然后做:

set uniqueItems [lsort -unique $bucket]

您可以使用
if{“key3”in$example}{…
代替
lsearch
(操作符在8.5中介绍)。老实说,我认为这个问题非常具体地说明了它在寻找什么。列表、映射和集都是具有不同属性的不同数据结构。这不是一个好答案,因为搜索不是O(1)。您可以使用
if{“key3”in$example}{…
而不是
lsearch
(操作符在8.5中介绍)。老实说,我认为这个问题非常具体地说明了它在寻找什么。列表、映射和集都是具有不同属性的不同数据结构。这不是一个好答案,因为搜索不是O(1)。