473,395 Members | 1,726 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,395 software developers and data experts.

keep splitting the atom question

Hello

I am writing a sampling type program which takes a buffer, and picks
the middle of the buffer. But I need to take a bit out the middle and
then take what is left (on both sides) and take the middle out of
these fragments.

I have a function which takes a range, eg start, end and a samplesize
and calculates the range of the buffer to take for sampling. But of
course each time I call this function it creates two new start-end
ranges to again get the middle bit again. I have a size of sample so
when the middle bits reach the sample size I just stop.

How would I write something to achieve this? Should it be a recursive
function?

Sep 25 '07 #1
4 1364
"Angus" <an*********@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
Hello

I am writing a sampling type program which takes a buffer, and picks
the middle of the buffer. But I need to take a bit out the middle and
then take what is left (on both sides) and take the middle out of
these fragments.

I have a function which takes a range, eg start, end and a samplesize
and calculates the range of the buffer to take for sampling. But of
course each time I call this function it creates two new start-end
ranges to again get the middle bit again. I have a size of sample so
when the middle bits reach the sample size I just stop.

How would I write something to achieve this? Should it be a recursive
function?
I'd probably do it recursively. This is more a programming question than a
C++ quesiton though.
Sep 25 '07 #2
On 2007-09-25 12:28, Angus wrote:
Hello

I am writing a sampling type program which takes a buffer, and picks
the middle of the buffer. But I need to take a bit out the middle and
then take what is left (on both sides) and take the middle out of
these fragments.

I have a function which takes a range, eg start, end and a samplesize
and calculates the range of the buffer to take for sampling. But of
course each time I call this function it creates two new start-end
ranges to again get the middle bit again. I have a size of sample so
when the middle bits reach the sample size I just stop.

How would I write something to achieve this? Should it be a recursive
function?

Recursive is probably a good idea. However for these kinds of questions
please consult comp.programming instead.

--
Erik Wikström
Sep 25 '07 #3
Angus wrote:
I am writing a sampling type program which takes a buffer, and picks
the middle of the buffer. But I need to take a bit out the middle
What does that mean "to take a bit out the middle"?
and
then take what is left (on both sides) and take the middle out of
these fragments.
And then what? When does it end, and what do you expect as the result
of that processing?
I have a function which takes a range, eg start, end and a samplesize
and calculates the range of the buffer to take for sampling. But of
course each time I call this function it creates two new start-end
ranges to again get the middle bit again. I have a size of sample so
when the middle bits reach the sample size I just stop.

How would I write something to achieve this? Should it be a recursive
function?
Yes, the recursion seems to fit right in.

template<class Iterator, class F>
void doSomethingWithTheMiddle(Iterator start, Iterator end, F f)
{
if (start != end) { // not an empty range
Iterator middle = start + (start - end)/2;
f(*middle);
doSomethingWithTheMiddle(start, middle);
doSomethingWithTheMiddle(middle, end);
}
}

The function above has a flaw -- it will recurse infinitely for a range
of length 1. You need to correct it. Hint: you need to add 1 addition
somewhere.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 25 '07 #4
>
template<class Iterator, class F>
void doSomethingWithTheMiddle(Iterator start, Iterator end, F f)
{
if (start != end) { // not an empty range
Iterator middle = start + (start - end)/2;
Did you mean:

= start + (end-start)/2; // which equals (start+end)/2

?
f(*middle);
doSomethingWithTheMiddle(start, middle);
doSomethingWithTheMiddle(middle, end);
}
}
-Howard

Sep 28 '07 #5

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

Similar topics

6
by: Steve Jorgensen | last post by:
I tried to fix a problem for a client today in which report sections and even individual text controls in some of their reports are being split across page boundaries. Of course, I was thinking...
2
by: Just close your eyes and see | last post by:
Hello All can any one help me where is the windows atom table and how to navigate it, and how to add and delete values from it thx
0
by: banjolibrarian | last post by:
I have been setting up RSS and Atom feeds for our library's podcasts. The RSS feed works fine, but when I subscribe to the Atom feed (via Bloglines), the link to the file itself defaults to...
15
by: Brady Love | last post by:
I am currently working an an app that will post and edit blogs on blogger. Right now I have it so I can recive a list of the blogs and the content of those blogs using Atomizer. This is my first...
0
by: S.T | last post by:
Hi! I've spend this weekend trying and coding a php-based atom- and rss-feed writer. I don't know if this is the right place for my questions. However, since both feeds are based on xml, maybe...
1
by: yawnmoth | last post by:
I recently saw a phpBB modification that presented feeds in RSS 0.91, RSS 1.0, RS 2.0, and Atom 1.0. In contrast, sites like wikipedia (when viewing article history) only seem to offer one version...
1
by: aplonis | last post by:
I have an XML (Atom) doc at this URL... Atom ...which displays as HTML using any one of three XSLT stylesheets, the principal one being at this URL... XSLT ...with two...
2
by: Hakuin | last post by:
Hello! I have to fetch and syndicate some data from a atom feed (blogger's) in asp.net 2.0; I read I need a xml schema to work on the xml as a datagrid, but I can't find on the internet a atom...
7
by: js | last post by:
Hi, I'm looking for RSS/ATOM generator I can use in Python. I searched on pypi and the other places but I couldn't find any options on this. (I found many parsers, though) Is there any de-fact...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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...

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.