2012-10-11 9 views
5

हाल ही में मैं ConcurrentSkipListMap में चलाता हूं, जो skip listConcurrentNavigableMap के कार्यान्वयन है। अब मुझे आश्चर्य है, इसे skip list के रूप में क्यों लागू किया गया है।ConcurrentNavigableMap को स्किप सूची के रूप में क्यों लागू किया गया है?

skip listसमवर्ती नौवहन मानचित्रों का एक "मानक" कार्यान्वयन करता है? क्या skip list इसके लिए विशेष रूप से अच्छा बनाता है?

उत्तर

5

ConcurrentSkipListMap स्रोत कोड ने कारण बताया है।

वहाँ सामान्य सरणी-आधारित

  1. सरणी आधारित कार्यान्वयन के बजाय इस दृष्टिकोण को रखने के लिए दो कारण हैं और अधिक जटिलता और भूमि के ऊपर का सामना करने लगते हैं
  2. हम भारी-चल सूचकांक के लिए सस्ता एल्गोरिदम का उपयोग कर सकते हैं सूचीबद्ध करता आधार सूचियों

यहाँ के लिए इस्तेमाल किया जा सकता से जावाडोक

है
/* 
* This class implements a tree-like two-dimensionally linked skip 
* list in which the index levels are represented in separate 
* nodes from the base nodes holding data. **There are two reasons 
* for taking this approach instead of the usual array-based** 
* structure: 1) Array based implementations seem to encounter 
* more complexity and overhead 2) We can use cheaper algorithms 
* for the heavily-traversed index lists than can be used for the 
* base lists. Here's a picture of some of the basics for a 
* possible list with 2 levels of index: 
* 
* Head nodes   Index nodes 
* +-+ right  +-+      +-+ 
* |2|---------------->| |--------------------->| |->null 
* +-+     +-+      +-+ 
* | down    |      | 
* v     v      v 
* +-+   +-+ +-+  +-+   +-+  +-+ 
* |1|----------->| |->| |------>| |----------->| |------>| |->null 
* +-+   +-+ +-+  +-+   +-+  +-+ 
* v    | |   |    |   | 
* Nodes next  v v   v    v   v 
* +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ 
* | |->|A|->|B|->|C|->|D|->|E|->|F|->|G|->|H|->|I|->|J|->|K|->null 
* +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ 
संबंधित मुद्दे

 संबंधित मुद्दे