Datenstrukturen: Unterschied zwischen den Versionen
Aus Das Sopra Wiki
Keine Bearbeitungszusammenfassung |
|||
| Zeile 246: | Zeile 246: | ||
| class="close" | Verfügt über [[TryGetValue]]-Methode<br>schneller als SortedDictionary bei vorsortierten Daten | | class="close" | Verfügt über [[TryGetValue]]-Methode<br>schneller als SortedDictionary bei vorsortierten Daten | ||
|} [[Kategorie:Code-Beispiele]] | |} [[Kategorie:Code-Beispiele]] | ||
== Laufzeiten nach eigenen Tests in ms == | |||
Der Quellcode des für die Tests verwendeten Miniprogramms kann [[DatenstrukturenSpeedTest|hier]] eingesehen werden. | |||
=== ein-elementige Datenstrukturen === | |||
{| class="default" | |||
|- | |||
| class="blank" | <br> | |||
! colspan="6" | Laufzeiten | |||
| class="blank" | <br> | |||
|- | |||
| class="blank" | <br> | |||
! Add | |||
! Remove | |||
! ElementAt | |||
! Contains | |||
! Clear | |||
! Count | |||
! Element-Typ | |||
! [[ThreadSafety|Thread-safe]] | |||
! Bemerkungen | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/bb359438.aspx HashSet<T>] | |||
| O(1)<br>O(n) wenn Count + 1 > Capacity | |||
| O(1) | |||
| O(n) | |||
| O(1) | |||
| O(n) | |||
| O(1) | |||
| T | |||
| Nein | |||
| class="close" | keine Duplikate<br> | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/he2s3bh7.aspx LinkedList<T>] | |||
| O(1) | |||
| O(1) | |||
| O(n) | |||
| O(n) | |||
| O(n) | |||
| O(1) | |||
| T | |||
| Nein | |||
| class="close" | | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx List<T>] | |||
| O(1)<br>O(n) wenn Count + 1 > Capacity | |||
| O(n) | |||
| O(1) | |||
| O(n) | |||
| O(n) | |||
| O(1) | |||
| T | |||
| Nein | |||
| class="close" | | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/7977ey2c.aspx Queue<T>] | |||
| O(1)<br>O(n) wenn Count + 1 > Capacity | |||
| O(1)<br> | |||
| O(n)<br> | |||
| O(n)<br> | |||
| O(n)<br> | |||
| O(1)<br> | |||
| T<br> | |||
| Nein<br> | |||
| class="close" | | |||
Remove und Add sind Deqeue und Enqueue | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/3278tedw.aspx Stack<T>] | |||
| O(1)<br>O(n) wenn Count + 1 > Capacity <br> | |||
| O(1)<br> | |||
| O(n)<br> | |||
| O(n)<br> | |||
| O(n)<br> | |||
| O(1)<br> | |||
| T<br> | |||
| Nein<br> | |||
| class="close" | Remove und Add sind Pop und Push<br> | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/ms668265.aspx SynchronizedCollection<T>] | |||
| O(1)<br>O(n) wenn Count + 1 > Capacity<br> | |||
| O(n)<br> | |||
| O(1)<br> | |||
| O(n)<br> | |||
| O(n)<br> | |||
| O(1)<br> | |||
| T<br> | |||
| Ja<br> | |||
| class="close" | | |||
benutzt intern List<T>, hat aber zusätzliche Mechanismen<br>um [[ThreadSafety|Thread-safety]] zu garantieren | |||
|} | |||
=== zwei-elementige Datenstrukturen === | |||
{| class="default" | |||
|- | |||
| class="blank" | | |||
! colspan="5" | Laufzeiten | |||
| class="blank" | | |||
|- | |||
| class="blank" | | |||
! Add | |||
! Remove | |||
! ContainsKey | |||
! Clear | |||
! Count | |||
! Element-Typ | |||
! [[ThreadSafety|Thread-safe]] | |||
! Bemerkungen | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/xfhwa508.aspx Dictionary<TKey, TValue>] | |||
| O(1)<br>O(n) wenn Count + 1 > Capacity | |||
| O(1) | |||
| O(1) | |||
| O(n) | |||
| O(1) | |||
| [http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx KeyValuePair<TKey,TValue>] | |||
| Nein | |||
| class="close" | Verfügt über [[TryGetValue]]-Methode | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/f7fta44c.aspx SortedDictionary<TKey, TValue>] | |||
| O(log n) | |||
| O(log n) | |||
| O(log n) | |||
| O(n) | |||
| O(1) | |||
| [http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx KeyValuePair<TKey,TValue>] | |||
| Nein | |||
| class="close" | Verfügt über [[TryGetValue]]-Methode<br>schneller als SortedList bei unsortierten Daten | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx Hashtable] | |||
| O(1)<br>O(n) wenn Count + 1 > Capacity | |||
| O(1) | |||
| O(1) | |||
| O(n) | |||
| O(1) | |||
| [http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx KeyValuePair<object,object>]<br>oder<br>[http://msdn.microsoft.com/en-us/library/system.collections.dictionaryentry.aspx DictionaryEntry] | |||
| Read-Only mit einem schreibenden Thread | |||
| class="close" | Die initiale Capacity der Hashtable kann im [[Konstruktor]] angegeben werden: [http://msdn.microsoft.com/en-us/library/k3x9ky40.aspx <tt>Hashtable(Int32)</tt>] | |||
|- | |||
! [http://msdn.microsoft.com/en-us/library/ms132319.aspx SortedList<TKey, TValue>] | |||
| O(n) | |||
| O(n) | |||
| O(log n) | |||
| O(n) | |||
| O(1) | |||
| [http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx KeyValuePair<TKey,TValue>] | |||
| Nein | |||
| class="close" | Verfügt über [[TryGetValue]]-Methode<br>schneller als SortedDictionary bei vorsortierten Daten | |||
|} [[Kategorie:Code-Beispiele]] | |||
== Referenzen == | == Referenzen == | ||
