Re: Collections challenge (MRU)
- From: "CMM" <cmm@xxxxxxxxxx>
- Date: Fri, 10 Mar 2006 03:40:44 -0500
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]" <notmyfirstname@xxxxxxxxx> wrote in message
news:u7OKsYBRGHA.5924@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxx> schreef in bericht
news:ec$sXNBRGHA.4344@xxxxxxxxxxxxxxxxxxxxxxx
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]" <notmyfirstname@xxxxxxxxx> wrote in message
news:%23wgX56ARGHA.3916@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxx> schreef in bericht
news:OBJmtlARGHA.1728@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxx> wrote in message
news:OYvsC9%23QGHA.5500@xxxxxxxxxxxxxxxxxxxxxxx
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
.
- References:
- Collections challenge (MRU)
- From: CMM
- Re: Collections challenge (MRU)
- From: CMM
- Re: Collections challenge (MRU)
- From: Cor Ligthert [MVP]
- Re: Collections challenge (MRU)
- From: CMM
- Re: Collections challenge (MRU)
- From: Cor Ligthert [MVP]
- Collections challenge (MRU)
- Prev by Date: Re: Defining data types for fields, when you a create a file
- Next by Date: hair cross cursor
- Previous by thread: Re: Collections challenge (MRU)
- Next by thread: Re: Collections challenge (MRU)
- Index(es):