G
G
Geronom2020-08-13 16:48:00
C++ / C#
Geronom, 2020-08-13 16:48:00

Finding and combining data by condition in ConcurrentQueue / Dictionary - how?

Greetings!

There is a dictionary that contains a key and a set of some string data.

IEnumerable<string> test1 = new List<string>() 
            { 
                "текст 1",
                "текст 2",
                "текст 3",
                "текст 4",
                "текст 5"
            };

            IEnumerable<string> test2 = new List<string>()
            {
                "текст 01",
                "текст 02",
                "текст 03",
                "текст 3",
                "текст 4",
                "текст 5"
            };

            IEnumerable<string> test3 = new List<string>()
            {
                "текст 1",
                "текст 2",
                "текст 3",
                "текст 49870",
                "текст 687"
            };

            IEnumerable<string> test4 = new List<string>()
            {
                "текст 01",
                "текст 02",
                "текст 03",
                "текст 411",
                "текст 611"
            };

ConcurrentQueue<Dictionary<string, IEnumerable<string>>> pairs = new ConcurrentQueue<Dictionary<string, IEnumerable<string>>>();

pairs.Enqueue(new Dictionary<string, IEnumerable<string>> { { "ключ 1", test1 }});
pairs.Enqueue(new Dictionary<string, IEnumerable<string>> { { "ключ 2", test2 } });
pairs.Enqueue(new Dictionary<string, IEnumerable<string>> { { "ключ 3", test3 } });
pairs.Enqueue(new Dictionary<string, IEnumerable<string>> { { "ключ 4", test4 } });


How to get the following result from pairs:

Union #1
Combined: 1, 3

Union #2
Combined: 2, 4

The basic rule of union is that in one union there are only those keys that have common values ​​and the minimum number of such common values ​​is 3.

Then there are 2 values ​​in urls1 and urls3: text 1, text 2, text 3. This union does not include urls2, since it has common values ​​only with urls1, but not with urls3.

Tried different options, but did not get something worthwhile.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
#
#, 2020-08-13
@mindtester

let's first break down the syntax and the tag .. then maybe we can get to itConcurrentQueue>> pairs = new ConcurrentQueue>>();C#
tag

Look here
AYIH3cM.png

- choose C# .. well, understand - copy the code so that I (well, it's not about personalities already) can try it - then and only then, you will get the exact answer

D
d-stream, 2020-08-13
@d-stream

If we are talking about a queue, then do not try to turn it inside out with fur. Its main purpose is the FIFO queue . That is, some processes crap in this queue, and some others are sorted out of it in order of receipt . The closest example is a pharmacy with an "electronic queue": several terminals are placed near each entrance, where a check with a number is printed at an arbitrary moment by pressing a button. And then with this number a scoreboard is displayed above one of the free windows ...
And if you really get something synthetic, then from dictionaries, lists, etc. with the prefix Concurrent or without.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question