Skip to main content

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

Project description

String Repetition Detector

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

安装方法

从源码安装

# 克隆仓库
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.0.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.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: string_repetition-0.3.0.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.0.tar.gz
Algorithm Hash digest
SHA256 b3492779193cef4f8bfd48c0e6157a693eb8301b4a78ea107f1ccaabfcf30d13
MD5 8aaac9a36477e83dc2708dbd69fdccf5
BLAKE2b-256 b1d217f191899de7fe3da8f16e8101cb5483ad6aa8e7bdf11d7ba7ffe2221b0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for string_repetition-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94cc253b1d0df59766cccb7761a3b388c041295574c9431bdc5e9a80ee471ad2
MD5 2ede03af52fccb1146ccb8c724a791d7
BLAKE2b-256 88bb454d21d7f207dea83ec295874b0103b639420be3c15ac9d7644ec4591a78

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