Home All Groups Group Topic Archive Search About

Collections challenge (MRU)

Author
10 Mar 2006 3:03 AM
CMM
First let me say that maybe I'm having a "duh" moment and perhaps I'm
missing something... but it seems to me that no one thing in the
System.Collections namespace (even in .NET 2.0) even comes close to the
still-useful-today VB intrinsic Collection. Here's the challenge (I know I'm
totally missing something here)....

Implement a full featured MRU (Most Recently Used) list using
System.Collections.

Use Case:
1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
sometime between step 1and2
3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*

Requirements:

1) Items must be stored in their original case, but searches on the
collection must be case-insensitive. No storing items using ToLower()
cheating crap to work around the framework's case-sensitive collections.

2) Items must be stored oldest to newest (or newest to oldest... it doesn't
really matter).

3) When adding a new item (case preserved), a matching item (case
insensitive) already in the collection gets popped out.
Well, Dictionary(Of String) seems to be the answer.... as the default
comparator for Key is case-insensitive...
MRUDictionary.Remove(file) <-- case insensitive
MRUDictionary.Add(file, file) <-- new case preserved

BUT...

4) The collection should allow access by index AND it must be "trimmable."
Sub TrimMRU()
    If MRU.Count > 10 Then
        Dim delta As Integer = MRU.Count - 10
        For tally As Integer = 1 To delta
            MRU.RemoveAt(0) '<-- oldest items removed
        Next tally
    End If
End Sub
Dictionary does not support this. You cannot access items "by index."

Anyone have an answer? This is easily done using "Collection"...... but is
there no "framework" equivalent without doing a lot of "kludgy" code?

--
-C. Moya
www.cmoya.com

Author
10 Mar 2006 6:11 AM
CMM
Oh and the collection must be serializable (like, able to be stored in
My.Settings).

Since the original post, I decided to just "forget about it" and go with the
intrinsic VB Collection object... only to find that it's not serializable...
so the values can't be stored in My.Settings. Sure, I can write an algorithm
to convert it... but, I'm looking for an easy non-kludgy solution.

--
-C. Moya
www.cmoya.com
Show quoteHide quote
"CMM" <cmm@nospam.com> wrote in message
news:OYvsC9%23QGHA.5500@TK2MSFTNGP12.phx.gbl...
> First let me say that maybe I'm having a "duh" moment and perhaps I'm
> missing something... but it seems to me that no one thing in the
> System.Collections namespace (even in .NET 2.0) even comes close to the
> still-useful-today VB intrinsic Collection. Here's the challenge (I know
> I'm totally missing something here)....
>
> Implement a full featured MRU (Most Recently Used) list using
> System.Collections.
>
> Use Case:
> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
> 2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
> sometime between step 1and2
> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>
> Requirements:
>
> 1) Items must be stored in their original case, but searches on the
> collection must be case-insensitive. No storing items using ToLower()
> cheating crap to work around the framework's case-sensitive collections.
>
> 2) Items must be stored oldest to newest (or newest to oldest... it
> doesn't really matter).
>
> 3) When adding a new item (case preserved), a matching item (case
> insensitive) already in the collection gets popped out.
> Well, Dictionary(Of String) seems to be the answer.... as the default
> comparator for Key is case-insensitive...
> MRUDictionary.Remove(file) <-- case insensitive
> MRUDictionary.Add(file, file) <-- new case preserved
>
> BUT...
>
> 4) The collection should allow access by index AND it must be "trimmable."
> Sub TrimMRU()
>    If MRU.Count > 10 Then
>        Dim delta As Integer = MRU.Count - 10
>        For tally As Integer = 1 To delta
>            MRU.RemoveAt(0) '<-- oldest items removed
>        Next tally
>    End If
> End Sub
> Dictionary does not support this. You cannot access items "by index."
>
> Anyone have an answer? This is easily done using "Collection"...... but is
> there no "framework" equivalent without doing a lot of "kludgy" code?
>
> --
> -C. Moya
> www.cmoya.com
>
Author
10 Mar 2006 6:50 AM
Cor Ligthert [MVP]
Carlos,

Even Herfried agrees that the old VB collection should have been placed in
the VB compatible namespace instead in the normal VB namespace. It should
not been used. It is so much different from any other collection in Net
(which AFAIK implements all ICollection) that it is embarrassing that the
names are kept the same.

Just my thought,

Cor

Show quoteHide quote
"CMM" <cmm@nospam.com> schreef in bericht
news:OBJmtlARGHA.1728@TK2MSFTNGP11.phx.gbl...
> Oh and the collection must be serializable (like, able to be stored in
> My.Settings).
>
> Since the original post, I decided to just "forget about it" and go with
> the intrinsic VB Collection object... only to find that it's not
> serializable... so the values can't be stored in My.Settings. Sure, I can
> write an algorithm to convert it... but, I'm looking for an easy
> non-kludgy solution.
>
> --
> -C. Moya
> www.cmoya.com
> "CMM" <cmm@nospam.com> wrote in message
> news:OYvsC9%23QGHA.5500@TK2MSFTNGP12.phx.gbl...
>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>> missing something... but it seems to me that no one thing in the
>> System.Collections namespace (even in .NET 2.0) even comes close to the
>> still-useful-today VB intrinsic Collection. Here's the challenge (I know
>> I'm totally missing something here)....
>>
>> Implement a full featured MRU (Most Recently Used) list using
>> System.Collections.
>>
>> Use Case:
>> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
>> 2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
>> sometime between step 1and2
>> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>>
>> Requirements:
>>
>> 1) Items must be stored in their original case, but searches on the
>> collection must be case-insensitive. No storing items using ToLower()
>> cheating crap to work around the framework's case-sensitive collections.
>>
>> 2) Items must be stored oldest to newest (or newest to oldest... it
>> doesn't really matter).
>>
>> 3) When adding a new item (case preserved), a matching item (case
>> insensitive) already in the collection gets popped out.
>> Well, Dictionary(Of String) seems to be the answer.... as the default
>> comparator for Key is case-insensitive...
>> MRUDictionary.Remove(file) <-- case insensitive
>> MRUDictionary.Add(file, file) <-- new case preserved
>>
>> BUT...
>>
>> 4) The collection should allow access by index AND it must be
>> "trimmable."
>> Sub TrimMRU()
>>    If MRU.Count > 10 Then
>>        Dim delta As Integer = MRU.Count - 10
>>        For tally As Integer = 1 To delta
>>            MRU.RemoveAt(0) '<-- oldest items removed
>>        Next tally
>>    End If
>> End Sub
>> Dictionary does not support this. You cannot access items "by index."
>>
>> Anyone have an answer? This is easily done using "Collection"...... but
>> is there no "framework" equivalent without doing a lot of "kludgy" code?
>>
>> --
>> -C. Moya
>> www.cmoya.com
>>
>
>
Author
10 Mar 2006 7:21 AM
CMM
How so? I would agree if there was an alternative with all the same
features. So far, from what I have seen, there is NOT ONE framework-based
collection that does what VB-Collection does... as it is a hybrid of
Dictionary and List. Dictionary does not maintain FIFO order... and List is
not Keyed.

Maybe I'm missing something? :-)

Hey Cor... hotshot... solve the MRU problem. ;-)

--
-C. Moya
www.cmoya.com
Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23wgX56ARGHA.3916@TK2MSFTNGP11.phx.gbl...
> Carlos,
>
> Even Herfried agrees that the old VB collection should have been placed in
> the VB compatible namespace instead in the normal VB namespace. It should
> not been used. It is so much different from any other collection in Net
> (which AFAIK implements all ICollection) that it is embarrassing that the
> names are kept the same.
>
> Just my thought,
>
> Cor
>
> "CMM" <cmm@nospam.com> schreef in bericht
> news:OBJmtlARGHA.1728@TK2MSFTNGP11.phx.gbl...
>> Oh and the collection must be serializable (like, able to be stored in
>> My.Settings).
>>
>> Since the original post, I decided to just "forget about it" and go with
>> the intrinsic VB Collection object... only to find that it's not
>> serializable... so the values can't be stored in My.Settings. Sure, I can
>> write an algorithm to convert it... but, I'm looking for an easy
>> non-kludgy solution.
>>
>> --
>> -C. Moya
>> www.cmoya.com
>> "CMM" <cmm@nospam.com> wrote in message
>> news:OYvsC9%23QGHA.5500@TK2MSFTNGP12.phx.gbl...
>>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>>> missing something... but it seems to me that no one thing in the
>>> System.Collections namespace (even in .NET 2.0) even comes close to the
>>> still-useful-today VB intrinsic Collection. Here's the challenge (I know
>>> I'm totally missing something here)....
>>>
>>> Implement a full featured MRU (Most Recently Used) list using
>>> System.Collections.
>>>
>>> Use Case:
>>> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
>>> 2) User opens "myspreadsheet1.txt" (note the case... the file was
>>> renamed sometime between step 1and2
>>> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>>>
>>> Requirements:
>>>
>>> 1) Items must be stored in their original case, but searches on the
>>> collection must be case-insensitive. No storing items using ToLower()
>>> cheating crap to work around the framework's case-sensitive collections.
>>>
>>> 2) Items must be stored oldest to newest (or newest to oldest... it
>>> doesn't really matter).
>>>
>>> 3) When adding a new item (case preserved), a matching item (case
>>> insensitive) already in the collection gets popped out.
>>> Well, Dictionary(Of String) seems to be the answer.... as the default
>>> comparator for Key is case-insensitive...
>>> MRUDictionary.Remove(file) <-- case insensitive
>>> MRUDictionary.Add(file, file) <-- new case preserved
>>>
>>> BUT...
>>>
>>> 4) The collection should allow access by index AND it must be
>>> "trimmable."
>>> Sub TrimMRU()
>>>    If MRU.Count > 10 Then
>>>        Dim delta As Integer = MRU.Count - 10
>>>        For tally As Integer = 1 To delta
>>>            MRU.RemoveAt(0) '<-- oldest items removed
>>>        Next tally
>>>    End If
>>> End Sub
>>> Dictionary does not support this. You cannot access items "by index."
>>>
>>> Anyone have an answer? This is easily done using "Collection"...... but
>>> is there no "framework" equivalent without doing a lot of "kludgy" code?
>>>
>>> --
>>> -C. Moya
>>> www.cmoya.com
>>>
>>
>>
>
>
Author
10 Mar 2006 7:44 AM
Cor Ligthert [MVP]
Carlos,

I have not your problem complete in mind, however are you sure that the
SortedList does not solve your problem. In your text is so much that is as
well written in the description for this class. (I never have used it yet)
You have an overloaded amount of questions so maybe can you do that with
that class by inheriting it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionssortedlistclasstopic.asp

Although your problem is majory sounds in my opinion a stack do I believe
that you cannot use that or you should add very much to it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsstackclasstopic.asp


I hope this helps something,

Cor

Show quoteHide quote
"CMM" <cmm@nospam.com> schreef in bericht
news:ec$sXNBRGHA.4344@TK2MSFTNGP12.phx.gbl...
> How so? I would agree if there was an alternative with all the same
> features. So far, from what I have seen, there is NOT ONE framework-based
> collection that does what VB-Collection does... as it is a hybrid of
> Dictionary and List. Dictionary does not maintain FIFO order... and List
> is not Keyed.
>
> Maybe I'm missing something? :-)
>
> Hey Cor... hotshot... solve the MRU problem. ;-)
>
> --
> -C. Moya
> www.cmoya.com
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:%23wgX56ARGHA.3916@TK2MSFTNGP11.phx.gbl...
>> Carlos,
>>
>> Even Herfried agrees that the old VB collection should have been placed
>> in the VB compatible namespace instead in the normal VB namespace. It
>> should not been used. It is so much different from any other collection
>> in Net (which AFAIK implements all ICollection) that it is embarrassing
>> that the names are kept the same.
>>
>> Just my thought,
>>
>> Cor
>>
>> "CMM" <cmm@nospam.com> schreef in bericht
>> news:OBJmtlARGHA.1728@TK2MSFTNGP11.phx.gbl...
>>> Oh and the collection must be serializable (like, able to be stored in
>>> My.Settings).
>>>
>>> Since the original post, I decided to just "forget about it" and go with
>>> the intrinsic VB Collection object... only to find that it's not
>>> serializable... so the values can't be stored in My.Settings. Sure, I
>>> can write an algorithm to convert it... but, I'm looking for an easy
>>> non-kludgy solution.
>>>
>>> --
>>> -C. Moya
>>> www.cmoya.com
>>> "CMM" <cmm@nospam.com> wrote in message
>>> news:OYvsC9%23QGHA.5500@TK2MSFTNGP12.phx.gbl...
>>>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>>>> missing something... but it seems to me that no one thing in the
>>>> System.Collections namespace (even in .NET 2.0) even comes close to the
>>>> still-useful-today VB intrinsic Collection. Here's the challenge (I
>>>> know I'm totally missing something here)....
>>>>
>>>> Implement a full featured MRU (Most Recently Used) list using
>>>> System.Collections.
>>>>
>>>> Use Case:
>>>> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
>>>> 2) User opens "myspreadsheet1.txt" (note the case... the file was
>>>> renamed sometime between step 1and2
>>>> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>>>>
>>>> Requirements:
>>>>
>>>> 1) Items must be stored in their original case, but searches on the
>>>> collection must be case-insensitive. No storing items using ToLower()
>>>> cheating crap to work around the framework's case-sensitive
>>>> collections.
>>>>
>>>> 2) Items must be stored oldest to newest (or newest to oldest... it
>>>> doesn't really matter).
>>>>
>>>> 3) When adding a new item (case preserved), a matching item (case
>>>> insensitive) already in the collection gets popped out.
>>>> Well, Dictionary(Of String) seems to be the answer.... as the default
>>>> comparator for Key is case-insensitive...
>>>> MRUDictionary.Remove(file) <-- case insensitive
>>>> MRUDictionary.Add(file, file) <-- new case preserved
>>>>
>>>> BUT...
>>>>
>>>> 4) The collection should allow access by index AND it must be
>>>> "trimmable."
>>>> Sub TrimMRU()
>>>>    If MRU.Count > 10 Then
>>>>        Dim delta As Integer = MRU.Count - 10
>>>>        For tally As Integer = 1 To delta
>>>>            MRU.RemoveAt(0) '<-- oldest items removed
>>>>        Next tally
>>>>    End If
>>>> End Sub
>>>> Dictionary does not support this. You cannot access items "by index."
>>>>
>>>> Anyone have an answer? This is easily done using "Collection"...... but
>>>> is there no "framework" equivalent without doing a lot of "kludgy"
>>>> code?
>>>>
>>>> --
>>>> -C. Moya
>>>> www.cmoya.com
>>>>
>>>
>>>
>>
>>
>
>
Author
10 Mar 2006 8:28 AM
CMM
6 years later and the Framework still falls short of stuff that was so easy
in VB.Classic.

SortedList: Definately not. FIFO order is not maintained.
Stack: Doesn't provide a way to remove duplicate values. Aside from
Contains() being case-sensitive, you still have NO way to pop out a
duplicate that's in the middle of the stack (AFAIK).

Come on... MRU is a simple concept. While my original post was detailed...
it's essentially very simple. Simply study how the Visual Studio MRU list in
the File menu works... or in any app for that matter. Traditionally you
accomplish it via either a lot of brute force array work... or slightly
easiser using VB-Collection.

You SHOULD be able to EASILY accomplish it using at least one of the
collections in .NET but their case-sensitivity (I HATE THAT... not all
collections provide an IComparer option in their constructor) and lack of
indexes makes it extremely difficult.

--
-C. Moya
www.cmoya.com
Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:u7OKsYBRGHA.5924@TK2MSFTNGP09.phx.gbl...
> Carlos,
>
> I have not your problem complete in mind, however are you sure that the
> SortedList does not solve your problem. In your text is so much that is as
> well written in the description for this class. (I never have used it yet)
> You have an overloaded amount of questions so maybe can you do that with
> that class by inheriting it.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionssortedlistclasstopic.asp
>
> Although your problem is majory sounds in my opinion a stack do I believe
> that you cannot use that or you should add very much to it.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsstackclasstopic.asp
>
>
> I hope this helps something,
>
> Cor
>
> "CMM" <cmm@nospam.com> schreef in bericht
> news:ec$sXNBRGHA.4344@TK2MSFTNGP12.phx.gbl...
>> How so? I would agree if there was an alternative with all the same
>> features. So far, from what I have seen, there is NOT ONE framework-based
>> collection that does what VB-Collection does... as it is a hybrid of
>> Dictionary and List. Dictionary does not maintain FIFO order... and List
>> is not Keyed.
>>
>> Maybe I'm missing something? :-)
>>
>> Hey Cor... hotshot... solve the MRU problem. ;-)
>>
>> --
>> -C. Moya
>> www.cmoya.com
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
>> news:%23wgX56ARGHA.3916@TK2MSFTNGP11.phx.gbl...
>>> Carlos,
>>>
>>> Even Herfried agrees that the old VB collection should have been placed
>>> in the VB compatible namespace instead in the normal VB namespace. It
>>> should not been used. It is so much different from any other collection
>>> in Net (which AFAIK implements all ICollection) that it is embarrassing
>>> that the names are kept the same.
>>>
>>> Just my thought,
>>>
>>> Cor
>>>
>>> "CMM" <cmm@nospam.com> schreef in bericht
>>> news:OBJmtlARGHA.1728@TK2MSFTNGP11.phx.gbl...
>>>> Oh and the collection must be serializable (like, able to be stored in
>>>> My.Settings).
>>>>
>>>> Since the original post, I decided to just "forget about it" and go
>>>> with the intrinsic VB Collection object... only to find that it's not
>>>> serializable... so the values can't be stored in My.Settings. Sure, I
>>>> can write an algorithm to convert it... but, I'm looking for an easy
>>>> non-kludgy solution.
>>>>
>>>> --
>>>> -C. Moya
>>>> www.cmoya.com
>>>> "CMM" <cmm@nospam.com> wrote in message
>>>> news:OYvsC9%23QGHA.5500@TK2MSFTNGP12.phx.gbl...
>>>>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>>>>> missing something... but it seems to me that no one thing in the
>>>>> System.Collections namespace (even in .NET 2.0) even comes close to
>>>>> the still-useful-today VB intrinsic Collection. Here's the challenge
>>>>> (I know I'm totally missing something here)....
>>>>>
>>>>> Implement a full featured MRU (Most Recently Used) list using
>>>>> System.Collections.
>>>>>
>>>>> Use Case:
>>>>> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
>>>>> 2) User opens "myspreadsheet1.txt" (note the case... the file was
>>>>> renamed sometime between step 1and2
>>>>> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>>>>>
>>>>> Requirements:
>>>>>
>>>>> 1) Items must be stored in their original case, but searches on the
>>>>> collection must be case-insensitive. No storing items using ToLower()
>>>>> cheating crap to work around the framework's case-sensitive
>>>>> collections.
>>>>>
>>>>> 2) Items must be stored oldest to newest (or newest to oldest... it
>>>>> doesn't really matter).
>>>>>
>>>>> 3) When adding a new item (case preserved), a matching item (case
>>>>> insensitive) already in the collection gets popped out.
>>>>> Well, Dictionary(Of String) seems to be the answer.... as the default
>>>>> comparator for Key is case-insensitive...
>>>>> MRUDictionary.Remove(file) <-- case insensitive
>>>>> MRUDictionary.Add(file, file) <-- new case preserved
>>>>>
>>>>> BUT...
>>>>>
>>>>> 4) The collection should allow access by index AND it must be
>>>>> "trimmable."
>>>>> Sub TrimMRU()
>>>>>    If MRU.Count > 10 Then
>>>>>        Dim delta As Integer = MRU.Count - 10
>>>>>        For tally As Integer = 1 To delta
>>>>>            MRU.RemoveAt(0) '<-- oldest items removed
>>>>>        Next tally
>>>>>    End If
>>>>> End Sub
>>>>> Dictionary does not support this. You cannot access items "by index."
>>>>>
>>>>> Anyone have an answer? This is easily done using "Collection"......
>>>>> but is there no "framework" equivalent without doing a lot of "kludgy"
>>>>> code?
>>>>>
>>>>> --
>>>>> -C. Moya
>>>>> www.cmoya.com
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
10 Mar 2006 8:40 AM
CMM
Or to make it even simpler

MRU.Push("Newsgroup")
MRU.Push("Carlos")
MRU.Push("Cor")
MRU.Push("carlos")
=
Newsgroup
Cor
carlos

It MUST work this way. None of that "Why don't you call ToLower before you
add the string?" crap.

At first glance List(Of String) might work.
List.Remove(s)
List.Add(s)
Aaargh case-sensitivity breaks it!!! (i.e. "carlos" does not trump
"Carlos".)

Well, how about one of the dictionaries?
Dictionary.Remove(s)
Dictionary.Add(s, s)
That works!!!! ... because the key in a dictionary is case insensitive.
But now, what if you want to trim the list? Call RemoveAt(0) n-times?
There's no way. There's no "index" access to a Dictionary.



--
-C. Moya
www.cmoya.com
Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:u7OKsYBRGHA.5924@TK2MSFTNGP09.phx.gbl...
> Carlos,
>
> I have not your problem complete in mind, however are you sure that the
> SortedList does not solve your problem. In your text is so much that is as
> well written in the description for this class. (I never have used it yet)
> You have an overloaded amount of questions so maybe can you do that with
> that class by inheriting it.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionssortedlistclasstopic.asp
>
> Although your problem is majory sounds in my opinion a stack do I believe
> that you cannot use that or you should add very much to it.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsstackclasstopic.asp
>
>
> I hope this helps something,
>
> Cor
>
> "CMM" <cmm@nospam.com> schreef in bericht
> news:ec$sXNBRGHA.4344@TK2MSFTNGP12.phx.gbl...
>> How so? I would agree if there was an alternative with all the same
>> features. So far, from what I have seen, there is NOT ONE framework-based
>> collection that does what VB-Collection does... as it is a hybrid of
>> Dictionary and List. Dictionary does not maintain FIFO order... and List
>> is not Keyed.
>>
>> Maybe I'm missing something? :-)
>>
>> Hey Cor... hotshot... solve the MRU problem. ;-)
>>
>> --
>> -C. Moya
>> www.cmoya.com
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
>> news:%23wgX56ARGHA.3916@TK2MSFTNGP11.phx.gbl...
>>> Carlos,
>>>
>>> Even Herfried agrees that the old VB collection should have been placed
>>> in the VB compatible namespace instead in the normal VB namespace. It
>>> should not been used. It is so much different from any other collection
>>> in Net (which AFAIK implements all ICollection) that it is embarrassing
>>> that the names are kept the same.
>>>
>>> Just my thought,
>>>
>>> Cor
>>>
>>> "CMM" <cmm@nospam.com> schreef in bericht
>>> news:OBJmtlARGHA.1728@TK2MSFTNGP11.phx.gbl...
>>>> Oh and the collection must be serializable (like, able to be stored in
>>>> My.Settings).
>>>>
>>>> Since the original post, I decided to just "forget about it" and go
>>>> with the intrinsic VB Collection object... only to find that it's not
>>>> serializable... so the values can't be stored in My.Settings. Sure, I
>>>> can write an algorithm to convert it... but, I'm looking for an easy
>>>> non-kludgy solution.
>>>>
>>>> --
>>>> -C. Moya
>>>> www.cmoya.com
>>>> "CMM" <cmm@nospam.com> wrote in message
>>>> news:OYvsC9%23QGHA.5500@TK2MSFTNGP12.phx.gbl...
>>>>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>>>>> missing something... but it seems to me that no one thing in the
>>>>> System.Collections namespace (even in .NET 2.0) even comes close to
>>>>> the still-useful-today VB intrinsic Collection. Here's the challenge
>>>>> (I know I'm totally missing something here)....
>>>>>
>>>>> Implement a full featured MRU (Most Recently Used) list using
>>>>> System.Collections.
>>>>>
>>>>> Use Case:
>>>>> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
>>>>> 2) User opens "myspreadsheet1.txt" (note the case... the file was
>>>>> renamed sometime between step 1and2
>>>>> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>>>>>
>>>>> Requirements:
>>>>>
>>>>> 1) Items must be stored in their original case, but searches on the
>>>>> collection must be case-insensitive. No storing items using ToLower()
>>>>> cheating crap to work around the framework's case-sensitive
>>>>> collections.
>>>>>
>>>>> 2) Items must be stored oldest to newest (or newest to oldest... it
>>>>> doesn't really matter).
>>>>>
>>>>> 3) When adding a new item (case preserved), a matching item (case
>>>>> insensitive) already in the collection gets popped out.
>>>>> Well, Dictionary(Of String) seems to be the answer.... as the default
>>>>> comparator for Key is case-insensitive...
>>>>> MRUDictionary.Remove(file) <-- case insensitive
>>>>> MRUDictionary.Add(file, file) <-- new case preserved
>>>>>
>>>>> BUT...
>>>>>
>>>>> 4) The collection should allow access by index AND it must be
>>>>> "trimmable."
>>>>> Sub TrimMRU()
>>>>>    If MRU.Count > 10 Then
>>>>>        Dim delta As Integer = MRU.Count - 10
>>>>>        For tally As Integer = 1 To delta
>>>>>            MRU.RemoveAt(0) '<-- oldest items removed
>>>>>        Next tally
>>>>>    End If
>>>>> End Sub
>>>>> Dictionary does not support this. You cannot access items "by index."
>>>>>
>>>>> Anyone have an answer? This is easily done using "Collection"......
>>>>> but is there no "framework" equivalent without doing a lot of "kludgy"
>>>>> code?
>>>>>
>>>>> --
>>>>> -C. Moya
>>>>> www.cmoya.com
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
10 Mar 2006 10:29 AM
Larry Lard
CMM wrote:
> First let me say that maybe I'm having a "duh" moment and perhaps I'm
> missing something... but it seems to me that no one thing in the
> System.Collections namespace (even in .NET 2.0) even comes close to the
> still-useful-today VB intrinsic Collection. Here's the challenge (I know I'm
> totally missing something here)....
[snip]
> Anyone have an answer? This is easily done using "Collection"...... but is
> there no "framework" equivalent without doing a lot of "kludgy" code?

The framework doesn't claim to have a solution to every problem.
There's nothing stopping you from creating your own collection class
that behaves the way you want it to. I'm sure I can't be the only
person who wrote their own QueueOfT class, pre-2.0. I still use my
DequeueOfT classes, although now of course I have re implemented as
Dequeue(Of T). What I didn't do was rant about the framework not
providing a double ended queue (I mean, isn't this ESSENTIAL??!??!?!!)
for me.

--
Larry Lard
Replies to group please
Author
10 Mar 2006 10:52 AM
CMM
It wasn't a rant. It was a challenge (using System.Collections)...  And MRU
is not an uncommon programming challenge... in fact, the new
TextBox/ComboBox "AutoComplete" features use it. And if any of your apps do
FileNew/Open/Save stuff... so should you.

And there is indeed a simple solution for the rest of us (without writing
oodles of code). The VB intrinsic Collection object. I guess MS didn't put
it in the "Compatibility" namespace graveyard for a reason. That is because
it's still useful.

Its serialization was easy too. Simply loop through it and dump it into a
StringCollection (which is serializable) for "My.Settings" use or anything
else that requires serialization.


--
-C. Moya
www.cmoya.com
Show quoteHide quote
"Larry Lard" <larryl***@hotmail.com> wrote in message
news:1141986546.568521.213080@u72g2000cwu.googlegroups.com...
>
> CMM wrote:
>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>> missing something... but it seems to me that no one thing in the
>> System.Collections namespace (even in .NET 2.0) even comes close to the
>> still-useful-today VB intrinsic Collection. Here's the challenge (I know
>> I'm
>> totally missing something here)....
> [snip]
>> Anyone have an answer? This is easily done using "Collection"...... but
>> is
>> there no "framework" equivalent without doing a lot of "kludgy" code?
>
> The framework doesn't claim to have a solution to every problem.
> There's nothing stopping you from creating your own collection class
> that behaves the way you want it to. I'm sure I can't be the only
> person who wrote their own QueueOfT class, pre-2.0. I still use my
> DequeueOfT classes, although now of course I have re implemented as
> Dequeue(Of T). What I didn't do was rant about the framework not
> providing a double ended queue (I mean, isn't this ESSENTIAL??!??!?!!)
> for me.
>
> --
> Larry Lard
> Replies to group please
>
Author
10 Mar 2006 11:00 AM
CMM
And I would also note, that this would be easy if the Framework collections
made consistent use of IComparer. Some collection types allow it to be
passed in the constructure and some don't. Most notably (and stupidly)
StringCollection does not.... so the nifty CaseInsensitiveComparer sits
there not being used where it is most useful.

Now that IS a rant!

--
-C. Moya
www.cmoya.com
Show quoteHide quote
"CMM" <cmm@nospam.com> wrote in message
news:%23GtLMDDRGHA.4300@TK2MSFTNGP14.phx.gbl...
> It wasn't a rant. It was a challenge (using System.Collections)...  And
> MRU is not an uncommon programming challenge... in fact, the new
> TextBox/ComboBox "AutoComplete" features use it. And if any of your apps
> do FileNew/Open/Save stuff... so should you.
>
> And there is indeed a simple solution for the rest of us (without writing
> oodles of code). The VB intrinsic Collection object. I guess MS didn't put
> it in the "Compatibility" namespace graveyard for a reason. That is
> because it's still useful.
>
> Its serialization was easy too. Simply loop through it and dump it into a
> StringCollection (which is serializable) for "My.Settings" use or anything
> else that requires serialization.
>
>
> --
> -C. Moya
> www.cmoya.com
> "Larry Lard" <larryl***@hotmail.com> wrote in message
> news:1141986546.568521.213080@u72g2000cwu.googlegroups.com...
>>
>> CMM wrote:
>>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>>> missing something... but it seems to me that no one thing in the
>>> System.Collections namespace (even in .NET 2.0) even comes close to the
>>> still-useful-today VB intrinsic Collection. Here's the challenge (I know
>>> I'm
>>> totally missing something here)....
>> [snip]
>>> Anyone have an answer? This is easily done using "Collection"...... but
>>> is
>>> there no "framework" equivalent without doing a lot of "kludgy" code?
>>
>> The framework doesn't claim to have a solution to every problem.
>> There's nothing stopping you from creating your own collection class
>> that behaves the way you want it to. I'm sure I can't be the only
>> person who wrote their own QueueOfT class, pre-2.0. I still use my
>> DequeueOfT classes, although now of course I have re implemented as
>> Dequeue(Of T). What I didn't do was rant about the framework not
>> providing a double ended queue (I mean, isn't this ESSENTIAL??!??!?!!)
>> for me.
>>
>> --
>> Larry Lard
>> Replies to group please
>>
>
>
Author
10 Mar 2006 12:15 PM
Kerry Moorman
CMM,

Would the NameValueCollection (or one that you create from
NameObjectCollectionBase) work for you?

Kerry Moorman


Show quoteHide quote
"CMM" wrote:

> First let me say that maybe I'm having a "duh" moment and perhaps I'm
> missing something... but it seems to me that no one thing in the
> System.Collections namespace (even in .NET 2.0) even comes close to the
> still-useful-today VB intrinsic Collection. Here's the challenge (I know I'm
> totally missing something here)....
>
> Implement a full featured MRU (Most Recently Used) list using
> System.Collections.
>
> Use Case:
> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
> 2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
> sometime between step 1and2
> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>
> Requirements:
>
> 1) Items must be stored in their original case, but searches on the
> collection must be case-insensitive. No storing items using ToLower()
> cheating crap to work around the framework's case-sensitive collections.
>
> 2) Items must be stored oldest to newest (or newest to oldest... it doesn't
> really matter).
>
> 3) When adding a new item (case preserved), a matching item (case
> insensitive) already in the collection gets popped out.
> Well, Dictionary(Of String) seems to be the answer.... as the default
> comparator for Key is case-insensitive...
> MRUDictionary.Remove(file) <-- case insensitive
> MRUDictionary.Add(file, file) <-- new case preserved
>
> BUT...
>
> 4) The collection should allow access by index AND it must be "trimmable."
> Sub TrimMRU()
>     If MRU.Count > 10 Then
>         Dim delta As Integer = MRU.Count - 10
>         For tally As Integer = 1 To delta
>             MRU.RemoveAt(0) '<-- oldest items removed
>         Next tally
>     End If
> End Sub
> Dictionary does not support this. You cannot access items "by index."
>
> Anyone have an answer? This is easily done using "Collection"...... but is
> there no "framework" equivalent without doing a lot of "kludgy" code?
>
> --
> -C. Moya
> www.cmoya.com
>
>
>
Author
10 Mar 2006 12:47 PM
CMM
Actually, I think it might! When I first reviewed it, I dismissed it because
I couldn't see a way of  truncating the collection when necessary (usually
accomplished via RemoveAt(0))
But it is possible with the NameValueCollection using this (somewhat
unintuitive) technique:

col.Remove(col.Keys.Item(0))

I knew I was missing something.

--
-C. Moya
www.cmoya.com
Show quoteHide quote
"Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
news:C91030AE-49C4-422B-A084-5257014E1888@microsoft.com...
> CMM,
>
> Would the NameValueCollection (or one that you create from
> NameObjectCollectionBase) work for you?
>
> Kerry Moorman
>
>
> "CMM" wrote:
>
>> First let me say that maybe I'm having a "duh" moment and perhaps I'm
>> missing something... but it seems to me that no one thing in the
>> System.Collections namespace (even in .NET 2.0) even comes close to the
>> still-useful-today VB intrinsic Collection. Here's the challenge (I know
>> I'm
>> totally missing something here)....
>>
>> Implement a full featured MRU (Most Recently Used) list using
>> System.Collections.
>>
>> Use Case:
>> 1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
>> 2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
>> sometime between step 1and2
>> 3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
>>
>> Requirements:
>>
>> 1) Items must be stored in their original case, but searches on the
>> collection must be case-insensitive. No storing items using ToLower()
>> cheating crap to work around the framework's case-sensitive collections.
>>
>> 2) Items must be stored oldest to newest (or newest to oldest... it
>> doesn't
>> really matter).
>>
>> 3) When adding a new item (case preserved), a matching item (case
>> insensitive) already in the collection gets popped out.
>> Well, Dictionary(Of String) seems to be the answer.... as the default
>> comparator for Key is case-insensitive...
>> MRUDictionary.Remove(file) <-- case insensitive
>> MRUDictionary.Add(file, file) <-- new case preserved
>>
>> BUT...
>>
>> 4) The collection should allow access by index AND it must be
>> "trimmable."
>> Sub TrimMRU()
>>     If MRU.Count > 10 Then
>>         Dim delta As Integer = MRU.Count - 10
>>         For tally As Integer = 1 To delta
>>             MRU.RemoveAt(0) '<-- oldest items removed
>>         Next tally
>>     End If
>> End Sub
>> Dictionary does not support this. You cannot access items "by index."
>>
>> Anyone have an answer? This is easily done using "Collection"...... but
>> is
>> there no "framework" equivalent without doing a lot of "kludgy" code?
>>
>> --
>> -C. Moya
>> www.cmoya.com
>>
>>
>>