473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Which method to use

I'm working with data that streams into a function which I'd like to
sort from low to high based on the value of the first record. What
would be the best most efficient way to do this... linked lists, an
array, or..? Here's an exmplae of what I'm looking at:

void MyData::StreamingData()
{
double a = sData->record;
int b = sData->record2
char ss[256];
printf(ss, "%.4lf %d", a, b);
}
96.01 5
96.01 3
97.01 1
98.02 9
97.01 1


etc.

I get a record every few minutes, so I'd like to limit the stored data
to maybe 10 records... so the container would be continually adding and
deleting on the fly. I'd also like to be able to delete records if the
second record returns a 0. What route would be the best for this
scenario?

With much appreciation,
Marcus

Jul 23 '05 #1
5 1227
Ok, well it seems perhaps I need to narrow down the direction for
appropriate guidance.

I currenlty have ruled out using arrays for this problem and have
narrowed it down to using either the STL list or STL set. I'm starting
to veer away from the list, because everytime an insertion is made the
list would have to be resorted... which isn't very efficient. While,
with set it is possible to maintain an ordered container without
sorting. However, I'm still unclear on which route to go, as I've never
attempted something like this before.

Anyway, if anyone has any suggestions, or needs me to be more clear on
what I'm trying to accomplish, please let me know.

Best regards,
Marcus

Jul 23 '05 #2
* Marcus:
I'm working with data [pairs] that streams into a function which I'd like to
sort from low to high based on the value of the first [item in each pair]. What
would be the best most efficient way to do this... linked lists, an
array, or..?
Programming efficiency: use a std::map.
Execution efficiency: don't worry about that.
Memory usage efficiency: don't worry about that.

Here's an exmplae of what I'm looking at:

void MyData::StreamingData()
{
double a = sData->record;
int b = sData->record2
char ss[256];
printf(ss, "%.4lf %d", a, b);
}


Note that you're missing a semicolon in there. That means the printf
specification might also be missing a character, or be misspelled. And
in that case you're out in Undefined Behavior territory (not that I say
you are, but printf is dangerous, not recommended for newbies).

Anyway, don't do i/o in member functions, except in classes _dedicated_
to i/o.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #3
On 2005-07-13 12:47:27 -0500, "Marcus" <mc*******@walla.com> said:
I'm working with data that streams into a function which I'd like to
sort from low to high based on the value of the first record. What
would be the best most efficient way to do this... linked lists, an
array, or..? Here's an exmplae of what I'm looking at:

void MyData::StreamingData()
{
double a = sData->record;
int b = sData->record2
char ss[256];
printf(ss, "%.4lf %d", a, b);
}
96.01 5
96.01 3
97.01 1
98.02 9
97.01 1


etc.

I get a record every few minutes, so I'd like to limit the stored data
to maybe 10 records... so the container would be continually adding and
deleting on the fly. I'd also like to be able to delete records if the
second record returns a 0. What route would be the best for this
scenario?


I don't understand. You have a process/function call that produces
data, and you have to write a sorting function on that data based on
your criteria? You say that you will limit data allocation to 10 items,
but so the stream wouldn't be sorted if you just sort them 10 at a time
step.a

For what I understand, if you have a function that uses a tuple, then
you really don't need STL or C++. You have a slow data rate, but you
don't say anything about the amount of data you have actually to sort,
could be terabytes...

With qsort and standard C you can easily do whatever you want without
adding complexity. If your data set is huge, then probably you want an
on disk routine, which is far more complex.

Explain better the problem...

--
Sensei <se******@tin.it>

cd /pub
more beer

Jul 23 '05 #4
Alf, thanks for the std::map, suggestion, I'll be looking in to how to
use that. Yes, it appears I missed a semicolon... I must have missed it
when I was modifying it to something more readable/understandable.

Sensei, yes the function call produces data which needs to be sorted
with a maximum of 10 items in the container at any given time. So when
there are 10 items in the container and the function receives a new
pair, there needs to be an operation that adds and removes a pair in
the container so that the limit is always ten based on the value of the
"a" double variable. For example:

If a is > than any a->item in the container, then the pair is not
added. If a is < than any a->item in the container then the pair is
added in order based on the value of a, unless the value of b is 0 in
which case this would give instruction to remove a pair of matching "a"
value.

The amount of data is trivial, just take a look at the example output
above and imagine there never being more than ten items as above in the
container. So, like 70 bytes for the container... very compact. The
container needs to be small as it will be used in a small GUI where
this data will be viewed in real time.

Hope this was more clear.

Marcus

Jul 23 '05 #5
On 2005-07-15 22:12:34 -0500, "Marcus" <mc*******@walla.com> said:
Sensei, yes the function call produces data which needs to be sorted
with a maximum of 10 items in the container at any given time. So when
there are 10 items in the container and the function receives a new
pair, there needs to be an operation that adds and removes a pair in
the container so that the limit is always ten based on the value of the
"a" double variable. [...]


I see. Well, if size *really* matters, use plain C and make a
do-it-yourself function, which is really really small. If you can
afford std::map and std::string and so on, then use it and don't bother
about C :)

--
Sensei <se******@tin.it>

cd /pub
more beer

Jul 23 '05 #6

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

Similar topics

2
by: Rick Trotter | last post by:
I was trying to write some polymorphic application code and found that a superclass method implementation gets invoked when I expect a subclass implementation. Here's how I have abstracted the...
3
by: Edward | last post by:
ASP.NET / VB.NET SQL Server 7.0 Our client has insisted that we change our established practice of building SQL in-line and move it all to SPROCs. Not a problem for 80% of the app. However,...
17
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
13
by: Benny | last post by:
Hi, I have something like this: try { // some code } catch // note - i am catching everything now {
1
by: Tomas | last post by:
Is there any sequence diagram on the web that clearly shows in which order all Page methods (load, render and so on) are being called compared to the order the page's contained control methods are...
4
by: Lerp | last post by:
Hi all, With regards to calling data from a database and filling in an editing form based on some query, which is the best (least intensive on processor) method for assigning the returned...
20
by: Parag | last post by:
Hi, I am trying to figure out best testing tool for my project. I have narrowed down my requirements to two tools NUNIT and VSTS unit. But I have used neither and I have to use only one of them....
1
by: thickface | last post by:
Hi all, I have a question and any suggestions for solutions would be greatly appreciated. In my program, I first defined a variable called 'incidence' which has to be updated at every time step, ...
4
by: QC | last post by:
Hi Friends, I have one Application running on Client PC, i coded to store all Debug, Info, and Trace related information in Log file. This log file helps me to analyze the exception if any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.