定制 ryvova/linkedlist 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ryvova/linkedlist

Composer 安装命令:

composer require ryvova/linkedlist

包简介

SortedLinkedListPackage

README 文档

README

Do you really use linked lists? I met them at the grammar school in the 1st year of programming lessons in 1986 and I haven't needed them since. Even then, I thought it was a terribly stupid thing, because:

  • It is terribly slow to access the value in the middle of the list (it has to be traversed step-by-step) unlike, for example, an array.
  • In addition, it is also memory-intensive due to the need to store a link to the next (eventually previous) element.
  • Low instruction level parallelism - while traversing a linkded list, the CPU doesn't have a lot of work to do because it cannot start processing the next node until it has finished loading the current node.

I used a two-way linked list.

  • The advantage are:
    • It makes it easier and faster to delete the last element of the list (I don't have to loop through the whole list).
    • if I know, for example, that the data in the sorted list has a normal distribution, I can adjust the method for adding/deleting so that when the min. value 1, max 10000 and I will want to insert/delete 7000, so I will traverse from back to front.
  • The disadvantage is: A higher memory requirement (each node must contain a link not only to the next one, but also to the previous one).

To decide whether to choose a one-way/two-way linked list and whether to sort it in ascending/descending order, it would be necessary to know more about:

  • What it is to be used for,
  • How the data that will be filled into it will look like, if, for example, the data will go in sorted order, than we can modify add to add to the beginning/end,
  • How important is time or memory consumption etc.

When merging two lists, I use the fact that they are both sorted. Of course, I could call the add() method on each element of the list being added, which would go through the first list from the beginning and put it in the right place. Since they are both sorted, I just need to remember the pointer to where I added the element in the list I'm adding to and continue from there.

The assignment does not specify how the lists with string values should be sorted. I use sort by system settings. Since int values are compared using </=/> and string values using compare, I modified function compare so that it can also compare int values so that I don't have to find out what type the values are every time. Perhaps it would be more efficient to simply retype int to string and then use the compare.

It would be worth considering that the Node contains not only the value, but also the number of times the value occurs. It would simplify adding and removing nodes - it would only be enough to increment/decrement the number and pointers would not have to be solved (unless all Nodes with a given value were deleted).

In practice, where the library would be part of a larger project, it would be advisable to consider whether the collator should be made as a singleton, since its settings would always be the same according to the system.

I use the __toString() methods to clearly display information about lists for testing purposes (var_dump objects with pointers is very confusing). I want to be sure that the code is functional, so I wrote unit tests for it.

It is worth considering whether to make the list immutable - after creation, set a flag to it and during further processing check whether there has been a change.

Since you say you use your own rules for PHPStan, I also ran the code through PHPStan level 9.

I never use recursion due to extreme memory requirements. I wanted to be sure that the code works, so I also wrote PHPUnit tests for the methods. It should be a libraty, so I registered the code as a package on packagist.org as ryvova/linkedlist

ryvova/linkedlist 适用场景与选型建议

ryvova/linkedlist 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 ryvova/linkedlist 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-09-11