查找两个数据集之间差异的有效方法 [英] Efficient way to find the difference between two data sets

查看:229
本文介绍了查找两个数据集之间差异的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据副本,其中 1 代表我的数据量, 2 代表我的问题。我必须将 COPY2 COPY1 进行比较,并找到 COPY2 COPY1 始终是一个超集和 COPY2 可以相等,也可以始终是子集)。
现在,我必须在COPY2中获取缺少的书卷和问题。
这样,从下图(场景)中我得到的结果为:-

I have two copies of data, here 1 represents my volumes and 2 represent my issues. I have to compare COPY2 with COPY1 and find all the elements which are missing in COPY2 (COPY1 will always be a superset and COPY2 can be equal or will always be a subset). Now, I have to get the missing volume and the issue in COPY2. Such that from the following figure(scenario) I get the result as : -

问题-


  1. 我应使用哪种数据结构存储以上值

  2. 我应该如何以最有效的方式在java中实现此方案以找出这两个副本之间的差异?


推荐答案

我建议使用 HashSet< VolumeIssue> 。每个 VolumeIsss 实例对应一个分类的问题,例如 1-C

I suggest a flat HashSet<VolumeIssue>. Each VolumeIssue instance corresponds to one categorized issue, such as 1-C.

在这种情况下,您所需要找到的就是通话

In that case all you will need to find the difference is a call

copy1.removeAll(copy2);

copy1 剩下的都是 copy1 中存在的问题,而 copy2 中缺少的问题。

What is left in copy1 are all the issues present in copy1 and missing from copy2.

请注意,您的 VolumeIssue 类必须正确实现 equals hashCode 才能发挥作用。

Note that your VolumeIssue class must properly implement equals and hashCode for this to work.

这篇关于查找两个数据集之间差异的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆