Сравнение двух строкового массива и возвращение различий каждого в vb6 с хорошей производительностью - PullRequest
1 голос
/ 14 февраля 2012

У меня есть 2 расширяемых массива со строками в них, и я хочу сравнить оба друг с другом, чтобы увидеть, какие из них содержат строки, которых нет у другого.

Допустим, мои массивы похожи на:

ARRAY - 1       ARRAY - 2
   a1               a1
   a2               a2
   a3               a3
   a9               a4
   a10              a8
   a11              a10
   a12              a11

Я хочу получить результат как:

ARRAY - 4       ARRAY - 5       ARRAY - 6
   a9               a4             a1
   a12              a8             a2
                                   a3
                                   a10
                                   a11

другой 3 другой массив должен дать мне разницу в массиве 1 по сравнению с массивом 2

-array4 here gives the strings that is included in array1 but not found in array2
-array5 here gives the strings that is included in array2 but not found in array1
-array6 here gives the strings that is found in both

для этого я кодировал:

i = 0
j = 0

For Each innerElement1 In CompareElement1 'CompareElement1 is the array1 here

    NoneFound = 1

    'Ones thats in first element also found in second element..
    For Each innerElement2 In CompareElement2 'CompareElement2 is the array2 here

        If innerElement1 = innerElement2 Then

            'Expand array
            ReDim Preserve IncludedInBoth(0 To UBound(IncludedInBoth) + 1)
            IncludedInBoth(i) = innerElement1
            'Item found in both so NoneFound is 0.
            NoneFound = 0
            i = i + 1

        End If

    Next

    'Ones thats in first element but not found in second element..
    If NoneFound = 1 Then

        'Expand array
        ReDim Preserve NotIncludedInElem2(0 To UBound(NotIncludedInElem2) + 1)
        NotIncludedInElem2(j) = innerElement1
        j = j + 1

    End If

Next

'Seperate Comparison for the ones that found in second element _
 but not found in first element..
i = 0

For Each innerElement1 In CompareElement2

    NoneFound = 1

    'Ones thats in second element also found in first element.
    For Each innerElement2 In IncludedInBoth

        If innerElement1 = innerElement2 Then

            'Item found in both so NoneFound is 0.
            NoneFound = 0

        End If

    Next

    'Ones thats in second element but not found in first element..
    If NoneFound = 1 Then

        'Expand array
        ReDim Preserve NotIncludedInElem1(0 To UBound(NotIncludedInElem1) + 1)
        NotIncludedInElem1(i) = innerElement1
        i = i + 1

    End If

Next

мой код там точно выполняет сравнение и дает верный ответ, но при недостаточной производительности, вызванной внутренними вызовами for each, есть ли способ сделать это по сравнению с более быстрым способом? чтобы закончить это сравнение, нужно вечно.

также небольшая заметка:

array1 and array2 are two different sized arrays that contains thousands(~100.000)of strings in each.
also they are not in order. i would like to learn how to order them alphabetically.

1 Ответ

2 голосов
/ 15 февраля 2012

с таким количеством данных создайте базу данных, загрузите в таблицы и используйте SQL.Он будет работать слишком медленно, пытаясь сделать это вручную.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...