StringSet
StringSet 对象是一个容器,用于存储一个或多个唯一的字符串。它类似于数组或向量(例如,Vector),但其优势在于使用字典系统来定位字符串,而不是使用数字索引。因此,您可以比线性搜索 Vector 更快速地查找字符串。
您可以使用 DOpusFactory 对象创建新的 StringSet。StringSet 可以区分大小写(“cat” 和 “CAT” 将被视为两个不同的字符串),也可以不区分大小写。
属性名称 | 返回类型 | 说明 |
---|---|---|
count | int | 返回 StringSet 当前持有的元素数量。 |
empty | bool | 如果 StringSet 为空,则返回 True,否则返回 False。 |
length | int | count 的同义词。 |
size | int | count 的同义词。 |
方法名称 | 参数 | 返回类型 | 说明 |
assign | <StringSet:from> | none | 将另一个 StringSet 的内容复制到这个 StringSet 中。您还可以传递字符串数组或 Vector 对象。 |
clear | none | none | 清除 StringSet 的内容。 |
erase | <string> | none | 如果字符串存在于集合中,则将其擦除。 |
exists | <string> | bool | 如果指定字符串存在于集合中,则返回 True。 |
insert | <string> | bool | 如果字符串不存在,则将其插入到集合中。如果成功,则返回 True。 |
merge | <StringSet:from> | none | 将另一个 StringSet 的内容与这个 StringSet 合并。 |
最后更新于