473,406 Members | 2,956 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,406 software developers and data experts.

find the minus Key

Hi,

This is what i would like to do :
I have an Hashtable where all of my Keys are intergers.

The user choose a number, and i want to find the Closest minimal values
of my Keys.

For example :

mys Keys are : 0, 100, 250, 500.

The user enter the value 200, the programme should return 100.
The user enter the value 10, the programme should return 100.
The user enter the value 499, the programme should return 250.

Excuse my english, i hope i could be understand... :)

Thx!

Const.
Jan 11 '06 #1
3 2112
Const <ne**@ampdesign.net> wrote in news:43c579e8$0$31469$79c14f64@nan-
newsreader-07.noos.net:
The user enter the value 200, the programme should return 100.
The user enter the value 10, the programme should return 100.
The user enter the value 499, the programme should return 250.


Unfortunately there is no built-in way to do this... but if you use a
SortedList instead of a Hashtable, then you can iterate through each of the
keys, and once you find a value greater than what you are looking for just
return the previous one.

-mdb
Jan 11 '06 #2
Const <ne**@ampdesign.net> wrote:
This is what i would like to do :
I have an Hashtable where all of my Keys are intergers.

The user choose a number, and i want to find the Closest minimal values
of my Keys.

For example :

mys Keys are : 0, 100, 250, 500.

The user enter the value 200, the programme should return 100.
The user enter the value 10, the programme should return 100.
The user enter the value 499, the programme should return 250.

Excuse my english, i hope i could be understand... :)


Well, you could use a SortedList instead of a Hashtable, and then do a
binary chop to find the nearest value. Otherwise you'll have to go
through all the keys in turn.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 11 '06 #3
Michael Bray a écrit :
Const <ne**@ampdesign.net> wrote in news:43c579e8$0$31469$79c14f64@nan-
newsreader-07.noos.net:

The user enter the value 200, the programme should return 100.
The user enter the value 10, the programme should return 100.
The user enter the value 499, the programme should return 250.

Unfortunately there is no built-in way to do this... but if you use a
SortedList instead of a Hashtable, then you can iterate through each of the
keys, and once you find a value greater than what you are looking for just
return the previous one.

-mdb


I'll try, thanks to you and Jon ! :)
Jan 11 '06 #4

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

Similar topics

1
by: Rama S | last post by:
Hi, We need a query which retrieves option_code, for a plan from OPTION table which are unique in (market, "ALL"). I have an example below PLAN MARKET OPTION_CODE RATE...
2
by: Newbie | last post by:
Hi, Could someone please tell how MINUS operator works for comparing and giving non-matching records in Table1? Does MINUS operator compares all records of Table1 with all records of Table2 to...
1
by: Jiten | last post by:
Hi I have run a stored proc against a database to retrieve a list of date values. What i wanted to do is to add the values returned to an arraylist if the value is not null. here is a small...
1
by: Jiten | last post by:
Hi I have run a stored proc against a database to retrieve a list of date values. What i wanted to do is to add the values returned to an arraylist if the value is not null. here is a small...
6
by: Matthew Cook | last post by:
I would like to overload the unary minus operator so that I can negate an instance of a class and pass that instance to a function without creating an explicit temporary variable. Here is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.