2012-09-12 5 views
5

私は適切なC#不変の辞書を探しています。これは、(わずかな変更で辞書の部分的なコピーを作成する)高速更新メソッドを備えています。赤い黒色のツリーを更新するためにジッパーを使って自分自身を実装しましたが、特に高速ではありません。C#用のオープンソース不変ディクショナリはありますか?高速 'With/Without'メソッドはありますか?

「不変の辞書」とは、私は読取り専用またはconstを意味するものではありません。私は合理的に速い 'With'と 'Without'、またはこれと同等の方法で元のものを変更せずに少し修正したものを返すものが欲しい。別の言語から

の例では、読み取り専用のバイナリAVLツリーに基づいていくつかのimplementation of the immutable dictionaryありmap in Scala

答えて

1

です。

/** 
* 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()方法:Immutable AVL Tree in C#

/** 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) 
{ ... } 

をまた、別の実装があります。これは同じO(log N)ルックアップと挿入時間を持ちます。

関連する問題