DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 22 Aug 2007 06:04:03 -0700,    posted on: microsoft.public.dotnet.framework        back       

Thread Index
  1    Iain
          2    Peter Duniho
                 3    Iain
          4    Peter Duniho
          5    Iain


Finding Close matches in a collection class   
In an appliction I want to store lots of items in memory and locate sets of 
the based on the some starting substring.

If I was doing it in sql, I would use "select * from table where Key like 
'Fred%'

From what I've read the SortedDictionary should be able to do this (as it is 
implemented as a tree), but there seems no way of getting at this 
functionality (or the innards of the thing).

Will any of the collection classes do this?  Are there any other collection 
classes which will do something like this?

(I don't want to use a for each solution as I have to do LOTS of searches on 
LARGE datasets).

THanks for your help

Iain
Date:Wed, 22 Aug 2007 06:04:03 -0700   Author:  

Re: Finding Close matches in a collection class   
Iain wrote:

> In an appliction I want to store lots of items in memory and locate sets of 
> the based on the some starting substring.
> 
> If I was doing it in sql, I would use "select * from table where Key like 
> 'Fred%'
> 
> From what I've read the SortedDictionary should be able to do this (as it is 
> implemented as a tree), but there seems no way of getting at this 
> functionality (or the innards of the thing).
> 
> Will any of the collection classes do this?  Are there any other collection 
> classes which will do something like this?


I'm not aware of any.  You could implement a predicate delegate to use 
with something like the FindAll() method of a collection class like 
SortedDictionary, but that would not be very much different than just 
enumerating the whole collection, since there's no feedback from the 
delegate to help narrow the search.  It's just a binary "is this one or 
isn't it?".

So, I think you'd have to implement your own binary search.

Now, that said, you can at least short-cut the sorting part, as the 
SortedDictionary<> class (as well as some other sorted collection 
classes) has a Values property that returns a collection of the values 
in the collection, in the already-sorted order.  So you only have to 
write the binary search part, which shouldn't be that difficult.

Pete
Date:Wed, 22 Aug 2007 11:11:48 -0700   Author:  

Re: Finding Close matches in a collection class   
"Peter Duniho" wrote:

> I'm not aware of any.  You could implement a predicate delegate to use 
> with something like the FindAll() method of a collection class like 
> SortedDictionary, but that would not be very much different than just 
> enumerating the whole collection, since there's no feedback from the 
> delegate to help narrow the search.  It's just a binary "is this one or 
> isn't it?".
> 
> So, I think you'd have to implement your own binary search.
> 
> Now, that said, you can at least short-cut the sorting part, as the 
> SortedDictionary<> class (as well as some other sorted collection 
> classes) has a Values property that returns a collection of the values 
> in the collection, in the already-sorted order.  So you only have to 
> write the binary search part, which shouldn't be that difficult.
> 

Seems a shame they didn't provide access to the innards of the 
SortedDictionary.

On that (ish), when you access the Values collection on a dictionary, is it 
simply a pointer access or is an array created when the call is made? I've 
not found the documentation clear on that...

Thanks!

Iain
Date:Wed, 22 Aug 2007 13:06:04 -0700   Author:  

Re: Finding Close matches in a collection class   
Iain wrote:

> Seems a shame they didn't provide access to the innards of the 
> SortedDictionary.


Not sure what you mean here.  The point of encapsulation is to _not_ 
"provide access to the innards".  :)  That said, to some extent the 
SortedDictionary.Values property does give you access to the innards.


> On that (ish), when you access the Values collection on a dictionary, is it 
> simply a pointer access or is an array created when the call is made? I've 
> not found the documentation clear on that...


Did you try looking at the documentation for the SortedDictionary.Values 
property?

 From http://msdn2.microsoft.com/en-us/library/zazzsd83.aspx :

     The returned SortedDictionary.ValueCollection is not
     a static copy; instead, the SortedDictionary.ValueCollection
     refers back to the values in the original SortedDictionary.
     Therefore, changes to the SortedDictionary continue to be
     reflected in the SortedDictionary.ValueCollection

Pete
Date:Wed, 22 Aug 2007 13:55:58 -0700   Author:  

Re: Finding Close matches in a collection class   
"Peter Duniho" wrote:


> Iain wrote:
> > Seems a shame they didn't provide access to the innards of the 
> > SortedDictionary.
> 
> Not sure what you mean here.  The point of encapsulation is to _not_ 
> "provide access to the innards".  :)  That said, to some extent the 
> SortedDictionary.Values property does give you access to the innards.


Well, encapsulation is about design decisions.  One design decision would be 
to expose the internal tree structure in a read only fashion (in order to do 
all the things with trees which SortedDictionary doesn't do - prefix sort 
order, post fix sort order, range retrieval and so on).  Doing this would 
provide value but make the dictionary riskier to use (a node could become 
quite separated from the rest of the tree after some operations).  SO the 
choice was the dumbed down version (which, actually, I agree with).  However 
they could have provided a more primitive version with raw access for the 
benefit of those of us who know the risks!

Maybe V3 :) .


> Did you try looking at the documentation for the SortedDictionary.Values 
> property?
> 
>  From http://msdn2.microsoft.com/en-us/library/zazzsd83.aspx :
> 
>      The returned SortedDictionary.ValueCollection is not
>      a static copy; instead, the SortedDictionary.ValueCollection
>      refers back to the values in the original SortedDictionary.
>      Therefore, changes to the SortedDictionary continue to be
>      reflected in the SortedDictionary.ValueCollection
> 

Thanks.  

Iain
Date:Thu, 23 Aug 2007 01:04:11 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us