R
R
RicardoGonsales2017-04-29 17:20:50
OOP
RicardoGonsales, 2017-04-29 17:20:50

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

This table itself is thrust (in a bicycle way) into something like a static property of the class to which the compared objects belong.
Those. as you might guess, when asking if a and b
are equivalent oTable=Equivalent_table()
bool_result=oTable.Equalized(a,b) there
is a stupid long-long loop through the cell array, and then again loop through the cell array (Search function) , and it's all VERY, VERY SLOW, when there are a lot of objects in the oTable (and there are hundreds or even thousands of them).
And the question is: are there similar solutions among "normal" programming languages, but with GREAT PERFORMANCE?
I would prefer C#, because familiar with him, but something else will do.
Those. I know that it is possible to make the same bike on a sharp one-on-one, but I'm afraid of brakes, I'm primarily interested in speed-optimized search...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2017-04-29
@res2001

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.

A
agimgal, 2017-05-02
@agimgal

And what actually prevents to create one more table in a DB with fields id, id_A, id_B and to push all comparison there? if there is an index on id_A, id_B will work very fast. It is not even necessary to rewrite to another PL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question