承接 wrossmann/pc-iters 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wrossmann/pc-iters

Composer 安装命令:

composer require wrossmann/pc-iters

包简介

Memory-efficient permutation and combination generators.

README 文档

README

Memory-efficient PHP permutation and combination generators.

Both classes are generators that should incur no additional memory requirements beyond roughly one extra copy of the input set.

This library was written in response to a question regarding permuatation/combination generation in ##php on FreeNode, and published after a brief survey of alternatives showed only solutions that recursively generated incresasingly larger sets of results in-memory.

I would also like to include the word 'combinatorics' in this document so that search engines find it. :)

Caveats

  • The input array to the interators must be numerically-indexed with no gaps in the indexes. [see: array_values()]
  • Neither generator makes allowances for gaps or repetitions, all elements are assumed to be unique.
  • If you store the results of these generators you're still going to have memory issues.
  • This is not an ideal method to calculate the number of possible permutations and combinations. [see: Math]
  • This is not an ideal method to generate something like "all possible non-sequential, non-repeating IDs" [see: Linear-Feedback Shift Registers or just use a UUID]

Classes

  • CombinationIterator: Generates all possible combinations of N elements from the input set.
    • Uses a recursive, Gray Code-ish method.
    • Stack depth should never be deeper than the number of element in the output set.
  • PermutationIterator: Generates all possible arrangements of the input set.
    • Uses the non-recursive form of Heap's Algorithm.
    • Operates in-place on a copy of the input set.

Installation

composer require wrossmann/pc-iters

Usage

CombinationIterator

Function signature and docblock:

/**
 * Given a set of items, generate all unique combinations of the
 * specified number of items using a Gray Code-ish method.
 * 
 * @param	array	$set	The set of items
 * @param	int		$count	The number of items in the output set
 * @param	int		$begin	Offset in the set to start.
 * @param	int		$end	Offset in the set to end. [non-inclusive]
 */
public static function iterate($set, $count, $begin=NULL, $end=NULL)

Example:

use wrossmann\PCIters\CombinationIterator;

foreach( CombinationIterator::iterate([1,2,3,4,5], 3) as $comb ) {
	printf("%s\n", json_encode($comb));
}

Output:

[1,2,3]
[1,2,4]
[1,2,5]
[1,3,4]
[1,3,5]
[1,4,5]
[2,3,4]
[2,3,5]
[2,4,5]
[3,4,5]

PermutationIterator

Function signature and docblock:

/**
 * Given a set of items generate all possible unique arrangements
 * of items. Uses Heap's Algorithm.
 * 
 * @param	array	$set	The set of items on which to operate.
 */
public static function iterate($set)

Example:

use wrossmann\PCIters\PermutationIterator;

foreach( PermutationIterator::iterate([1,2,3]) as $comb ) {
	printf("%s\n", json_encode($comb));
}

Output:

[1,2,3]
[2,1,3]
[3,1,2]
[1,3,2]
[2,3,1]
[3,2,1]

wrossmann/pc-iters 适用场景与选型建议

wrossmann/pc-iters 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 wrossmann/pc-iters 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wrossmann/pc-iters 我们能提供哪些服务?
定制开发 / 二次开发

基于 wrossmann/pc-iters 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-20