473,770 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1343
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 objektorientier ter Datenverarbeitu ng
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
1585
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 byte which is at least 8 bits, short is at least 16 bits, int is at least 16 bits, and long is at least 32 bits. </quote>
2
1724
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 screen, at 7.8 seconds move the ball up and down. At this point, I hear you say 'Oh, like Flash'. Yes, well... Like Flash, but I don't want to take this app in the same direction as Macromedia took Flash, nor do I (ever) want the two to be
2
3516
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 part right but not sure since I keep getting an error message "Compile Error: Loop without Do". Of course I have a Do in the code and have looked at the help files to see what is wrong with my syntax and I don't see the problem.
12
6392
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 ranges, ie between 24/09/2004 and 01/10/2004 together with 05/10/2004 and 07/10/2004 ? If I enter the "Between" criteria on different lines it returns no data.
5
8787
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 to use a Try block to avoid throwing an exception when I try to read data from ranges which aren't there, and this slows things down considerably. I am able to find the *number* of named ranges in a particular workbook using this expression:
67
7710
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 4/30/06 I am looking for suggestions on how to find the date ranges where there were no transactions.
9
2597
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 I do not remember the author, title or link of the paper. Does anyone remember it? Greetings
3
1528
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 http://www.ipaddresslocation.org/ I've collected about 16,000 ranges in the format 208.202.120.0 208.203.111.255 208.203.114.0 208.203.244.127
7
10266
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 want to be able to tell the container to return object a for every given key between 0 and 10, object c for every key between 11 and 500000 and object c for every key between 500001 and 599999, without having to
0
9618
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
9454
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
10260
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
10101
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...
0
9906
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
6712
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
5354
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...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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

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.