markbaker/tries

PHP 类,用于 Trie 数据结构

2.0.0 2018-11-14 23:17 UTC

This package is auto-updated.

Last update: 2024-09-05 01:36:11 UTC


README

A PHP implementation of the Trie, RadixTrie and SuffixTrie data structures

主分支: Build Status

开发分支: Build Status

要求

  • PHP 版本 7.2 或更高

安装

我们推荐使用 Composer 来安装此包。

通过 composer

在项目根目录下执行

composer require markbaker/tries:dev-master

现在您应该在项目目录中拥有 composer.jsoncomposer.lock 文件,以及 vendor 目录。

然后您可以从代码中要求 Composer 自动加载器

require 'vendor/autoload.php';

或者,如果您已经有一个 composer.json 文件,则在该文件中要求此包,并更新 composer。

"require": {
    "markbaker/tries": "dev-master"
}

composer update

从 Phar

虽然我们强烈推荐使用 Composer,但我们还提供了一个 Phar 存档 构建器,该构建器将创建一个包含所有库代码的 Phar 文件。

phar 构建器脚本位于存储库根目录中,可以使用以下命令运行:

php buildPhar.php

要使用该存档,只需从脚本中要求它

require 'Tries.phar';

标准自动加载器

如果您想在不使用 composer 的自动加载器的情况下运行代码,并且不想构建 Phar,则可以在您的代码中从存储库中要求 bootstrap.php 文件,这将启用库的自动加载器。

require 'bootstrap.php';

想要贡献吗?

将此库分支出来!

许可协议

Tries 使用 MIT 许可协议 许可

示例

/examples 文件夹中有两个示例,用于演示其用法

  • playerSearch.php

  • playerSearchRadixTrie.php

  • playerSearchSuffixTrie.php

    允许根据姓氏搜索 Wigan Warriors 橄榄球联盟球员,并显示匹配输入搜索条件的记录

    用法

     php playerSearch <name> <limit>
    

     php playerSearchRadixTrie <name> <limit>
    

     php playerSearchSuffixTrie <name> <limit>
    

    其中

     name     the first few characters of the surname you want to
              search for (or characters from anywhere in the name
              if using the Suffix Trie search)
     limit    optional (default 8) limits the number of results
              returned
    
  • wordSearch.php

  • wordSearchRadixTrie.php

    在英语词典中搜索单词,显示匹配输入搜索条件的单词

    用法

     php wordSearch <searchterm> <limit>
    

     php wordSearchRadixTrie <searchterm> <limit>
    

    其中

     searchterm   can be a prefix*
                      e.g. "aba*" will return words beginning with "aba"
                  a *suffix
                      e.g. "*ose" will return words ending in "ose"
                  or a split*search criteria
                      e.g. "t*ly" will return words beginning with "t" 
                           and ending in "ly"
     limit        optional (default 8) limits the number of results
                  returned
    

    注意,包含 160k 个单词的词典将花费一些时间加载,具体取决于您的系统