最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java編程中的HashSet和BitSet詳解

 更新時間:2017年03月06日 11:22:41   投稿:lqh  
這篇文章主要介紹了Java編程中的HashSet和BitSet詳解的相關(guān)資料,需要的朋友可以參考下

Java編程中的HashSet和BitSet詳解

我在Apache的開發(fā)郵件列表中發(fā)現(xiàn)一件很有趣的事,Apache Commons包的ArrayUtils類的removeElements方法,原先使用的HashSet現(xiàn)在換成了BitSet。

HashSet<Integer> toRemove = new HashSet<Integer>(); 
for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) { 
  Character v = e.getKey(); 
  int found = 0; 
  for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) { 
    found = indexOf(array, v.charValue(), found); 
    if (found < 0) { 
      break; 
    } 
    toRemove.add(found++); 
  } 
} 
 
 
return (char[]) removeAll((Object)array, extractIndices(toRemove)); 

新代碼如下:

BitSet toRemove = new BitSet(); 
for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) { 
  Character v = e.getKey(); 
  int found = 0; 
  for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) { 
    found = indexOf(array, v.charValue(), found); 
    if (found < 0) { 
      break; 
    } 
    toRemove.set(found++); 
  } 
} 
return (char[]) removeAll(array, toRemove); 

為什么會使用BitSet代替HashSet呢?

據(jù)Apache Commons作者指出,這樣代碼執(zhí)行時可以占用更少的內(nèi)存,速度也更快。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

玛曲县| 平湖市| 阿巴嘎旗| 德令哈市| 静乐县| 神木县| 鸡东县| 方正县| 抚州市| 深圳市| 额尔古纳市| 巫溪县| 方山县| 长武县| 民丰县| 清远市| 普兰县| 翁牛特旗| 绿春县| 巴彦县| 浙江省| 南木林县| 济南市| 元朗区| 江都市| 重庆市| 朝阳市| 宿州市| 七台河市| 嫩江县| 九龙坡区| 泾川县| 龙陵县| 玛纳斯县| 都江堰市| 通州区| 南澳县| 晋州市| 瓮安县| 林州市| 竹溪县|