471,306 Members | 1,237 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 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 2050
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Rama S | last post: by
2 posts views Thread by Newbie | last post: by
1 post views Thread by Jiten | last post: by
1 post views Thread by Jiten | last post: by
6 posts views Thread by Matthew Cook | last post: by

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.