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.2.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.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: string_repetition-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 ddad36041cf8b1d650997247d49610d71f652eb4e5758b3b111636bb5bba20cd
MD5 ffb228da41a4098432ad659bc2b97497
BLAKE2b-256 8f873336a0dcf08e016fae93dad6b3f60a6cd5069821c4c2096ab1e6c917cbc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for string_repetition-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35911ae71fdcf9a99282374927e7a59e56612e7473ffd2752303ec6d75f79603
MD5 f20c2d7243182b6d2a45b81ea35815f5
BLAKE2b-256 a9c0d2b01f4011cc67b5912df437b876308cc2b1c3a9fb50598c92e2991bd4e5

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