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

collection find()

If you have a sorted collection, how do you find the location ^closest^
to where a particular key would be if an element with key isn't in the
collection?

For example, if you have a SortedArray containing:
{ 1.102, "fox" }
{ 1.592, "cat" }
{ 2.239, "dog" }
how do you get an interator that points to the location where { 1.910,
"otter" } would be inserted? (I guess in this case the functional
equivalent of an iterator is the index of.)

What I'm hoping for is something that looks like:
int index = mySortedArray.find(1.910); // sets index = 2

Thanks,
H

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
2 3538
One way to get the index of where an item would be inserted is to
actually insert the item to the collection. Get the index and remove the
item.
Just an idea.

--

This posting is provided "AS IS" with no warranties, and confers no rights.
"howard" <none> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
If you have a sorted collection, how do you find the location ^closest^
to where a particular key would be if an element with key isn't in the
collection?

For example, if you have a SortedArray containing:
{ 1.102, "fox" }
{ 1.592, "cat" }
{ 2.239, "dog" }
how do you get an interator that points to the location where { 1.910,
"otter" } would be inserted? (I guess in this case the functional
equivalent of an iterator is the index of.)

What I'm hoping for is something that looks like:
int index = mySortedArray.find(1.910); // sets index = 2

Nov 16 '05 #2
That would work (would be dog-ugly, but work) unless the element did
already exist, in which case it would be overwritten.

I'm sure there must be a simple, efficient way to do this. Right now the
only way I can think of to do it is to get the keys and do my own binary
search. Surely there's another way??

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

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

Similar topics

9
by: Gerald Lightsey | last post by:
I am doing some work that involves automating MS MapPoint 2002. The object model is documented in the context of Visual Basic 6.0. A typical example follows. 'Output first result of find...
16
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
5
by: Jeff Stewart | last post by:
Let's say I create a collection of DateTime objects like so: Dim clxn_Times As Collection = New Collection() Let's go on to say I add 3 elements to the collection. How do I pull off the...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
1
by: Ruben | last post by:
I have a collection (PersonCollection inherits collectionbase and implements ITypedList it's a collection of Person objects) this collection also implements the IComponent interface, so I can drag...
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
1
by: holysmokes99 | last post by:
I have run the VB.Net upgrade wizard to get a vb6 project up to VB.Net 1.1. This is a class library that is referenced by another VB6 app. I have exposed it to for COM access. The problem is that...
5
by: David Longnecker | last post by:
I'm working to create a base framework for our organization for web and client-side applications. The framework interfaces with several of our systems and provides the business and data layer...
22
by: Steve Richter | last post by:
Does the .NET framework provide a class which will find the item in the collection with a key which is closest ( greater than or equal, less than or equal ) to the keys of the collection? ex:...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.