marisa-trie README

The project's README from github.com/pytries/marisa-trie. As one markdown file: README.md.

MARISA Trie

|PyPI Version| |PyPI Status| |PyPI Python Versions| |Github Build Status|

.. tip::

Become **my boss** to help me work on this awesome software, and make the world better:

|Patreon|

Static memory-efficient Trie-like structures for Python (3.9+) based on marisa-trie_ C++ library.

String data in a MARISA-trie may take up to 50x-100x less memory than in a standard Python dict; the raw lookup speed is comparable; trie also provides fast advanced methods like prefix search.

.. note::

There are official SWIG-based Python bindings included
in C++ library distribution; this package provides alternative
Cython-based pip-installable Python bindings.

.. _marisa-trie: https://github.com/s-yata/marisa-trie

Installation

::

python -m pip install -U marisa-trie

Usage

See tutorial_ and API_ for details.

For immutable str -> str mappings, use marisa_trie.StringTrie (implemented as two internal tries plus a compact ID mapping table).

.. _tutorial: https://marisa-trie.readthedocs.io/en/latest/tutorial.html .. _API: https://marisa-trie.readthedocs.io/en/latest/api.html

Current limitations

License

Wrapper code is licensed under MIT License.

Bundled marisa-trie_ C++ library is dual-licensed under LGPL or BSD 2-clause license.

.. |PyPI Version| image:: https://img.shields.io/pypi/v/marisa-trie.svg :target: https://pypi.python.org/pypi/marisa-trie/ .. |PyPI Status| image:: https://img.shields.io/pypi/status/marisa-trie.svg :target: https://pypi.python.org/pypi/marisa-trie/ .. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/marisa-trie.svg :target: https://pypi.python.org/pypi/marisa-trie/ .. |Github Build Status| image:: https://github.com/pytries/marisa-trie/actions/workflows/tests.yml/badge.svg :target: https://github.com/pytries/marisa-trie/actions/workflows/tests.yml .. |Patreon| image:: https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white :target: https://www.patreon.com/mschoentgen

marisa-trie (pytries/marisa-trie)

Searching Database…

这是做什么的?为 Python 提供静态、省内存的类 trie 数据结构,底层基于 marisa-trie 这个 C++ 库。存进去的字符串占用的内存最多可比标准 Python dict 少 50 到 100 倍,查找速度相近,前缀搜索也很快。
它是加到我 Python 项目里的库,还是一个独立的工具?是一个可以用 pip 安装的库,导入到 Python 代码里使用。它提供基于 Cython 的绑定,作为 C++ 库发行包自带的官方 SWIG 绑定的替代方案。
它支持哪些 Python 版本?Python 3.9 或更新版本;GitHub 的 topics 里也列出了对 PyPy3 的支持。
目前有哪些限制?read() 和 write() 只能用于真实文件,不支持文件类对象——这种情况请改用 pickling。BytesTrie 和 RecordTrie 的 .prefixes() 方法相当慢,而且没有对应的迭代器版本;这些 trie 类暴露了 keys() 和 items(),却没有 values()。Mingw32 构建也未经过测试。
这个许可证商用起来省心吗?大体上可以:包装层代码采用 MIT 许可证,但捆绑的 marisa-trie C++ 库同时以 LGPL 或 BSD 2-clause 双许可证发布,所以如果你要再分发 C++ 部分,需要查看 LGPL 的条款。
这个包提供哪几种 trie?文档主要介绍的类是 StringTrie,用于不可变的 str 到 str 映射,内部由两个 trie 加上一个紧凑的 ID 映射表实现。此外还提供 Trie、BytesTrie 和 RecordTrie 这几个类。
这些结构被描述为“静态”的——是不是意味着只读?是的——你先构建一次 trie,之后就只能查询它。StringTrie 明确定位为不可变的 str 到 str 映射,也就是说用不可更新换取紧凑的内存占用和快速的查找。
MARISA 是什么?它是这个包底层的 C++ 库:marisa-trie 实现了这些紧凑的 trie 结构和内存布局,而这个仓库在其之上增加了基于 Cython 的 Python 绑定,并发布到 PyPI 上。
Creator
pytries
Size
3.2 MB
Stars
1.1K
Age
14y
Commits · 90 Days