473,493 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Searching in SortedList

Hi,
I would like to use a SortedList collection to store numeric data items with
a key (numeric location). When I have a key which is not stored in the
SortedList and which should not be stored but I just want to know at which
index location it would be stored according the sort order. If I would be
able to get the noughbours of this key in the List I could do an
interpolation with the neighbour items to calculate the values for the this
key.
Of course I could Add the new key and find at which index it is stored and
delete it afterwards, but this is not very nice and efficiency.

Can anybody help?

Georg
Mar 8 '06 #1
2 1865
Georg,

Instead of using a SortedList, I would use an array, or an ArrayList
which you keep sorted (when you insert new items). Then, you can do a
binary search on the array/arraylist to find the appropriate place in the
array/arraylist where an item would be inserted.

You can then map the elements of the array to whatever other data you
have in a hashtable or dictionary.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Georg" <GJ@PlasserTheurer.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
I would like to use a SortedList collection to store numeric data items
with a key (numeric location). When I have a key which is not stored in
the SortedList and which should not be stored but I just want to know at
which index location it would be stored according the sort order. If I
would be able to get the noughbours of this key in the List I could do an
interpolation with the neighbour items to calculate the values for the
this key.
Of course I could Add the new key and find at which index it is stored and
delete it afterwards, but this is not very nice and efficiency.

Can anybody help?

Georg

Mar 8 '06 #2


Georg wrote:
Of course I could Add the new key and find at which index it is stored and
delete it afterwards, but this is not very nice and efficiency.
If you aren't iterating the list this may well be the easiest solution.
whether it is efficient *enough*, I would let user-experience decide, or
maybe a profiler.

The usual solution is for IndexOf to return ~i if the object looked for
should have been at position i, but wasn't, but unfortunatly SortedList
doesn't do that. System.Array.BinarySearch does this -- so much for
consistency in the collections in C#1 :)
Can anybody help?


You can do the binary search yourself. If you search for some
example-code, this operation is called lower_bound in c++
standard-library terms.

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Mar 9 '06 #3

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

Similar topics

1
20493
by: gerrod | last post by:
Hi - Does anyone know a way to created a SortedList (in the System.Collections namespace) that will sort on VALUES instead of KEYS... ? The scenario is this - I have a SortedList containing...
6
1859
by: Jose Jarabo | last post by:
Hello, thanks in advance for any and all replies. I am not sure how to categorize this, either a bug or something else but here is my problem. I am testing with 2 elements on a sorted list. If...
2
3064
by: Pekka | last post by:
Could somebody say why the piece of code below does not work? My purpose is to renumber keys in a SortedList (after removal of an item) so that the keys would always contain an unbroken sequence of...
2
1481
by: KrippZ | last post by:
Hello I'm having some problems with a a sortedList in C#. My set is as follows: I have a sortedList as a class variable (DataList) I inisiate it in my constructor with DataList = new SortedList()....
2
2025
by: Prez | last post by:
I started writing .net code yesterday and I am grasping it well enough. I have a few questions about SortedLists. I am using managed C++ if that makes any difference. Of the examples I...
4
10104
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
4
5053
by: aeshiels | last post by:
Hello, I have a SortedList defined as... SortedList<CUser, CUseruserList = new SortedList<CUser, CUser>(); ....and which to copy it to another sorted list SortedList<CUser,...
1
3885
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash:...
6
2490
by: n3tx | last post by:
Hi! I have a problem with sortedlist, i guess i dont understand how it works. I have a method called GetPublishingPlaces that returns an IList<PublishingPlace> (ex. contains 11 rows) I want...
0
6989
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...
0
7157
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
7367
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
5453
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,...
1
4889
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...
0
4579
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
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 ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.