Giter Club home page Giter Club logo

suffixarray's Introduction

倍增构造后缀数组

时间复杂度 $\mathcal{O}(n\log n)$,空间复杂度 $\mathcal{O}(n)$(但处理大数据集时需要注意有常数)。

使用场景

该后缀数组需要保证输入为 utf-8 编码,在此基础上支持中文。使用 C++ 编写,并使用 Cython 构建 Python 库,因此支持的语言有 C++ 和 Python。

已有函数

  • size():返回文本串长度。
  • get_id(suf_rank):输入后缀排名(1-index),返回其在文本串中的位置(0-index)。
  • get_suf(suf_rank):输入后缀排名(1-index),返回对应后缀。
  • get_rank(suf_id):输入后缀左边界位置(0-index),返回对应字典序排名。
  • get_count(pattern):输入模式串,返回其在文本串中出现的次数。
  • get_prob(prompt):输入一段文本,返回其下一个字的概率分布。
  • get_branch_entropy(prompt):输入一段文本,返回其右分支熵。
  • get_mutual_information(text):输入一段文本,返回其互信息大小。

部署方式

执行

python setup.py build_ext --inplace

即可在当前目录下生成库文件。可以直接复制粘贴到使用该库的代码同路径下使用。

不足

  • 没有使用线性的构造算法(先这样吧)
  • 空间常数不小,不便用于大数据集
  • 没有充足的测试(目前仅用于个人使用,是一种能用就行的状态)

suffixarray's People

Contributors

hkr04 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.