[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r9241 - Extractor-mono/LibExtractor/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r9241 - Extractor-mono/LibExtractor/src |
Date: |
Thu, 22 Oct 2009 14:40:33 -0600 |
Author: patrick
Date: 2009-10-22 14:40:32 -0600 (Thu, 22 Oct 2009)
New Revision: 9241
Modified:
Extractor-mono/LibExtractor/src/Extractor.cs
Log:
* src/Extractor.cs: replaced RemoveDuplicateKeywords() by a proper
implementation that uses less resources
Modified: Extractor-mono/LibExtractor/src/Extractor.cs
===================================================================
--- Extractor-mono/LibExtractor/src/Extractor.cs 2009-10-21 21:54:07 UTC
(rev 9240)
+++ Extractor-mono/LibExtractor/src/Extractor.cs 2009-10-22 20:40:32 UTC
(rev 9241)
@@ -175,6 +175,46 @@
}
public static Keyword[] RemoveDuplicateKeywords(Keyword[]
keywords, DuplicateOptions options) {
+ int removed = 0;
+
+ for (int i = 0; i < keywords.Length; i++) {
+ Keyword current = keywords[i];
+
+ if (current == null)
+ continue;
+
+ KeywordType type = current.keywordType;
+ string keyword = current.keyword;
+
+ for (int j = 0; j < keywords.Length; j++) {
+ Keyword pos = keywords[j];
+
+ if ((i == j) || (pos == null))
+ continue;
+
+ if ( (pos.keyword == keyword) &&
+ ( (pos.keywordType == type) ||
+ ( ((options &
DuplicateOptions.DUPLICATES_TYPELESS) > 0) &&
+ ( (pos.keywordType ==
KeywordType.EXTRACTOR_SPLIT) ||
+ (type !=
KeywordType.EXTRACTOR_SPLIT)) ) ||
+ ( ((options &
DuplicateOptions.DUPLICATES_REMOVE_UNKNOWN) > 0) &&
+ (pos.keywordType ==
KeywordType.EXTRACTOR_UNKNOWN)) ) ) {
+
+ // do not modify the original
array
+ if (removed == 0)
+ keywords =
CopyKeywords(keywords);
+
+ keywords[j] = null;
+ removed++;
+ }
+ }
+ }
+
+ return RemoveNullKeywords(keywords, removed);
+ }
+
+ /*
+ public static Keyword[] RemoveDuplicateKeywords(Keyword[]
keywords, DuplicateOptions options) {
List<Keyword> lst = new List<Keyword>();
for (int i = 0; i < keywords.Length; i++) {
@@ -207,6 +247,7 @@
else
return lst.ToArray();
}
+ */
public static Keyword[] RemoveEmptyKeywords(Keyword[] keywords)
{
List<Keyword> lst = new List<Keyword>();
@@ -272,6 +313,27 @@
return result;
}
+ private static Keyword[] CopyKeywords(Keyword[] original) {
+ Keyword[] copy = new Keyword[original.Length];
+ Array.Copy(original, copy, original.Length);
+ return copy;
+ }
+
+ private static Keyword[] RemoveNullKeywords(Keyword[] keywords,
int nullCount) {
+ if (nullCount < 1)
+ return keywords;
+
+ Keyword[] copy = new Keyword[keywords.Length -
nullCount];
+ int n = 0;
+
+ for (int i = 0; i < keywords.Length; i++) {
+ if (keywords[i] != null)
+ copy[n++] = keywords[i];
+ }
+
+ return copy;
+ }
+
///
/// Cleanup stuff
///
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r9241 - Extractor-mono/LibExtractor/src,
gnunet <=