最新国产好看的视频,伊人天堂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)文章

最新評論

台湾省| 北宁市| 宜章县| 开平市| 凤庆县| 土默特右旗| 阜城县| 宣城市| 会昌县| 阳朔县| 德阳市| 永善县| 洛隆县| 伊通| 浏阳市| 南木林县| 民勤县| 稻城县| 米林县| 锦屏县| 陆川县| 宜丰县| 瓦房店市| 锡林郭勒盟| 洛阳市| 邯郸县| 青海省| 平原县| 和龙市| 冷水江市| 瑞金市| 郑州市| 石河子市| 咸阳市| 德令哈市| 河池市| 加查县| 隆化县| 南丰县| 益阳市| 贵德县|