473,725 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

program design, what datastructure to choose question.....

Hello,

I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\n
24\t11\t4\t10\n
.....

I now have a structure which allows me to access the data like this:
x->row[i].coll[0].value.d;
where coll is a structure containing a union and the type of data used in
this field. x->row[i].coll[0].utype ;

However in my inexperience I forgot that most of the functions I want to
use on this data accept arrays only - Now I have added an extra step to
create an array of pointers linking to all the values in the
collumn.unions.

When I think of it [what I should have done before starting to program] I
have three choices;
Leave it this way disregarding the extra overhead of creating an array of
pointers, but maintaining all the preferences of each field.
Remove the union and create void pointers
or at runtime create an array for each collumn and a `super' structure
that holds all the preferences of each collumn.

Again I'm not very experienced with this - but what would be the best way
to go for storing this type of data in such way that it becomes easy to
preform operations on it ?

Any suggestions are welcome.

Thank you.

Jas.
Nov 9 '07 #1
6 1667
jason <ji***@notmal.c omwrites:
I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\n
24\t11\t4\t10\n
....

I now have a structure which allows me to access the data like this:
x->row[i].coll[0].value.d;
where coll is a structure containing a union and the type of data used in
this field. x->row[i].coll[0].utype ;
Looks like overkill. You have a pointer to a struct containing a
array of another struct containing an array of some union type? Wow.
(BTW coll does not seem to be structure as you claim but rather an
array.)

The data looks tabular, so the first thing is so say why a 2D array is
not suitable. If it is not, we can then go further.

There may be very sound reasons for what you have done, but showing
two rows of four integers does not capture the complexity. What is
the data and how is it accessed? Do you need to process columns as
well as rows?

--
Ben.
Nov 9 '07 #2
On Fri, 09 Nov 2007 16:36:16 +0000, Ben Bacarisse wrote:
jason <ji***@notmal.c omwrites:
>I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\ n
24\t11\t4\t10\ n
....

I now have a structure which allows me to access the data like this:
x->row[i].coll[0].value.d;
where coll is a structure containing a union and the type of data used
in this field. x->row[i].coll[0].utype ;

Looks like overkill. You have a pointer to a struct containing a array
of another struct containing an array of some union type? Wow. (BTW
coll does not seem to be structure as you claim but rather an array.)

The data looks tabular, so the first thing is so say why a 2D array is
not suitable. If it is not, we can then go further.

There may be very sound reasons for what you have done, but showing two
rows of four integers does not capture the complexity. What is the data
and how is it accessed? Do you need to process columns as well as rows?
Well that's the thing... Youre right that it is a overkill...

I would like todo something like function(A, B, nsize);
Where `A' and `B' are the collumn designators.
about accessing rows I would also like to do something like:
function(A10, B10); so accessing the values in row[10] collumn `A' etc...

I think that I'm going to scale back the complexity as I think of it
more..

Jas.
Nov 9 '07 #3

"jason" <ji***@notmal.c omwrote in message
news:47******** *************** @dreader21.news .xs4all.nl...
Hello,

I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\n
24\t11\t4\t10\n
....

I now have a structure which allows me to access the data like this:
x->row[i].coll[0].value.d;
where coll is a structure containing a union and the type of data used in
this field. x->row[i].coll[0].utype ;

However in my inexperience I forgot that most of the functions I want to
use on this data accept arrays only - Now I have added an extra step to
create an array of pointers linking to all the values in the
collumn.unions.

When I think of it [what I should have done before starting to program] I
have three choices;
Leave it this way disregarding the extra overhead of creating an array of
pointers, but maintaining all the preferences of each field.
Remove the union and create void pointers
or at runtime create an array for each collumn and a `super' structure
that holds all the preferences of each collumn.

Again I'm not very experienced with this - but what would be the best way
to go for storing this type of data in such way that it becomes easy to
preform operations on it ?

Any suggestions are welcome.
this depends on what you are doing...

however, here are a few typical ways to deal with 2D grids of values:
a 2D array (say, of pointers);
a 1D array indexing 1D arrays;
a custom representation (say, the above, but combined with a sequence of
"spans" or similar for applying in-memory compression);
....

a 2D array is good for speed and simplicity, and can also be memory
efficient (if the data is strictly a grid), but it can become very slow to
resize or also very wasteful with memory in some cases.
a 1D array of 1D arrays adds a little more complexity and overhead, but can
make dynamic resizing a lot faster and easier (adding an item often only
involves expanding 1 or 2 of these arrays).

a pair of arrays with a system of 'spans' is useful for when items are
spread sparsely over a large area, as this allows storing a fairly large
space in a comparatively small number of array spots. however, this adds yet
more complexity.
value:
this depends again very highly on usage.

if the values are usually or almost always the same type, and there is
little or no variation is the size, a slab may be a good option. this is an
array of items (say, structs), where we grab off items as needed and use
them where needed (usually a method exists for fairly quickly finding free
items, with linear allocation, marks+rovers, and free-lists being common
approaches).

it types are far more hetrogeneous (one item may be an integer, a float, a
string, another array, an object, ...) implementing some kind of dynamic
type system may be sensible.

for example, each item is an integer with a few low bits used to indicate
type, with the rest being either a value, a pointer, or a handle.

another approach is to use pointers, but implement a system for finding
types associated with pointers (for example, hidden object headers, having
the pointers point into 'special' areas of memory known to represent items
of specific types, ...).
and there are many other factors...

or such...

Thank you.

Jas.

Nov 9 '07 #4
jason wrote:
Hello,

I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\n
24\t11\t4\t10\n
.....
The first thing i thought of, was

T matrix[n][m];
--
Tor <bw****@wvtqvm. vw | tr i-za-h a-z>
Nov 9 '07 #5
Jams Jamma <ja*****@jamba. comwrites:
On Fri, 09 Nov 2007 16:36:16 +0000, Ben Bacarisse wrote:
>jason <ji***@notmal.c omwrites:
>>I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11 \n
24\t11\t4\t10 \n
....

I now have a structure which allows me to access the data like this:
x->row[i].coll[0].value.d;
where coll is a structure containing a union and the type of data used
in this field. x->row[i].coll[0].utype ;

Looks like overkill.
The data looks tabular, so the first thing is so say why a 2D array is
not suitable. If it is not, we can then go further.
Well that's the thing... Youre right that it is a overkill...

I would like todo something like function(A, B, nsize);
Where `A' and `B' are the collumn designators.
about accessing rows I would also like to do something like:
function(A10, B10); so accessing the values in row[10] collumn `A'
etc...
C has no way to access the columns of a 2D array (well, it has not
way other than simply indexing the elements). If you need a function
that can do the same sort of thing to either the rows or the columns,
a common trick is to make the parameter a plain pointer and to pass a
"stride" -- the gap between elements.

So you build a 'T array[N][M];' and you pass:

function(&array[x][0], 1); /* to access row x */
and
function(&array[0][y], M); /* to access column y */

Inside 'function(T *p, size_t stride)', you inspect elements
'p[i * stride]'.

The other standard method is simply to transpose the matrix or extract
the columns into a 1D array as needed. Obviously the trade-offs
between methods depends on the details.

Some languages allow you to do this directly.

(Code caveat: check the details, it's late!)

--
Ben.
Nov 10 '07 #6
On Fri, 09 Nov 2007 14:43:32 +0000, jason wrote:
Hello,

I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\n
24\t11\t4\t10\n
....

I now have a structure which allows me to access the data like this:
x->row[i].coll[0].value.d;
where coll is a structure containing a union and the type of data used
in this field. x->row[i].coll[0].utype ;

However in my inexperience I forgot that most of the functions I want to
use on this data accept arrays only - Now I have added an extra step to
create an array of pointers linking to all the values in the
collumn.unions.

When I think of it [what I should have done before starting to program]
I have three choices;
Leave it this way disregarding the extra overhead of creating an array
of pointers, but maintaining all the preferences of each field. Remove
the union and create void pointers or at runtime create an array for
each collumn and a `super' structure that holds all the preferences of
each collumn.

Again I'm not very experienced with this - but what would be the best
way to go for storing this type of data in such way that it becomes easy
to preform operations on it ?

Any suggestions are welcome.

Thank you.

Jas.
Thank you for all your suggestions, Its more clear now. I made the
overall structure a bit to complicated and I'm going for a plain 2D array
with one structure that holds any preferences for each collumn.
Simplicity is the key for me here..

Thankx again.

Jas.
Nov 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1333
by: Nick Evans | last post by:
Hey all, I am currently working on a simple program (small group membership database) just to get to grips with the language (bit of a newbie here :-)) and am wondering about the best way of organising the data within the program. From my understanding I would have something like person1 =("name","address","phone","subs-due") Then you would put membershipdatabase = (person1, person2, personX....) etc Now is this the best way of...
13
3406
by: takashi | last post by:
Hi, I have a question. I am learning about how to use c++ language. I have attempted to make my own programs, using the knowledge that I have, but sometimes when I get stuck on writing a code, it took me a long time to figure out what I should do. For instance, I was writing a program which tells you all the prime numbers that are less than the number you input on the console. It was a very short program, but it took me a while to write...
2
1280
by: eddiec | last post by:
hi everyone, I am designing a pallet management system. Many items are placed onto one pallet. The items are all unique and have distinct features. Now, as far as application design is concerned the most intuitive way of handling this would be to have a Pallet object that holds an array of Item objects, which reflects the situation in real life. As far as database design is concerned, however, it is easier for the item to 'know' which...
3
2004
by: Merlin | last post by:
Design Problem =============== Would appreciate any help or suggestion on this design issue. I have spent a great deal of time and effort for an elegant solution but it seems I am not getting anywhere... I have simplified my design problem to the following: Consider the following classes:
51
5077
by: John Baker | last post by:
Hi: Some time ago I developed a program in Access, and separated the database and the program itself (using the normal access tools).We have the db on our server and the programin the desktop system. I have modified the program a number of times, and now find that I need to change the DB slightlt. This appears to require that I REMERGE the data base and program, and I have no idea how to do that. Can someone give me some pointers,...
2
2140
by: Mike | last post by:
Hi I have been tasked with converting my pulp and paper mills weekly projected and actual contractor hrs excel spreadsheet into a an Access 97 database. So far my design has been to use a form with a button for each to day navigate the recordset of a single table using .findfirst and .nomatch and I am worried about performance as I'm basically creating a flat file.
6
3658
by: Santosh | last post by:
Hello, I would like some input on choosing a datastructure and a algorithm. I have a text file which contains three strings(say name, phonenumber and city). The file contains a about a billion records. I need to choose a datastructure which will sort efficienctly based on any of the strings(keys) which may be any one of the three or a combination of the three in which case we will need to sort with multiple keys.
29
4402
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this process. Is it correct?
21
1584
by: Pieter | last post by:
Hi, I need some type of array/list/... In which I can store objects together with a unique key. The most important thing is performance: I will need to do the whole time searches in the list of given keys. Which datastructure will be best suited for this? A Hashtable? The list may contain upto 10^12 items, bit more proably most of the time +- 10^9 of even 10^6... Thanks a lot in advance,
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.