473,609 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

organizing elements of two sets for efficient search.

Hi,
I am trying to do the following: I have two sets of integers(both are
disjoint). Based on some criteria, I choose one integer from each set
and do one computationally expensive operation using the two. Now, I do
not want to do the same operation more than once on same pair of
integers. So I was thinking of making up some kind of table of pairs of
two integers, one from each set, and checking in this table if the
operation has already been done. If yes, then I move on, and if not
then I attempt it.
Also, every now and then, I would want to remove all such pairs whose
first element is a given or whose second element is a given value. Also
if I find a new pair which is not already in the table, I would like to
insert it into the table.
For a bit more detail, the operation is linear program, and the set of
integers identify regions in N dimensional space.
So, as to be expected as N increases, the no of elements in the set
could be expected to rise exponentially.

Any suggestions, given this scenario, what might be best way in terms
of efficiency to do it. Of course, this would make sense as long as
searching through the table takes less time then solving the linear
program itself..

thanks,
--a.

Sep 23 '05 #1
1 1243
In article <11************ *********@o13g2 000cwo.googlegr oups.com>,
"Amit" <am*********@gm ail.com> wrote:
Hi,
I am trying to do the following: I have two sets of integers(both are
disjoint). Based on some criteria, I choose one integer from each set
and do one computationally expensive operation using the two. Now, I do
not want to do the same operation more than once on same pair of
integers. So I was thinking of making up some kind of table of pairs of
two integers, one from each set, and checking in this table if the
operation has already been done. If yes, then I move on, and if not
then I attempt it.
Also, every now and then, I would want to remove all such pairs whose
first element is a given or whose second element is a given value. Also
if I find a new pair which is not already in the table, I would like to
insert it into the table.
For a bit more detail, the operation is linear program, and the set of
integers identify regions in N dimensional space.
So, as to be expected as N increases, the no of elements in the set
could be expected to rise exponentially.

Any suggestions, given this scenario, what might be best way in terms
of efficiency to do it. Of course, this would make sense as long as
searching through the table takes less time then solving the linear
program itself..


Instead of a table, how about a std::set<pair<i nt, int> > or perhaps a
std::map<pair<i nt, int>, result>. If your pair<int, int> is reversible
(i.e. pair(x,y) == pair(y,x)) you could write a custom comparison
operator to reflect that.

The removal operation might be problematic if pair(x,y) != pair(y,x) for
searching on the second element of the pair. If the search domain is
large enough, and the search speed important enough, you could set up a
secondary map<int, map<pair<int, int>, result>::iterat or> to help you
quickly find pairs that have a 'y' value. Or perhaps:

typedef list<pair<pair< int, int>, result> Db;
Db container; // unsorted
map<pair<pair<i nt, int>, Db::iterator> sorted_by_x_the n_y;
map<pair<pair<i nt, int>, Db::iterator> sorted_by_y_the n_x;

or some variation thereof. I'm not pretending to have offered a
completely thought out solution, just throwing out some possibilities in
case it helps.

-Howard
Sep 23 '05 #2

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

Similar topics

24
4160
by: superprad | last post by:
Is there an easy way to grab the Unique elements from a list? For Example: data = what I am looking for is the unique elements 0.4 and 0.9 with their index from the list. Probably something like a Hash Table approach!! I would like to get this done without unnecessary overhead.And the list could be essentially anything strings,floats,int etc...
3
4323
by: Jamie | last post by:
Hi, Thanks for the excellent answer to my last question! One more: Does anyone have a method they follow for organizing stylesheets themselves? They seem like they can get bloated and hard to read. Aside from putting all the "h1" rules together, I haven't thought of any way to do it, if it's necessary at all. J.
1
2014
by: Andrea | last post by:
Hi All, I am looking for SOM running under WIN32 and Microsoft Visual Studio 6.0. Can anybody help me? Andrea p.s. I apologize for cross-posting, but I have to solve this problem quickly :|
4
2262
by: omidmottaghi | last post by:
I need to disable/enable form elements in my form. the code i was developed works fine in FF, but in IE, its behaviour is very strange!! in the form, we have a lot of checkboxes, all of them named like "xyz_np". in front of each checkbox, we have some fields, named "xyz" this is my JS code. after clicking on checkboxes:
10
3238
by: Rada Chirkova | last post by:
Hi, at NC State University, my students and I are working on a project called "self-organizing databases," please see description below. I would like to use an open-source database system for implementation and would really appreciate your opinion on whether PostgreSQL is suitable for the project. In general, I am very impressed by the quality of PostgreSQL code and documentation, as well as by the support of the developer community. ...
2
1482
by: Paminu | last post by:
I have a Linked-List and would like to create pointers to elements in this list. e.g I would like two pointers that point to each of their elements in the Linked-List. But there should always be exactly 5 nodes between these pointers. Does this make any sense or are there some more efficient way to access certain elements in a Linked-List?
12
1675
by: Ju Hui | last post by:
I want to remove about 50000 elements from a list,which has 100000 elements. sample code like below: >>> a=range(10) >>> b=range(4) >>> for x in b: .... a.remove(x) .... >>> a
6
1368
by: happyhondje | last post by:
Hello everyone, I've got a little issue, both programming and performance-wise. I have a set, containing objects that refer to other sets. For example, in a simple notation: (<a, b, c>, <d, e>) (or in a more object-like display: set(obj1.choices=set(a, b, c) ). There may be obj1..objN objects in the outer set, and the amount of items in the choices sets could also reach a high number. The objects in the choices sets might overlap.
2
3976
by: jehugaleahsa | last post by:
Hello: I have a bunch of related items that are either parents, children or not directly related to each other. In my case, I have a bunch of database tables joined with foreign keys. Another example would be a family tree. I would like to take a flat list of these items and build the hierarchy. So, in other words, I would like to take one element and figure out its relationship to the other items. When I am all done, I
0
8109
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
8035
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
8534
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
6969
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
6034
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
4059
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2502
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1630
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1366
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.