日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java-数据结构-续

發(fā)布時間:2025/1/21 编程问答 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java-数据结构-续 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
接口: Collection<E> 子接口: BlockingDeque<E>, BlockingQueue<E>, Deque<E>, List<E>, NavigableSet<E>, Queue<E>, Set<E>, SortedSet<E> 實(shí)現(xiàn)類: ArrayBlockingQueue, ArrayDeque, ArrayList, ConcurrentLinkedQueue, ConcurrentSkipListSet, CopyOnWriteArrayList, CopyOnWriteArraySet, DelayQueue, EnumSet, HashSet, LinkedBlockingDeque, LinkedBlockingQueue, LinkedHashSet, LinkedList, PriorityBlockingQueue, PriorityQueue, Stack, SynchronousQueue, TreeSet, Vector List<E> 實(shí)現(xiàn)類: ArrayList, CopyOnWriteArrayList, LinkedList,Stack, Vector Queue<E> 子接口: BlockingDeque<E>, BlockingQueue<E>, Deque<E> 實(shí)現(xiàn)類: ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingDeque, LinkedBlockingQueue, LinkedList, PriorityBlockingQueue, PriorityQueue, SynchronousQueue Set<E> 子接口: NavigableSet<E>, SortedSet<E> 實(shí)現(xiàn)類: ConcurrentSkipListSet, CopyOnWriteArraySet, EnumSet, HashSet, LinkedHashSet, TreeSet Map<K,V> 子接口: ConcurrentMap<K,V>, ConcurrentNavigableMap<K,V>, SortedMap<K,V> 實(shí)現(xiàn)類: ConcurrentHashMap, ConcurrentSkipListMap, EnumMap, HashMap, Hashtable, IdentityHashMap, LinkedHashMap, TreeMap, WeakHashMap 并發(fā)與線程安全等 通常含有Concurrent,CopyOnWrite,Blocking的是線程安全的,但是這些線程安全通常是有條件的,所以在使用前一定要仔細(xì)閱讀文檔。具體實(shí)現(xiàn): List<E>系列: ArrayList<E>,如其名,但是其容量增長計劃是newCapacity = (oldCapacity * 3)/2 + 1,和C++通常的Vector是翻倍的策略不同。 CopyOnWriteArrayList<E>,里面有一個ReentrantLock,每當(dāng)add時,都鎖住,把所有的元素都復(fù)制到一個新的數(shù)組上。 只保證歷遍操作是線程安全的,get操作并不保證,也就是說如果先得到size,再調(diào)用get(size-1),有可能會失效 那么CopyOnWriteArrayList是如何實(shí)現(xiàn)線程安全的迭代操作? 在迭代器中保存原數(shù)組。 LinkedList<E>,標(biāo)準(zhǔn)雙向鏈表 Vector<E>,過時,多數(shù)方法上加上了synchronized Stack<E>,繼承自Vector,過時,優(yōu)先應(yīng)使用 Deque<Integer> stack = new ArrayDeque<Integer>();Queue<E>系列: LinkedList<E>,見List<E>系列 ArrayDeque<E>,內(nèi)部用一個數(shù)組保存元素,有int類型head和tail的。 PriorityQueue<E>,內(nèi)部用一個數(shù)組來保存元素,但數(shù)組是以堆的形式來組織的,因此是有序的。 PriorityBlockingQueue<E>,包裝了一個PriorityQueue<E>,一個ReentrantLock,一個Condition,TODO ArrayBlockingQueue<E>,TODO ConcurrentLinkedQueue<E>,TODO DelayQueue<E>,TODO LinkedBlockingDeque<E>,TODO LinkedBlockingQueue<E>,TODO SynchronousQueue<E>,TODODeque<E>(雙端隊(duì)列)系列: ArrayDeque<E>,見Queue系列 LinkedList<E>,見List系列 LinkedBlockingDeque<E>,TODOSet系列: HashSet,包裝了一個HashMap:public HashSet() {map = new HashMap<E,Object>();} TreeSet,包裝了一個TreeMap,參考HashSet LinkedHashSet,包裝了LinkedHashMap,參考HashSet EnumSet,TODO CopyOnWriteArraySet,簡單包裝了CopyOnWriteArrayList,注意這個Set的get的時間復(fù)雜度。 ConcurrentSkipListSet,包裝了一個ConcurrentSkipListMap,參考HashSet。Map系列: HashMap<K,V>,標(biāo)準(zhǔn)鏈地址法實(shí)現(xiàn) TreeMap<K,V>,紅黑二叉樹 LinkedHashMap<K,V>,在Entry中增加before和after指針把HashMap中的元素串聯(lián)起來,這樣在迭代時,就可以按插入順序歷遍。 EnumMap,TODO ConcurrentHashMap,參考之前的文章 ConcurrentSkipListMap,TODO,log(n)的時間復(fù)雜度,有點(diǎn)像多級鏈表保存的,貌似有點(diǎn)像redis中的SortedSet的實(shí)現(xiàn) Hashtable,過時 IdentityHashMap,正常的HashMap中比較是用equals方法,這個用的是“==”比較符 WeakHashMap<K,V>,弱引用的HashMap,正常的HashMap是強(qiáng)引用,即里面的value不會被GC回收,在WeakHashMap<K,V>中,V中最好是WeakReference類型的,用像這樣的代碼:m.put(key, new WeakReference(value))。其它的一些實(shí)用的第三方的數(shù)據(jù)結(jié)構(gòu): LRUCache,LongHashMap,Java7中的LinkedTransferQueue, Apache的包,里面有很多實(shí)用的類: http://commons.apache.org/collections/ Google的包,里面有很多并發(fā)的牛B類: AtomicLongMap,等等 大對象的數(shù)據(jù)結(jié)構(gòu):https://github.com/HugeCollections/Collections 注意事項(xiàng): 并發(fā)容器多數(shù)不能使用null值

總結(jié)

以上是生活随笔為你收集整理的java-数据结构-续的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。