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

implicit ranges

I recently faced the following problem: I have an increasing sequence
a1 <= a2 <= ... <= an <= ... The sequence is generated by a function f
such that ai = f(i). Now I want to search for a certain number inside
set a1 ... an. This could be easily done with a binary search. However
I could not find implicit ranges (like xrange in python) in stl such
that I can use lower_bound or upper_bound from <algorithm>. Is there
any such thing in STL or boost? Or do I always have to rewrite the
binary search to support my operation?

--Alexandru

Oct 8 '07 #1
2 1324
On 2007-10-08 22:06, Alexandru wrote:
I recently faced the following problem: I have an increasing sequence
a1 <= a2 <= ... <= an <= ... The sequence is generated by a function f
such that ai = f(i). Now I want to search for a certain number inside
set a1 ... an. This could be easily done with a binary search. However
I could not find implicit ranges (like xrange in python) in stl such
that I can use lower_bound or upper_bound from <algorithm>. Is there
any such thing in STL or boost? Or do I always have to rewrite the
binary search to support my operation?
I am not sure what these implicit ranges are, so all I can tell you is
that lower_bound will work on any sorted container supporting forward
iterators. If you have to write your own container for the implicit
ranges make it support iterators and you will get lower_bound for free
along with other algorithms.

--
Erik Wikström
Oct 8 '07 #2
On Oct 8, 11:58 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-08 22:06, Alexandru wrote:
I recently faced the following problem: I have an increasing sequence
a1 <= a2 <= ... <= an <= ... The sequence is generated by a function f
such that ai = f(i). Now I want to search for a certain number inside
set a1 ... an. This could be easily done with a binary search. However
I could not find implicit ranges (like xrange in python) in stl such
that I can use lower_bound or upper_bound from <algorithm>. Is there
any such thing in STL or boost? Or do I always have to rewrite the
binary search to support my operation?
I am not sure what these implicit ranges are, so all I can tell you is
that lower_bound will work on any sorted container supporting forward
iterators. If you have to write your own container for the implicit
ranges make it support iterators and you will get lower_bound for free
along with other algorithms.
You don't need a container, only iterators. (And lower_bound
will work a lot better if your iterator is random access.)
Boost.iterators has support for iterators which don't require a
backing container; I think once supplies exactly what he's
looking for (but if not, it's really pretty trivial to do).

The problem, of course, is that formally, without a backing
container, the operator* can't return a unique reference, which
means that only input iterator can be supported. I think that
the boost iterators have a way of working around this, as well,
for const iterators (which is what his would be), but I'm not
familiar with the details.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 9 '07 #3

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

Similar topics

30
by: Alf P. Steinbach | last post by:
The C++ FAQ item 29.5 (this seems to be strongly related to C), at <url: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5> mentions that <quote> C++ guarantees a char is exactly one...
2
by: Ben O'Steen | last post by:
Scenario: ========= Using PyGame in particular, I am trying to write an application that will run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put the image of a ball on...
2
by: Loribeth | last post by:
Hi All, I am working on a sub that will loop through a recordset and validate that the ranges are valid, ie no overlapping values - no gaps in the ranges. I am pretty sure I have the validation...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
5
by: John Brock | last post by:
I am using VB.NET to read Excel workbooks which have various named ranges, some of which may not exist in any given workbook. I am trying to get a list of all the range names -- otherwise I need...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
9
by: Christoph Bartoschek | last post by:
Hi, some time ago I've read a paper that advised to store intervals on discrete values in the format [a;b[. One starts with the first element and finishes with one past the last one. However...
3
by: Snedker | last post by:
Hi there, I really need some input of how to approach my little assignment. A customer wants to exclude all US IP-ranges from accessing part of his website. From...
7
by: guido | last post by:
Hi, I'm looking for a container class that can map whole ranges of keys to objects - something like std::map, but not only for individual values for the key, but for whole ranges. Example: I...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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...

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.