Answer the question
In order to leave comments, you need to log in
How to store information about an event where two objects participate?
I have a large number of objects, they are all stored in a linked list. Periodically, an event occurs between two objects. Objects can suddenly be added to the end of the list and removed from anywhere.
How to store information about the occurred event between two objects? I need to know if this event has already happened.
At first I thought to use a dictionary, dictionaries, where the object would be the key. But here there will be either duplication of information or not receiving it, tk. dict[obj1][obj2] != dict[obj2][obj1]. I thought in the direction of bit masks, but the int type is not enough for storage.
I think that you need to give the objects an id and make some kind of hash function that will hash equally as 1 and 2 as 2 and 1, as 1 and 3 as 3 and 1, etc. But such a function does not come to mind.
How best to solve the problem?
Answer the question
In order to leave comments, you need to log in
The first thing that comes to mind is to take the IDs of both objects, sort and glue them into a string through some separator. Such a "function" will give the same result for both 1-2 and 2-1 - something like "1:2".
If we refer to the terminology of databases, then get a new table "Events" (for you, this is a list), and the objects will refer to the elements of this list. If the event should also refer to objects, then this can also be added to the table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question