https://github.com/pangongzi/algorithm
A PHP library for implementing various algorithms
https://github.com/pangongzi/algorithm
algorithm php snowflake
Last synced: 24 days ago
JSON representation
A PHP library for implementing various algorithms
- Host: GitHub
- URL: https://github.com/pangongzi/algorithm
- Owner: pangongzi
- License: other
- Created: 2025-02-18T01:23:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-18T02:31:43.000Z (over 1 year ago)
- Last Synced: 2025-12-14T16:50:20.390Z (6 months ago)
- Topics: algorithm, php, snowflake
- Language: PHP
- Homepage: https://github.com/pangongzi/algorithm
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Algorithm | php算法库
### 项目描述
`pangongzi/algorithm` 是一个 PHP 库,提供了多种算法的实现,包括雪花算法等。
目前仅有雪花算法
### 安装
使用 Composer 安装:
```bash
# 安装
composer require pangongzi/algorithm
# 更新
composer update pangongzi/algorithm
# 删除
composer remove pangongzi/algorithm
```
### 使用方法
雪花算法
初始化 首先,需要引入自动加载文件并实例化 SnowflakeService 类:
```php
generate();
echo "生成的唯一ID: " . $id . PHP_EOL;
// int(546849135915962368)
```
### 编码为 Base62 字符串
使用 encode 方法将生成的ID编码为 Base62 字符串:
```php