Metadata-Version: 2.5
Name: iibags
Version: 0.0.4
Summary: 带显式算术的计数多重集合。
Project-URL: Homepage, https://pypi.org/project/iibags/
Author-email: lqxnjk <lqxnjk@qq.com>
License: MIT
License-File: LICENSE
Keywords: bag,counter,counting,frequency,multiset
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# iibags

[English](#english) | 中文

带显式算术的计数多重集合。

## 安装

```console
pip install iibags
```

## 用法

```python
from iibags import MultiBag

bag = MultiBag(["a", "b", "a"])
bag.count("a")          # 2
bag.count("zzz")        # 0，且没有创建键
bag.total()             # 3
bag.unique()            # 2
bag.most_common(1)      # [('a', 2)]

bag.discard("a", 5)     # 归零并删除键
"a" in bag              # False
```

## 说明

与 `Counter` 的差别：读一个不存在的键**不会创建它**；扣减超额时归零并删除键，不留负数；`n_count` 传负数直接抛 `ValueError`——负计数是「库存怎么变成 -3」的常见根源。

## 许可证

MIT

---

<a id="english"></a>
## English

A counting multiset with explicit arithmetic.

## Install

```console
pip install iibags
```

## Usage

```python
from iibags import MultiBag

bag = MultiBag(["a", "b", "a"])
bag.count("a")          # 2
bag.count("zzz")        # 0，且没有创建键
bag.total()             # 3
bag.unique()            # 2
bag.most_common(1)      # [('a', 2)]

bag.discard("a", 5)     # 归零并删除键
"a" in bag              # False
```

## Notes

Unlike `Counter`: reading a missing key does not create it, over-subtracting clamps to zero and drops the key, and a negative `n_count` raises `ValueError`. Negative counts are the usual source of "why is my inventory -3" bugs.

## License

MIT
