Appendix B. Migration Cheat Sheet

STL to Generics

STL

.NET Generics class

Comments

vector

List<T>

 

deque

LinkedList<T>

deque allows addition and deletion at both ends in constant time.

list

LinkedList<T>

list also allows addition and deletion at both ends in constant time. Thus, that is what is best mapped to these two containers.

stack

Stack<T>

 

Queue

Queue<T>

 

priority_queue

Not available

You can use PriorityQueue<TKey,TValue> described in Chapter 3, Dictionaries.

set

HashSet<T>, SortedSet<T>

Use SortedSet<T> if you always want the set to be sorted.

multiset

Not available. You can use OrderedBag from PowerCollections.

Can be modeled as Dictionary<T,int> or SortedDictionary<T,int> if you want entries to be sorted.

map

Dictionary<TKey,TValue>

SortedDictionary<TKey,TValue>

Use SortedDictionary<TKey,TValue> if you always want entries to be sorted.

multimap

Dictionary<TKey,List<TValue>>

You can also use OrderedBag in PowerCollection

bitset

List<bool>

 

JCF to Generics

Java Collection Framework (JCF)

.NET Generics class

Comments

LinkedList

LinkedList<T>

 

ArrayList

Not available

Use ArrayList<T> in C5 Collections.

HashSet

HashSet<T>

 

TreeSet

Not available

Use TreeSet<T> in C5 Collections.

HashMap

Not available

Use HashDictionary<TKey,TValue> in C5 Collections.

TreeMap

Not available

Use TreeDictionary<TKey,TValue> in C5 Collections.

LinkedHashMap

HashDictionary<TKey,TValue>

 

Vector

List<T>

 

HashTable

Dictionary<TKey,TValue>

 

SortedSet

SortedSet<T>

 

SortedMap

SortedDictionary<TKey,TValue>

 

PriorityQueue

Not available

Use PriorityQueue<TKey,TValue> described in Chapter 3, Dictionaries.

Deque

LinkedList<T>

 

Power Collections to Generics

Power Collection Class

.NET Generics class

Comments

Pair<TKey,TValue>

KeyValuePair<TKey,TValue>

 

Set<T>

Set<T>

 

MultiDictionary<TKey,TValue>

Not Available

You can use the MultiDictionary we have created in Chapter 3, Dictionaries.

OrderedSet<T>

SortedSet<T>

 

Bag<T>

List<T>

 

OrderedBag<T>

Not available

This is basically a sorted list where duplicates are allowed.

Deque<T>

List<T>

You can add/remove from both ends of a List<T>.

Triple<T1,T2,T3>

Tuple<T1,T2,T3>

This is a special case of a Tuple.

BigList<T>

List<T>

 

.NET 1.1 to Generics .NET 4.0

Non-generic collection

Generic collection (available from .Net 2.0)

Thread-safe generic collection

ArrayList

List<T>

ConcurrentBag<T>

Stack

Stack<T>

ConcurrentStack<T>

Queue

Queue<T>

ConcurrentQueue<T>

HashTable

Dictionary<TKey,TValue>

ConcurrentDictionary<T>

SortedList

SortedList<TKey,TValue>

ConcurrentDictionary<TKey,TValue>

BitArray

List<bool>

ConcurrentBag<bool>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.97.200