Skip to main content

一个高效的字符串重复检测算法

Project description

String Repetition Detector

一个基于后缀自动机的高效字符串重复检测工具,可以找出字符串中符合指定长度和重复次数的重复子串。

安装方法

从源码安装

# 克隆仓库
git clone https://github.com/your-username/string_repetition.git
cd string_repetition

# 安装到当前Python环境
pip install -e .

直接从PyPI安装(假设已发布)

pip install string_repetition

基本用法

from string_repetition import StringRepetitionDetector

# 创建检测器实例
detector = StringRepetitionDetector(min_length=3, min_repeats=2)

# 检测单个字符串
text = "abcabcabcabc"
result = detector.detect(text)

if result.has_repetition:
    print(f"发现重复: '{result.substring}' 重复了 {result.repetition_count} 次")
    print(f"位置: {result.start_pos}-{result.end_pos}")
else:
    print("没有发现符合条件的重复")

# 批量检测多个字符串
texts = ["abcabc", "defghi", "xyzxyzxyz"]
results = detector.detect_batch(texts)
for text, result in zip(texts, results):
    print(f"文本 '{text}': {'有重复' if result.has_repetition else '无重复'}")

高级用法

# 并行处理长文本
long_text = "abc" * 1000000
result = detector.detect_string(long_text, parallel=True)

# 自定义参数
custom_detector = StringRepetitionDetector(
    min_length=5,    # 最小重复子串长度
    min_repeats=3    # 最小重复次数
)

运行测试

# 从项目根目录运行
python -m unittest discover tests

# 或者使用pytest
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

string_repetition-0.3.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

string_repetition-0.3.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file string_repetition-0.3.1.tar.gz.

File metadata

  • Download URL: string_repetition-0.3.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for string_repetition-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e0414bee7b2dae207d51666611ea6bbff16edea18fa2167eb414d0846cb0c431
MD5 99ba52f1bc0d203ad19aaf8185b15926
BLAKE2b-256 8e92f693c44ab3c4df05428b2788f876da4c5d362aa638970d474ad69fa6d0c7

See more details on using hashes here.

File details

Details for the file string_repetition-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for string_repetition-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92a294700a13a01f3725df1309c3a5bfaf458803de9e69c1e92ce257b5370008
MD5 2d7b95b0937f1ef2b60ad6e87b51cb73
BLAKE2b-256 023ed8fd8d9f23e395c51d7095d9368ee94c560eae8f0585bc4bcf56314ab011

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page