473,657 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple keys data structure

2 New Member
Hi,

What is the best data structure to use when you have a lot of data to process and you need to later search using different keys. Say you have to store tons of data of this form

struct node
{

string name;
Date date;
Number number;
};

Once you have stored this data you want to get all data for a given name or Date or number.

Also if anyone knows of good data structures in C++ groups please let me know.

Thanks
Jack
Aug 29 '07 #1
3 4753
weaknessforcats
9,208 Recognized Expert Moderator Expert
Do you have a SQL database handy?

Otherwise you will need to build the database and the association tables yourself. Multiple indexes to the same element s tricky since i the element is deleted tor moved, all of the keys to it become invalid.

If you have to do this yourself, manage the database in a linked list and do not delete or move items after they are added. You just mark a node as emtpy but it still remains in the list. This will require an index of empty nodes. I might even go so far as to suggest you generate an empty list and use the index of empty nodes to access the next available node in the list.

This empty list can be an STL map container. The key is node position (which never changes) and the valus is a pointer( or handle) to the node

When you need add an element in the list, you read the map of empy nodes for the first node available. You delete the key from the map.

Then using multimaps for a) name + pointer to node
b) date + pointer to node
c) number + pointer to node

you add keys using the values of the node you just changed.

For removal, a) you add the node to the map of empty nodes.
b) you read the other multimaps using the values of the node
and delete every key that has a pointer to the node being deleted.

For change, delete all keys using the original values and add new keys for the new values.

This approach has the advantage that if you run out of empty nodes, you can add more nodes to the end of the list and add keys to them to the map of empty nodes.

Also, the linked list can be more than one list.

Also, you can add members to your struct because you can always create new multimaps for the new members.

You might consider keeping the node number in the node itself for reference during the add/change/revise operations.

Do all of this using a class to avoid propagating the database code thorughout the application. Be sure it is self-contained.

Finally, consider a SQL inteface to your database. That is, instead of having users call member functions, have then submit an SQL query that youy can parse yourself.

I hope that if you are using Windows that you use SQL Server or Access instead of reinventing the wheel. On Unix, you can call Oracle directly from C++ using Oracle's Pro-C.

Good luck.
Aug 29 '07 #2
Djerba
2 New Member
Hi,

Thank you very much - this looks promising. can you please give more hints on how to implement this in C++. I do not have a database of any kind, this is for an embedded system and I am new to data structures and algorithm - I'm trying to get up to speed if anyone knows of a good book or news group please let me know.

Thanks agin and I hope to hear from you soon.

Do you have a SQL database handy?

Otherwise you will need to build the database and the association tables yourself. Multiple indexes to the same element s tricky since i the element is deleted tor moved, all of the keys to it become invalid.

If you have to do this yourself, manage the database in a linked list and do not delete or move items after they are added. You just mark a node as emtpy but it still remains in the list. This will require an index of empty nodes. I might even go so far as to suggest you generate an empty list and use the index of empty nodes to access the next available node in the list.

This empty list can be an STL map container. The key is node position (which never changes) and the valus is a pointer( or handle) to the node

When you need add an element in the list, you read the map of empy nodes for the first node available. You delete the key from the map.

Then using multimaps for a) name + pointer to node
b) date + pointer to node
c) number + pointer to node

you add keys using the values of the node you just changed.

For removal, a) you add the node to the map of empty nodes.
b) you read the other multimaps using the values of the node
and delete every key that has a pointer to the node being deleted.

For change, delete all keys using the original values and add new keys for the new values.

This approach has the advantage that if you run out of empty nodes, you can add more nodes to the end of the list and add keys to them to the map of empty nodes.

Also, the linked list can be more than one list.

Also, you can add members to your struct because you can always create new multimaps for the new members.

You might consider keeping the node number in the node itself for reference during the add/change/revise operations.

Do all of this using a class to avoid propagating the database code thorughout the application. Be sure it is self-contained.

Finally, consider a SQL inteface to your database. That is, instead of having users call member functions, have then submit an SQL query that youy can parse yourself.

I hope that if you are using Windows that you use SQL Server or Access instead of reinventing the wheel. On Unix, you can call Oracle directly from C++ using Oracle's Pro-C.

Good luck.
Sep 4 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
I cannot provide a code solution. My reply gave you some suggestions. Until you start a code solution and get stuck, I cannot help you further.
Sep 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

57
3591
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
3
1763
by: Gaz | last post by:
I have a table which has 10 columns which make up the secondary key. 1 or more of these columns can be set but the remaining columns in the secondary key will be null. For example : id k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 data ------------------------------------------------- 0 1 1 - - - - - - - - test0 1 1 1 1 - - - - - - - test1 2 1 1 2 - - - - - - - test2
26
14118
by: pb648174 | last post by:
I have a table called BidItem which has another table called BidAddendum related to it by foreign key. I have another table called BidFolder which is related to both BidItem and BidAddendum, based on a column called RefId and one called Type, i.e. type 1 is a relationship to BidItem and type 2 is a relationship to BidAddendum. Is there any way to specify a foreign key that will allow for the different types indicating which table the...
5
6400
by: Zero.NULL | last post by:
My multiple level nested corelated query is not fetching correct result. It work fine on small set of data, but fails on larger set of data. Any clue? Explaining data storing and discussing design would be tough for me here, still to show you how complex I have created my life, here is the query: select (
12
1755
by: Peter Proost | last post by:
Hi group, has anyone got any suggestions fot the best way to handle this problem, I've got 3 tables for example table A, B, and C table A looks like name, value table B looks like name, value table C looks like variablename, value, value an example would be
0
2008
by: The Frog | last post by:
Hello Everyone, I have been asked to try and create a single SQL query to retrieve product information from a database. The way that data is arranged is that in some tables there are user defined "attributes" or "dimensions" that in turn connect to the actual product table via a many-many (using a linking table). In each linking table there is a combination of the "dimension", the productID, and the "fact" that is stored against the...
8
2587
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array; m_ResultArray.Add ( aFoundObject);
13
3770
by: Eric IsWhoIAm | last post by:
I have four tables created so far: Courses, Instructors, Courses and Instructors (which shows the Course and Instructor Name fields, but holds their IDs since those are the keys), and Students. Now, I wish to create a Classrooms (or something similar) table which will allow me to pick the Course from Courses and Instructors, and hold multiple Students for each Course. I am unsure how to do this in Access. Each student can have multiple...
2
407
by: norseman | last post by:
Terry Reedy wrote: ================ First part I understand, second is still giving me a problem. For some reason I still want keys to be dbf column headers. like: name:address:zip so forth ---- ------- --- ------------------ guy: unknown:00000
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
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...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
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
8621
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
7354
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...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.