算法一步骤(SortSortIntersectionAlgorithm):
1、sort集合一
2、sort集合二
3、同时遍历已排序的两集合,进行计算
算法二步骤(SortIntersectionAlgorithm):
1、sort集合一
2、遍历集合二到已排序的集合一种进行查找, 并计算
算法的基准测试一(集合一比较小, 集合二比较大):
包含:
1、JDK List retainAll
2、SortSortIntersectionAlgorithm List intersection
3、SortSortIntersectionAlgorithm Array intersection
4、SortIntersectionAlgorithm List intersection
5、SortIntersectionAlgorithm Array intersection
算法的基准测试二(集合一与集合二一样大):
包含:
1、SortSortIntersectionAlgorithm Array intersection
2、SortIntersectionAlgorithm Array intersection
结果:
1、两集合都排序后再比较, 效率比较高一些
2、但一集合很小、另一集合很大时候, 使用小集合排序后、大集合到小集合中进行二分查找(找到后移除小集合中该元素并缩小集合大小,节约下次查找成本对性能提升不大),比较划算
3、Array计算效率明显高于List(快几倍呢)