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 11 1646
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" <cm*@nospam.com> wrote in message
news:OY****************@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
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" <cm*@nospam.com> schreef in bericht
news:OB**************@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" <cm*@nospam.com> wrote in message news:OY****************@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
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]" <no************@planet.nl> wrote in message
news:%2****************@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" <cm*@nospam.com> schreef in bericht news:OB**************@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" <cm*@nospam.com> wrote in message news:OY****************@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
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/de...classtopic.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/de...classtopic.asp
I hope this helps something,
Cor
"CMM" <cm*@nospam.com> schreef in bericht
news:ec**************@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]" <no************@planet.nl> wrote in message news:%2****************@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" <cm*@nospam.com> schreef in bericht news:OB**************@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" <cm*@nospam.com> wrote in message news:OY****************@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
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
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:u7**************@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/de...classtopic.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/de...classtopic.asp
I hope this helps something,
Cor
"CMM" <cm*@nospam.com> schreef in bericht news:ec**************@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]" <no************@planet.nl> wrote in message news:%2****************@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" <cm*@nospam.com> schreef in bericht news:OB**************@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" <cm*@nospam.com> wrote in message news:OY****************@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 >
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
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:u7**************@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/de...classtopic.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/de...classtopic.asp
I hope this helps something,
Cor
"CMM" <cm*@nospam.com> schreef in bericht news:ec**************@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]" <no************@planet.nl> wrote in message news:%2****************@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" <cm*@nospam.com> schreef in bericht news:OB**************@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" <cm*@nospam.com> wrote in message news:OY****************@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 >
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
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" <la*******@hotmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.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
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
"CMM" <cm*@nospam.com> wrote in message
news:%2****************@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" <la*******@hotmail.com> wrote in message news:11**********************@u72g2000cwu.googlegr oups.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
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
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
"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nathan Sokalski |
last post by:
I am using the Folder.Files collection to display all the images in a given
directory. The following shows the code I use to create and use this
collection:
Set...
|
by: Frank Buss |
last post by:
A new challenge:
http://www.frank-buss.de/marsrescue/index.html
Have fun! Now you can win real prices.
--
Frank Buß, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
|
by: Paige W. |
last post by:
I have added a mainmenu object to my windows form and would like to
display an MRU list on it. Is there an easy way? or do I have to do
it programatically? Can anyone point me to a good tutorial....
|
by: Richard D. Ford |
last post by:
Does anyone know how I can get an MRU File List to work for a MainMenu in VB
..NET 2003?
-Rick Ford.
|
by: Richard Jones |
last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March
to Sunday 2nd April (00:00UTC to 00:00UTC).
The PyWeek challenge invites entrants to write a game in one week from...
|
by: richard |
last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March
to Sunday 2nd April (00:00UTC to 00:00UTC).
The PyWeek challenge invites entrants to write a game in one week from...
|
by: Hexman |
last post by:
Hello all,
I want to remove some (not all) projects from the mru list. Where is it stored so I can edit it or is there a way to selectively remove an entry?
Thanks,
Hexman
|
by: Thierry |
last post by:
For those interested in <b>programming riddles</b>, I would like to
announce a new programming challenge I'm just launching at
http://software.challenge.googlepages.com
This challenge is in its...
|
by: Richard Jones |
last post by:
The fifth PyWeek is only a month away. Come along and join the fun: write a
video game in a week!
There's some really interesting new libraries that have popped up recently.
Have a gander on the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |