This is my work but not home work. I am trying to come up decide how best to represent a data I have using a native data structure(By native i mean I cannot use STL in C++, its a C++ code. Its our design decision not to use STL and have no way to change it or violate it)
Data is as follows:
There is a variable say int to denote ipaddr say e.g. 192.168.10.77(lets say this is stored in a int which is uniquely obtained from the 192.168.10.77 ) which lets call deviceId.
Now for each such deviceId there are other fields multiple services associated to it say service 1, service2, etc... Number of services associated with each device is variable from one deviceId to another.
So a sample of data could look like:
192.168.10.77
service1
service2
service3
service4
192.168.10.98
service1
service2
192.168.10.97
service1
Right now I store it in a inefficient data structure as below.
I have a struct as:
typedef struct
{
deviceId d;
serviceId s;
}mystr;
And then I use an array of a struct which holds
mystr mylist[64];
so entries of this array look like
mylist[0].d = 192.168.10.77
mylist[0].s = service1
mylist[1].d = 192.168.10.77
mylist[1].s = service2
mylist[2].d = 192.168.10.77
mylist[2].s = service3
mylist[3].d = 192.168.10.77
mylist[3].s = service4
mylist[4].d = 192.168.10.98
mylist[4].s = service1
mylist[5].d = 192.168.10.98
mylist[5].s = service2
... ... and so on ....
Essentially the deviceId value is duplicated as many times as there are services associated to it.
I need some thing more efficient because later I have to group all the services associated with a device.
So to do that I might have to search for deviceId and club the services for it together. I don't know how I am going to search by deviceId as it can have any value.
What is a better way to represent this data using some optimal data structure ?
[ I can see it as linked list but could not come up with the struct Node{ }
for it ]