Answer the question
In order to leave comments, you need to log in
What is the best way to make an object correspondence table?
Good day to all.
There is one project in Matlab, which I want to gradually overtake to some other programming language in parts (rewrite and call some of the classes from Matlab ... someday I will rewrite the whole thing).
The project provides for a multi-level database.
I need to make an association operation between two objects ( reference
type)
Roughly speaking, I have an object A and B, you need to do the operation Set_B_correspondence (A, B ) so that when you request
A == B? a check was made whether these objects correspond to each other.
!! I do not want to replace A with B or B with A in the database (i.e. do something like X.A = B), because of this, a mountain of problems emerges in terms of the logic of work, because A can lie in different objects, and when replacing it with B, you need to bother with the search system in this database, and you also need to make sure that when cloning the database, this entire mountain of objects in different places is replaced with clones correctly
. I solved this problem , making a bicycle class Equivalent_table, which is an array of approximately the same structure { {A, B, C}; {E}; {X Y} }
. this is a cell array, the elements in it are also a cell array, in which the associated handle-objects (reference type) lie
. from the example above: Match(A,B)=true, Match(A,X)=false
true for objects in the same cell and false for objects in different cells.
When I want to find out if objects A and B are associated with each other, such a request is made
%% Функция проверки на эквивалентность
function bool_result=Equalized(this,a,b)
bool_result=false; %Исходно делаем допущение, что объекты не ассоциированы
if eq(a,b) %если это одинаковые объекты, то результат true
bool_result=true;
else %если это два разных объекта, ищем в таблице
[is_used_a, line_index_a, group_index]=this.Search(a); %сначала а
[is_used_b, line_index_b, group_index]=this.Search(b); %потом b
if is_used_a&&is_used_b&&line_index_a==line_index_b % и если они лежали в одной ячейке, типа как выше {A, B, C}
bool_result=true;
end
end
end
Answer the question
In order to leave comments, you need to log in
Any compiled language will be faster than matlab.
Even C# and Java.
What kind of objects do you store in these tables?
If the tables are sorted, then binary search can be used. Even in matlab there will be a significant acceleration.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question