473,574 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2123
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.co m>
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
5844
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 PLAN1 TEXAS 1000 1 PLAN1 TEXAS 2000 2 PLAN1 ALL 1000 3 PLAN1 ALL 3000 4
2
13835
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 give differences? Say, i've got 2 tables - no keys defined on them. No PK and UK. Now MINUS operator will pick which columns for comparison? Having a...
1
264
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 portion of my code that i am using... Tr MyConn.Open( Dim rdr As SqlDataReade rdr = SPretDate.ExecuteReader(
1
1450
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 portion of my code that i am using... Tr MyConn.Open( Dim rdr As SqlDataReade rdr = SPretDate.ExecuteReader(
6
2581
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 example: #include <iostream> using namespace std; class Object { public:
0
7753
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...
0
8095
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. ...
1
7847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8132
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...
0
6500
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5645
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3769
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...
1
1365
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1096
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.