当前位置:网站首页>Illuminate\support\collection de duplication unique list de duplication
Illuminate\support\collection de duplication unique list de duplication
2022-06-23 06:33:00 【fareast_ mzh】
list , Array Specify rule de duplication
curMsg->getFundId() == $prevMsg->getFundId()
Repeat post-processing
// Which element to delete ?
if ($curMsg->created_at > $prevMsg->created_at) {
// The element to be deleted moves to the back
self::swap($list, $i, $dupIdx);
}
The replaceable parts are as above
There is no order , be it so
private static function swap(Collection $c, int $i, int $j) {
$tmp = $c->get($i);
$c->offsetSet($i, $c->get($j));
$c->offsetSet($j, $tmp);
}
/**
* Remove fund_id repeat , identical fund_id Get the latest records , Delete old records
* @param Collection $list
*/
private static function msgListUniq(Collection $list) {
$n = $list->count();
$countDel = 0;
for ($i = 1; $i < $n; $i++) {
$dupIdx = -1;
/** @var $curMsg PayMessage */
$curMsg = $list->get($i);
if (empty($curMsg)) {
break;
}
$prevMsg = null;
for ($j = 0; $j < $i; $j++) {
/** @var $prevMsg PayMessage */
$prevMsg = $list->get($j);
if ($curMsg->getFundId() == $prevMsg->getFundId()) {
$dupIdx = $j;
break;
}
}
// There is repetition fund_id
if (0 <= $dupIdx) {
if ($curMsg->created_at > $prevMsg->created_at) {
self::swap($list, $i, $dupIdx);
}
for ($k = $i+1; $k < $n-$countDel; $k++) {
$list->offsetSet($k-1, $list->get($k));
}
// $list->offsetUnset($k-1);
$countDel += 1;
}
}
// Do not cycle unset
while ($countDel > 0) {
$list->offsetUnset($n - $countDel);
$countDel -= 1;
}
}边栏推荐
- 熟练利用切片操作
- golang正则regexp包使用-04-使用正则替换(ReplaceAll(),ReplaceAllLiteral(),ReplaceAllFunc())
- Redis sentry
- Day_08 传智健康项目-移动端开发-体检预约
- Softing dataFEED OPC Suite将西门子PLC数据存储到Oracle数据库中
- Radar canvas
- 索引——MySQL
- Word pattern for leetcode topic analysis
- Eight data analysis models: ogsm model
- Detailed explanation of redis persistence, master-slave and sentry architecture
猜你喜欢

Microsoft interview question: creases in origami printing

图解 Google V8 # 17:消息队列:V8是怎么实现回调函数的?

How to query fields separated by commas in MySQL as query criteria - find_ in_ Set() function

十一、纺织面料下架功能的实现

mysql如何将日期转为数字

Day_13 传智健康项目-第13章

mysql以逗号分隔的字段作为查询条件怎么查——find_in_set()函数

Day_06 传智健康项目-移动端开发-体检预约
百度URL参数之LINK?URL参数加密解密研究(代码实例)

Day_ 03 smart communication health project - appointment management - inspection team management
随机推荐
Leetcode topic resolution valid Sudoku
Day_04 传智健康项目-预约管理-套餐管理
Gplearn appears assignment destination is read only
How to add libraries for Arduino ide installation
Runc symbolic link mount and container escape vulnerability alert (cve-2021-30465)
Day_ 03 smart communication health project - appointment management - inspection team management
机器学习3-岭回归,Lasso,变量选择技术
原址 交换
如何为 Arduino IDE 安装添加库
[vivado] xilinxcedstore introduction
How to query fields separated by commas in MySQL as query criteria - find_ in_ Set() function
golang正则regexp包使用-04-使用正则替换(ReplaceAll(),ReplaceAllLiteral(),ReplaceAllFunc())
C语言 踩坑:文档编码错误,导致base64中文编码错误
vs+qt项目转qt creator
Wechat tried out the 1065 working system, and was forced to leave work at 18:00; It is said that Apple will no longer develop off screen fingerprint identification; Amd chief independent GPU architect
[focus on growth and build a dream for the future] - TDP year-end event, three chapters go to the Spring Festival!
mongodb 4. X binding multiple IP startup errors
What is a PDCA cycle? How to integrate PDCA cycle and OKR
bootstrap如何清除浮动的样式
(1)基础学习——vim编辑器常用快捷操作命令