Skip to content

Commit 8f8e3fa

Browse files
authored
[210_10] 实现 bag 更新/子集/集合运算接口 (#395)
* 实现 bag 更新接口 * 实现 bag 更新/子集/集合运算接口 * wip
1 parent cc5e4cc commit 8f8e3fa

File tree

4 files changed

+692
-3
lines changed

4 files changed

+692
-3
lines changed

devel/210_10.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@
1010
bin/goldfish tests/goldfish/liii/bag-test.scm
1111
```
1212

13+
14+
## 2026/01/30 实现 bag 更新/子集/集合运算接口
15+
### What
16+
补齐 SRFI-113 的 bag 更新、删除、搜索、子集关系与集合运算接口,并在 (liii bag) 中导出与补齐测试。
17+
18+
1. 在 goldfish/srfi/srfi-113.scm 中实现 bag-adjoin / bag-adjoin! / bag-replace / bag-replace! / bag-delete / bag-delete! / bag-delete-all / bag-delete-all! / bag-search!,以及 bag=? / bag<? / bag>? / bag<=? / bag>=? 与 bag-union / bag-intersection / bag-difference / bag-xor 及其线性更新版本,并添加到导出列表
19+
2. 在 goldfish/liii/bag.scm 中导出以上函数
20+
3. 在 tests/goldfish/liii/bag-test.scm 中添加详细注释与覆盖测试
21+
22+
### Why
23+
提供多重集的增删改、搜索、包含关系与集合运算能力,覆盖 SRFI-113 对 bag 的核心语义。
24+
25+
### How
26+
1. bag-adjoin!/bag-adjoin 对元素逐个计数 +1,前者就地修改,后者基于副本
27+
2. bag-replace!/bag-replace 替换等价元素的代表值并保持计数不变
28+
3. bag-delete!/bag-delete 逐个删除一个元素实例,前者就地修改,后者基于副本
29+
4. bag-delete-all!/bag-delete-all 根据列表删除元素实例,列表含重复则多次删除
30+
5. bag-search! 按 comparator 等价查找,命中/未命中分别调用 success/failure 并提供 insert/update/remove 操作
31+
6. 子集关系按“计数包含”判断:每个元素计数满足 <= 或严格 < 关系
32+
7. 相等性要求各元素计数一致
33+
8. union 取计数最大值;intersection 取最小值;difference 按计数相减并截断为 0;xor 取计数绝对差
34+
1335
## 2026/01/29 实现 bag 查询与转换接口
1436
### What
1537
补齐 SRFI-113 的 bag 查询能力与复制/列表转换接口,并在 (liii bag) 中导出与补齐测试。

goldfish/liii/bag.scm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,24 @@
2222
bag-unfold bag-member bag-comparator bag->list
2323
list->bag! bag-copy
2424
bag? bag-contains? bag-empty? bag-disjoint?
25-
bag-size bag-find bag-count bag-any? bag-every?)
25+
bag-size bag-find bag-count bag-any? bag-every?
26+
bag=? bag<? bag>? bag<=? bag>=?
27+
bag-union bag-intersection bag-difference bag-xor
28+
bag-union! bag-intersection! bag-difference! bag-xor!
29+
bag-adjoin bag-adjoin! bag-replace bag-replace!
30+
bag-delete bag-delete! bag-delete-all bag-delete-all!
31+
bag-search!)
2632
(srfi srfi-128))
2733
(export bag bag-unfold bag-member bag-comparator
2834
bag->list list->bag list->bag! bag-copy
2935
bag? bag-contains? bag-empty? bag-disjoint?
30-
bag-size bag-find bag-count bag-any? bag-every?)
36+
bag-size bag-find bag-count bag-any? bag-every?
37+
bag=? bag<? bag>? bag<=? bag>=?
38+
bag-union bag-intersection bag-difference bag-xor
39+
bag-union! bag-intersection! bag-difference! bag-xor!
40+
bag-adjoin bag-adjoin! bag-replace bag-replace!
41+
bag-delete bag-delete! bag-delete-all bag-delete-all!
42+
bag-search!)
3143

3244
(define comp (make-default-comparator))
3345

0 commit comments

Comments
 (0)