To select the correct set, we must first understand some data structure knowledge. The so-called data structure is a set of data elements with one or more specific relationships between each other. Let's take a look at the classification of the set.

Set category

In, we can see that the set is generally divided into linear sets and non-linear sets. A linear set refers to a Data Structure Type in which an element has a unique precursor and a rear drive. A non-linear set refers to a data structure type that has multiple front-ends or back-drives, such as trees and graphs. In FCL, nonlinear sets are less implemented, so we will discuss linear sets more.

Note: Due to type security and transformation efficiency, we recommend that you only discuss generic collections.

Linear sets are stored in direct storage and sequential storage. Direct storage means that the data elements of this type of set can be accessed directly by subscript (INDEX). There are three forms in C: array (including array and list <t>), String, struct. The advantage of direct storage structure is that it is very efficient to add elements to the data structure, as long as it is directly placed on the first blank space at the end of the data. Its disadvantage is that inserting an element into a set will become inefficient. It needs to leave a place for the inserted element and move the subsequent element in sequence.

Although string and structs are directly stored structures, they are very different from general set definitions, so they are not discussed in this article. In the directly stored data structure, the selection of array and list <t> needs to be distinguished. Once again, if the number of sets is fixed and transformation is not involved, array efficiency is high; otherwise, list <t> is used.

Sequential storage structure, that is, linear table. The size of a linear table can be dynamically expanded or reduced. It stores data elements in a continuous area. A linear table cannot be searched by index. it searches for elements by referencing addresses. To find an element, it must traverse all elements until it finds the corresponding element. Therefore, a linear table has a high efficiency in data insertion and deletion, but the disadvantage is that the query efficiency is relatively low.

Linear tables can also be divided into queues, stacks, and index clusters. in C #, they are displayed as queue <t>, stack <t>, the Index Cluster is further generalized to dictionary <tkey, tvalue> and two-way linked list <t>.

The queue <t> follows the first-in-first-out mode. It adds elements to the end of the set and deletes elements from the beginning of the set,

Queue operations

Based on the characteristics of the queue, it can be used to process concurrent commands and other scenarios: all client commands are first queued and the queue commands are executed by a dedicated worker thread. In distributed mode, message queue is a typical queue application instance.

Stack stack <t> follows the post-in, first-out mode. It adds elements at the end of the Set, and also deletes elements at the end of the set, 2-3:

Stack operations

Dictionary dictionary <tkey, tvalue> stores key-value pairs, and stores values based on key-based hash codes. A dictionary object consists of buckets that contain collection elements. Each bucket is associated with a hash value based on the key of the element. If you need to search for values based on the key, using dictionary <tkey, tvalue> will make the search and retrieval faster.

A two-way linked list <t> is a collection of element objects of the listnode type. When we think that inserting and deleting data in a collection is slow, we can consider using a linked list. If we use the sort list <t>, we will find that this type does not have the add method common to other sets, instead of addafter, addbefore, addfirst, addlast and other methods. Each node in the two-way linked list points forward to the previous node and backward to the next node.

The linear set is discussed above. In FCL, there are not many implementations of Nonlinear sets. Non-linear sets are divided into hierarchical sets and group sets. Hierarchical sets, such as trees, are not implemented in FCL. A group set, which is divided into a set and a graph. The set is implemented as a hashset in FCL <t>, and the graph is not implemented in FCL. The concept of set means that the elements stored in the set are unordered and cannot be repeated. Demonstrate the purpose of the Set:

Set Operations

In addition to the set types we mentioned above, there are several other set types to be mastered. They are extensions of the above basic types developed in practical applications: sortedlist <t>, sorteddictionary <tkey, tvalue>, sortedset <t>. Their extended classes include list <t>, Dictionary <tkey, tvalue>, and hashset <t>. They are used to change unordered elements into ordered elements.

In addition to the requirements for sorting, the preceding three collection classes are added. Under the namespace system. Collections. Concurrent, several multi-threaded collection classes are involved. They are mainly: concurrentbag <t> corresponds to list <t>, concurrentdictionary <tkey, tvalue> corresponds to dictionary <tkey, tvalue>, concurrentqueue <t> corresponds to queue <t>, concurrentstack <t> corresponding stack <t>. If our set is used in multi-threaded applications, you can use these Collection types. For more information about the thread security of the Set, see msdn.

Most generic collection classes in FCL have been introduced so far. To better understand them, we finally provide a class diagram of the main collection classes. In actual work, select the appropriate collection class as needed.

FCL collection class diagram

Source: http://www.cnblogs.com/luminji/

To select the correct set, we must first understand some data structure knowledge. The so-called data structure is a set of data elements with one or more specific relationships between each other. Let's take a look at the classification of the set.

Set category

In, we can see that the set is generally divided into linear sets and non-linear sets. A linear set refers to a Data Structure Type in which an element has a unique precursor and a rear drive. A non-linear set refers to a data structure type that has multiple front-ends or back-drives, such as trees and graphs. In FCL, nonlinear sets are less implemented, so we will discuss linear sets more.

Note: Due to type security and transformation efficiency, we recommend that you only discuss generic collections.

Linear sets are stored in direct storage and sequential storage. Direct storage means that the data elements of this type of set can be accessed directly by subscript (INDEX). There are three forms in C: array (including array and list <t>), String, struct. The advantage of direct storage structure is that it is very efficient to add elements to the data structure, as long as it is directly placed on the first blank space at the end of the data. Its disadvantage is that inserting an element into a set will become inefficient. It needs to leave a place for the inserted element and move the subsequent element in sequence.

Although string and structs are directly stored structures, they are very different from general set definitions, so they are not discussed in this article. In the directly stored data structure, the selection of array and list <t> needs to be distinguished. Once again, if the number of sets is fixed and transformation is not involved, array efficiency is high; otherwise, list <t> is used.

Sequential storage structure, that is, linear table. The size of a linear table can be dynamically expanded or reduced. It stores data elements in a continuous area. A linear table cannot be searched by index. it searches for elements by referencing addresses. To find an element, it must traverse all elements until it finds the corresponding element. Therefore, a linear table has a high efficiency in data insertion and deletion, but the disadvantage is that the query efficiency is relatively low.

Linear tables can also be divided into queues, stacks, and index clusters. in C #, they are displayed as queue <t>, stack <t>, the Index Cluster is further generalized to dictionary <tkey, tvalue> and two-way linked list <t>.

The queue <t> follows the first-in-first-out mode. It adds elements to the end of the set and deletes elements from the beginning of the set,

Queue operations

Based on the characteristics of the queue, it can be used to process concurrent commands and other scenarios: all client commands are first queued and the queue commands are executed by a dedicated worker thread. In distributed mode, message queue is a typical queue application instance.

Stack stack <t> follows the post-in, first-out mode. It adds elements at the end of the Set, and also deletes elements at the end of the set, 2-3:

Stack operations

Dictionary dictionary <tkey, tvalue> stores key-value pairs, and stores values based on key-based hash codes. A dictionary object consists of buckets that contain collection elements. Each bucket is associated with a hash value based on the key of the element. If you need to search for values based on the key, using dictionary <tkey, tvalue> will make the search and retrieval faster.

A two-way linked list <t> is a collection of element objects of the listnode type. When we think that inserting and deleting data in a collection is slow, we can consider using a linked list. If we use the sort list <t>, we will find that this type does not have the add method common to other sets, instead of addafter, addbefore, addfirst, addlast and other methods. Each node in the two-way linked list points forward to the previous node and backward to the next node.

The linear set is discussed above. In FCL, there are not many implementations of Nonlinear sets. Non-linear sets are divided into hierarchical sets and group sets. Hierarchical sets, such as trees, are not implemented in FCL. A group set, which is divided into a set and a graph. The set is implemented as a hashset in FCL <t>, and the graph is not implemented in FCL. The concept of set means that the elements stored in the set are unordered and cannot be repeated. Demonstrate the purpose of the Set:

Set Operations

In addition to the set types we mentioned above, there are several other set types to be mastered. They are extensions of the above basic types developed in practical applications: sortedlist <t>, sorteddictionary <tkey, tvalue>, sortedset <t>. Their extended classes include list <t>, Dictionary <tkey, tvalue>, and hashset <t>. They are used to change unordered elements into ordered elements.

In addition to the requirements for sorting, the preceding three collection classes are added. Under the namespace system. Collections. Concurrent, several multi-threaded collection classes are involved. They are mainly: concurrentbag <t> corresponds to list <t>, concurrentdictionary <tkey, tvalue> corresponds to dictionary <tkey, tvalue>, concurrentqueue <t> corresponds to queue <t>, concurrentstack <t> corresponding stack <t>. If our set is used in multi-threaded applications, you can use these Collection types. For more information about the thread security of the Set, see msdn.

Most generic collection classes in FCL have been introduced so far. To better understand them, we finally provide a class diagram of the main collection classes. In actual work, select the appropriate collection class as needed.

FCL collection class diagram