vixen clothing Xiangjie. NET4 the SortedSet class of new features

Technology IT168 Microsoft. NET 3.5 added a HashSet class in. NET 4 added a SortedSet class, this paper describes their characteristics, and compare their similarities and differences.
. NET Collection library of HashSet, SortedSet these two generic classes, are implemented System.Collections.Generic.ISet interface; but the early Java 1.2 (or earlier) version before, already provided to achieve these two species of the same name as the data structure classes, and there are even more stringent TreeSet (inside the store items, even the types must be consistent. then not generic).
Set the “set” means, and its mathematical definition, is stored inside the element is no specific order, and does not allow duplication. We look at the following HashSet, SortedSet example:
ISet set = new HashSet () (5, 9, 2, 1, 2, 2, 3, 7, 4, 9, 9);
foreach (int element in set)
Response.Write (string.Format ((0), element));
Implementation of the results:
Figure 1 automatically remove duplicate elements
The same code, the HashSet into SortedSet, as follows:
ISet set = new SortedSet () (5, 9, 2, 1, 2, 2, 3, 7, 4, 9, 9);
foreach (int element in set)
Response.Write (string.Format ((0), element));
Implementation of the results:
Figure 2 repeat elements are automatically removed and will automatically do an internal sort
We see HashSet, SortedSet these two classes, does not allow repetition, but the former is based on the order of the element of storage, which will be re-added elements to rank, and be able to insert, delete and search elements, still to maintain the order of the data. So if you have the patience to read here, to learn a trick: If the normal programming to filter duplicate entries, then it can use both Set class, because the collection is not allowed to repeat elements. Not appear in the SortedSet. NET 3.5 era, we must use HashSet to remove duplicate entries, and then sort; while now. NET 4, we can use to remove duplication and achieve step SortedSet sort.
Of course, if you have different requirements (Do not consider the performance difference), do not want the default automatic sorting, or do not need to remove duplicate elements, can use the Sort method List class. In addition, you can put HashSet as key / value pair of Dictionary class, only key no value to use, because the Dictionary (generic HashTable) its identity, and HastSet similar element is also no particular order, and not allowed to repeat (key must be unique).
————————————————– ———————-
The following were listed. NET platform, HashSet, SortedSet class of their own some of these features:
HastSet features:
It Contains Method (HashSet objects to determine whether it contains a specified element) the implementation of very fast, because based “hash” of the find (hash-based lookup).
(Another Dictionary class retrieval speed is very fast, its “algorithm” Time Complexity close to O (1), this is because the Dictionary class is a hash table to achieve)
It's Add method (to be specified element to the HashSet object), if Count is less than the capacity of the internal array, this method of computation complexity is O (1). If you must adjust the size of the HashSet object, then the computational complexity of this method will be O (n).
It can not store duplicate elements and when elements overlap when inserted will automatically be ignored.
Not from a specific location, visit one of these elements.
SortedSet features:
It Contains Method (HashSet object to determine whether it contains a specified element) the implementation of very fast, because as based on “hash” lookup (hash-based lookup).
It's Add method (to be specified element to the HashSet object), if the Count is smaller than the capacity of the internal array, this method of computation complexity is O (1). If you must adjust the size of the HashSet object, then the computational complexity of this method will be O (n). (Data structure, the “red-black tree (Red-Black tree”) [3], [8]
It's Add method, if added to existing entries will be ignored, and returns False.
It can not store duplicate elements, and when inserted elements are repeated, will automatically be ignored.
Not from a specific location, visit one of these elements.
vixen clothing, express clothing, champion clothing,

Top

Let us talk about
Leave a reply
Name and Mail are required

©   2010, VixenKitty clothing storesmts Gossip Rag by mts WebDesign|| Top