A s pecial data structure

A

Alin

Hello
Let me introduce a nice problem:
1. A system S
2. System is composed by modules (Module1, Module2, ... Modulen)
3. Every module contains functions definitions. k-th module contains
functions definitions: Functionk1, Functionk2, ...Functionkm
4. All module can use any function from any module.
For example:
Module3 use Function12 which is defined in Module1.
Module4 use Function76 which is defined in Module7.
Module5 use Function12 which is defined in Module1.
So... Which is the best data structure which can be used? Why?
From my side the "natural" structure seems to be a directional graph
whith multi-vertex...
 
U

usenet

Alin said:
Let me introduce a nice problem:

Thanks for the introduction, but this is a Perl programming group. I'm
not sure how your "nice problem" relates to Perl. Mabye you can help me
understand... (maybe by posting some Perl code which illustrates your
question)
 
A

Alin

Sorry. That's right

For example I had two ways in my mind:
1st one is class implementation.

### package Function
package Function;
sub Function::new{
my @Modules;
my $ptrModules = \@Modules;

my $class = shift;
my $Name = shift; #function name
my $DefModule = shift; #module where function is defined

my $self ={
_Name => $Name, #function name
_DefModule => $DefModule, #module where function is defined
_ptrModules => $ptrModules, #modules which are using the
function(all elements are unique)
};
return bless $self, $class;
}
etc.

######package Module
package Module;

sub Module::new{
my @II; #imported interfaces
my @EI; #exported interfaces
my $ptrExpInterf = \@EI;
my $ptrImpInterf = \@II;

my $class = shift;
my $Name = shift;

my $self ={
_Name => $Name,
_ptrExpInterf => $ptrExpInterf,
_ptrImpInterf => $ptrImpInterf
};
return bless $self, $class;
}
####
There is nothing complicated inside other functions (add, getName,
setName) which are includded... But from ym side there is next item:
same information exists in two places... From my side there 2 negative
items:
1. Redundant information
2. Does't look enough flexible.

2 interesting way is:
$Nodes{"Module1"}{"Module2"}{"function1"} = 1;
$Nodes{"Module1"}{"Module3"}{"function2"} = 1;
$Nodes{"Module1"}{"Module4"}{"function3"} = 1;
$Nodes{"Module1"}{"Module4"}{"function1"} = 1;
where meaning of 1 is function1 defined in Module1 is called in Module
2 .
This way give me a kind of "instant information" if a function 1
defined in module1 is called in module2 or not but next question is how
to get all functions which are called in Module 3 or where is called
function 1?

In a way I don't like 1st model with Node, Function ... and Im looking
for a more "natural" model...
I hope now is much clear... The problem is a design problem with "perl"
constrains ( use the strong points of perl and avoid weak points of
perl)
 
P

Peter J. Holzer

Alin said:
Sorry. That's right

For example I had two ways in my mind:
1st one is class implementation.

package Function; [...]
package Module; [...]
There is nothing complicated inside other functions (add, getName,
setName) which are includded... But from ym side there is next item:
same information exists in two places... From my side there 2 negative
items:
1. Redundant information

See below.
2. Does't look enough flexible.

I think this is more flexible than the other way: You can replace the
whole implementation without changing the interface.

2 interesting way is:
$Nodes{"Module1"}{"Module2"}{"function1"} = 1;
$Nodes{"Module1"}{"Module3"}{"function2"} = 1;
$Nodes{"Module1"}{"Module4"}{"function3"} = 1;
$Nodes{"Module1"}{"Module4"}{"function1"} = 1;
where meaning of 1 is function1 defined in Module1 is called in Module
2 .

I find it curious that you separate the function from where it is
defined. I would have used

$Nodes{"Module1"}{"function1"}{"Module2"} = 1;

or

$Nodes{"Module2"}{"Module1"}{"function1"} = 1;

to represent that Module1::function1 is called from Module2.
This way give me a kind of "instant information" if a function 1
defined in module1 is called in module2 or not

It also gives you instant access to the list of functions on Module1
called from module2. Maybe you thought about that when you devised the
data structure?
but next question is how to get all functions which are called in
Module 3 or where is called function 1?

Search the whole tree.

If you represent multidimensional data in a hierarchical data
structure, you always can search along one dimension more easily than
along the others. So there are two ways:

1) Organize your data so that the most frequent searches are fast, and
live with the fact that others are (relatively) slow.

2) Build multiple trees and choose the one most appropriate for your
search. (This is what relational database systems do: Each index is
a tree duplicating the data for one dimension (or more)).

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top