Use C # To remove duplicate data from the 0.1 million-level Array

Source: Internet
Author: User

10 thousand test data entries

First Algorithm (4 minutes)

 

[Csharp]
///


/// List generic deduplication
///
/// Generics composed of one-dimensional arrays
/// Repeated items to be removed
Private void RemoveRepeaterUrl (ref List List, int ItemID)
{
For (int I = 0; I <list. Count; I ++)
{
For (int j = (I + 1); j <list. Count; j ++)
{
If (list [j] [ItemID] = list [I] [ItemID])
{
List. RemoveAt (j); // remove identical items
I = 0; // deduplication from the beginning. If there are a large number of repeated items in the array, only one deduplication cannot solve the problem. Using this method will make the efficiency slow by 1/3.
J = 0;
}
}
}
}

 

///


/// List generic deduplication
///
/// Generics composed of one-dimensional arrays
/// Repeated items to be removed
Private void RemoveRepeaterUrl (ref List List, int ItemID)
{
For (int I = 0; I <list. Count; I ++)
{
For (int j = (I + 1); j <list. Count; j ++)
{
If (list [j] [ItemID] = list [I] [ItemID])
{
List. RemoveAt (j); // remove identical items
I = 0; // deduplication from the beginning. If there are a large number of repeated items in the array, only one deduplication cannot solve the problem. Using this method will make the efficiency slow by 1/3.
J = 0;
}
}
}
}

 


Second algorithm (4S)

[Csharp]
// Remove duplicate data and return list
 
// Use the containsKeys method of the hashtable class in the class library to determine whether the data exists in hashtable. If the data does not exist
 
// Add the data to the new List and clear the hashtable.
 
Public List GetUnque (List List)
{
List List1 = new List ();
Hashtable hash = new Hashtable ();
Foreach (string stu in list)
{
String [] kk1 = stu. Split (new string [] {"--"}, StringSplitOptions. RemoveEmptyEntries );
String comword = kkk1.length = 3? Kk1 [2]: "";
If (! Hash. ContainsKey (comword ))
{
Hash. Add (comword, comword );
List1.Add (stu );
}
}
Hash. Clear ();
Hash = null;
Return list1;
}

// Remove duplicate data and return list

// Use the containsKeys method of the hashtable class in the class library to determine whether the data exists in hashtable. If the data does not exist

// Add the data to the new List and clear the hashtable.

Public List GetUnque (List List)
{
List List1 = new List ();
Hashtable hash = new Hashtable ();
Foreach (string stu in list)
{
String [] kk1 = stu. Split (new string [] {"--"}, StringSplitOptions. RemoveEmptyEntries );
String comword = kkk1.length = 3? Kk1 [2]: "";
If (! Hash. ContainsKey (comword ))
{
Hash. Add (comword, comword );
List1.Add (stu );
}
}
Hash. Clear ();
Hash = null;
Return list1;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.