普贤教程 › 包参考
set 包
集合
| 项 | 值 |
|---|---|
| 包名 | set |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | set.px |
| 分类 | 数据结构 |
| 文件数 / 行数 | 1 / 199 |
安装与引入
bash
pxpkg init # 首次 pxpkg add set@0.2.0 pxpkg install
px
import set所属分类教程:数据结构
公开接口
| 函数 | 参数 |
|---|---|
st_new | |
st_add | s, v |
st_discard | s, v |
st_has | s, v |
st_len | s |
st_to_list | s |
st_from_list | l |
st_union | a, b |
st_intersection | a, b |
st_difference | a, b |
st_subset | a, b |
其余 14 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
st_clone | s |
st_symmetric_difference | a, b |
st_superset | a, b |
st_disjoint | a, b |
st_equal | a, b |
st_is_empty | s |
st_clear | s |
st_pop | s |
st_update | s, items |
st_difference_update | s, items |
st_to_sorted_list | s |
st_filter | s, pred |
st_any | s |
st_to_string | s |
包内说明(源码头注释)
text
============================================================
普贤生态库:registry/set —— 集合
------------------------------------------------------------
纯函数库(无 IO、无状态,集合状态以 dict 显式传递),双模式一致。
st_new() → dict 空集合
st_add(s, v) → s 插入(幂等,可链式)
st_discard(s, v) → s 删除(不存在也 ok)
st_has(s, v) → bool 是否存在(非 string 一律 false)
st_len(s) → int
st_to_list(s) → [str]
st_from_list(l) → dict 去重建集合
st_union(a, b) → dict
st_intersection(a, b) → dict
st_difference(a, b) → dict a - b
st_subset(a, b) → bool a ⊆ b
元素类型:string(dict 键限定 str,见 docs/语言缺陷.md 写库限制;
int/bool/float 元素请自行转 str,或等官方泛型/任意键支持)。
============================================================