用C++编写后缀数组算法的快速子串/模式搜索Python库

PySubstringSearch的Python项目详细描述


Logo

用C++编写后缀数组算法的快速子串/模式搜索Python库

licensePythonBuildPyPi

目录

关于项目

PySubstringSearch是一个用于在索引文件中搜索子字符串模式的库。该库是用C++编写的,实现速度和效率。该库还使用Msufsort后缀数组构造库进行字符串索引。创建的索引由原始文本和32位后缀数组结构组成。该库依赖于一个专有的容器协议来保存原始文本以及512mb的索引块,以避免后缀数组构造实现的限制。在

该模块实现了两种方法:search_sequential和search_parallel。search_sequential逐个搜索内部块,其中search_parallel同时搜索。当处理大于1gb的大索引时,search_parallel的运行速度会更快。我建议将它们与结果索引一起检查,以找出哪一个更适合。在

使用

构建

性能

LibraryText SizeFunctionTime#ResultsImprovement Factor
ripgrepy500mbRipgrepy('text_one', '500mb').run().as_string.split('\n')127 ms ± 694 µs per loop125531.0x
PySubstringSearch500mbreader.search_sequential('text_one')2.48 ms ± 53.4 µs per loop1255351.2x
PySubstringSearch500mbreader.search_parallel('text_one')3.78 ms ± 350 µs per loop1255333.6x
ripgrepy500mbRipgrepy('text_two', '500mb').run().as_string.split('\n')127 ms ± 623 µs per loop7691.0x
PySubstringSearch500mbreader.search_sequential('text_two')156 µs ± 916 ns per loop769814.0x
PySubstringSearch500mbreader.search_parallel('text_two')251 µs ± 80.2 µs per loop769506.0x
ripgrepy6gbRipgrepy('text_one', '6gb').run().as_string.split('\n')1.38 s ± 3.82 ms2068841.0x
PySubstringSearch6gbreader.search_sequential('text_one')93.7 ms ± 2.16 ms per loop20688415.3x
PySubstringSearch6gbreader.search_parallel('text_one')34.3 ms ± 321 µs per loop20688440.5x
ripgrepy6gbRipgrepy('text_two', '6gb').run().as_string.split('\n')1.61 s ± 37.2 ms per loop69211.0x
PySubstringSearch6gbreader.search_sequential('text_two')2.22 ms ± 79.3 µs per loop6921725.2x
PySubstringSearch6gbreader.search_parallel('text_two')1.38 ms ± 26 µs per loop69211166.6x

先决条件

为了编译这个包,应该安装GCC&Python开发包。在

  • 软呢帽
sudo dnf install python3-devel gcc-c++
  • Ubuntu 18.04版
^{pr2}$

安装

pip3 install PySubstringSearch

使用

创建索引

importpysubstringsearch# creating a new index file# if a file with this name is already exists, it will be overwrittenwriter=pysubstringsearch.Writer(index_file_path='output.idx',)# adding entries to the new indexwriter.add_entry('some short string')writer.add_entry('another but now a longer string')writer.add_entry('more text to add')# making sure the data is dumped to the filewriter.finalize()

在索引中搜索子字符串

importpysubstringsearch# opening an index file for searchingreader=pysubstringsearch.Reader(index_file_path='output.idx',)# lookup for a substring sequentiallyreader.search_sequential('short')>>>['some short string']# lookup for a substring sequentiallyreader.search_sequential('string')>>>['some short string','another but now a longer string']# lookup for a substring concurrentlyreader.search_parallel('short')>>>['some short string']# lookup for a substring concurrentlyreader.search_parallel('string')>>>['some short string','another but now a longer string']

许可证

根据麻省理工学院的许可证分发。有关详细信息,请参见LICENSE。在

联系人

加本大卫-gal@intsights.com

项目链接:https://github.com/Intsights/PySubstringSearch

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从远程安卓应用程序打开/关闭嵌套   java在每个请求上获取memcache变量导致问题   如何在java中使用itext获取pdf文件的标题   java如何使用firebase令牌发送通知?   java不能在spring数据聚合中包含嵌套字段   用于调度作业的java Cron表达式   java当我使用TabActivity 安卓时,TabActivity类型已被弃用   加密Java Bouncy Castle加密使用AES加密   awt Java,将GUI与ActionListener类分离   如何在Java中创建一个根据输入返回枚举的方法?   java什么是Gxt 3.1.1实现对话框的方法。Gxt 3.0.0是否支持getHideButton()?   java如何解决构建错误?   java XWPF POI如何设置段落中的文本而不使用换行符