2012-09-12 31 views
5

मैं तेजी से अद्यतन विधियों के साथ एक उचित सी # अपरिवर्तनीय शब्दकोश की तलाश में हूं (जो मामूली परिवर्तनों के साथ शब्दकोश की आंशिक प्रतिलिपि बनाता है)। मैंने एक लाल-काले पेड़ को अद्यतन करने के लिए ज़िप्पर का उपयोग करके स्वयं को लागू किया है, लेकिन यह विशेष रूप से तेज़ नहीं है।क्या तेजी से 'बिना/बिना' विधियों के साथ सी # के लिए एक ओपन सोर्स अपरिवर्तनीय शब्दकोश है?

'अपरिवर्तनीय शब्दकोश' द्वारा मेरा मतलब केवल पढ़ने या कॉन्स्ट नहीं है। मुझे ऐसा कुछ चाहिए जो उचित रूप से तेज़ 'साथ' और 'बिना', या समकक्ष, विधियों को मूल रूप से संशोधित किए बिना मामूली संशोधन के साथ वापस कर देता है।

एक उदाहरण किसी अन्य भाषा से map in Scala

उत्तर

1

है वहाँ कुछ implementation of the immutable dictionary केवल पढ़ने के लिए द्विआधारी AVL पेड़ पर आधारित है।

/** 
* To modify, use the InsertIntoNew and RemoveFromNew methods 
* which return a new instance with minimal changes (about Log C), 
* so this is an efficient way to make changes without having 
* to copy the entire data structure. 
*/ 

कृपया InsertIntoNew() विधि पर एक नज़र डालें:

/** Return a new tree with the key-value pair inserted 
* If the key is already present, it replaces the value 
* This operation is O(Log N) where N is the number of keys 
*/ 
public ImmutableDictionary<K,V> InsertIntoNew(K key, V val) 
{ ... } 

RemoveFromNew() विधि:

/** Try to remove the key, and return the resulting Dict 
* if the key is not found, old_node is Empty, else old_node is the Dict 
* with matching Key 
*/ 
public ImmutableDictionary<K,V> RemoveFromNew(K key, out ImmutableDictionary<K,V> old_node) 
{ ... } 

इसके अलावा, वहाँ एक और दिया गया है: Immutable AVL Tree in C#। यह वही ओ (लॉग एन) लुकअप और सम्मिलन समय है।