CodeSmith Community
Your Code. Your Way. Faster!

Current C# Collection Templates [1.6.0]

Latest post 07-01-2004 2:11 PM by cnahr. 6 replies.
  • 01-19-2004 9:34 AM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Current C# Collection Templates [1.6.0]

    Eric,

    New version is up. I'm doing a case-insensitive check for int, integer, int32, and system.int32 -- that catches all C# and VB equivalents of the System.Int32 type.

    I'm getting notifications about private messages but I don't remember ever getting notified of regular forum posts. Maybe I'm just not logged on long enough at a time, though.

    Chris
    • Post Points: 5
  • 01-19-2004 3:50 PM In reply to

    • ejsmith
    • Top 10 Contributor
    • Joined on 12-27-2002
    • Dallas, TX USA
    • Posts 2,207
    • Points 1,053,935

    RE: Current C# Collection Templates [1.6.0]

    Chris,

    Great, I'll update these in the installer.

    Thanks,
    Eric J. Smith

    Eric J. Smith
    CodeSmith Tools, LLC
    Chief Software Architect

    • Post Points: 5
  • 01-20-2004 9:21 AM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Current C# Collection Templates [1.6.0]

    Well, everything seems to work fine so I've edited the two collection template threads as announced and removed the "preliminary" notice. If there are any problems or enhancement requests I'll handle them in a 1.4.2 release.
    • Post Points: 5
  • 01-25-2004 6:52 AM In reply to

    RE: Current C# Collection Templates [1.6.0]

    Chris,
    I notice that in ArrayList class, the ReadOnlyList, SyncList, and UniqueList classes are not overriding the "Contains" and "ContainsKey" functions. Is this an oversight, or am I missing something. (Since the array of the base class is never initialized, these won't work without an override, will they?) Also, ContainsKey is not declared as virtual in the ArrayList class.
    • Post Points: 5
  • 01-25-2004 7:33 AM In reply to

    RE: Current C# Collection Templates [1.6.0]

    Guys,

    I think we're mixing a HashList and an ArrayList in one. I would like to suggest that instead of adding key-based lookups to an ArrayList, we'd consider providing a HashList template implementation.

    Hashlist provides access by key (using internal HashTable), or by Index.
    This would not only address performance issues (instead of O(n)), but also provide uniqueness of keys for lookups, etc.

    Thoughts?
    • Post Points: 5
  • 01-25-2004 9:21 AM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Current C# Collection Templates [1.6.0]

    Bob -- Well spotted!  I did remove the "virtual" keywords and overrides from the Contains and ContainsKey methods in the last update because it was unnecessary.
     
    These methods merely perform a single call to another method (IndexOf/IndexOfKey) which is virtual & overriden, so the additional virtualization was just a waste of time.
     
    This is the same reason why the various explicit interface implementations aren't virtual and overriden, by the way -- like Contains/ContainsKey, they merely forward to other methods.
    • Post Points: 5
  • 01-25-2004 9:32 AM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Current C# Collection Templates [1.6.0]

    Yaron -- I'm afraid you're a bit late since we're already done adding key lookup to the ArrayList. :-)
     
    Moreover, I don't quite see your point.  Templates with fast key lookup and unique keys are already available in the collection package, namely Hashtable and SortedList.  The latter provides access by key as well as by index.
     
    The ArrayList key lookup was deliberately designed to have no impact on its existing functionality and performance.  We don't need the extra data structures for a hashing algorithm, and we can insert multiple items with identical keys.
     
    Lastly, while I don't know your situation I found that most of the collections I'm using have maybe 5-20 elements, and in that range an unsorted collection with linear searching is absolutely sufficient.  Fast searching for large N comes with a huge overhead at small N (Hashtable) or when inserting elements (SortedList).
     
    Just get a .NET decompiler like Reflector and look at Microsoft's hashtable implementation -- you'll be surprised how much auxiliary data it needs, and how many instructions have to be executed before anything is found.
    • Post Points: 5
  • 02-03-2004 6:08 AM In reply to

    • Joost
    • Not Ranked
    • Joined on 09-07-2003
    • Netherlands
    • Posts 3
    • Points 15

    RE: Current C# Collection Templates [1.6.0]

     
    Chris Nahr said...
    (What's new in version 1.4.1: I've added a "unique" wrapper to the ArrayList template, as requested by Eric.
     
    The wrapper is based on an idea posted by Joost in this forum but my implementation is somewhat different. It's strictly analogous to the standard wrappers (sync, read-only) in that there's only one property (IsUnique) and one method (Unique) that are specific to the new wrapper. Any operations that the wrapper doesn't like (adding duplicate elements) causes a documented NotSupportedException in the existing methods.)
     
     
    Did i actually have a good idea? smilewinkgrin
    Thanks Chris!!
     
    I agree your implementation is the way to go. I had included the methods AddUnique and InsertUnique in the base collection to insert a single unique item without using the wrapper. The unique wrapper class used those methods to disallow duplicates.


    • Post Points: 5
  • 03-01-2004 7:41 AM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Current C# Collection Templates [1.6.0]

    What's new in version 1.5.0:
     
    Added template file Queue.cst
    Added DeepCopy and DeepCopyItem properties to class templates
    Moved ItemValueType and KeyValueType to Context group
    Moved common script methods to separate file CommonScript.cs
    DictionaryList, SortedList: Clone duplicates synchronized wrappers
    DictionaryList, SortedList: Devirtualized Contains… methods
    Hashtable: Added ReadOnly wrapper, fixed CopyTo method
    Stack: Pop correctly clears reference to deleted element
     
    A more complete explanation of these changes can be found on my website, http://www.kynosarges.de/TemplatesNews.html
    • Post Points: 5
  • 05-13-2004 2:10 PM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Current C# Collection Templates [1.6.0]

    What's new in version 1.5.1:

    The CopyTo methods of all templates accept empty target arrays if the collection itself is empty and the target array index is zero, as requested by Kyle Blaney.
    • Post Points: 5
  • 07-01-2004 2:11 PM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Current C# Collection Templates [1.6.0]

    What's new in version 1.6.0: Many things, including some breaking changes!
     
    Please review the change log in the ReadMe file and on my website for details:
     
    Also note that the complete unit testing & benchmark suite is now available for download from the C# Templates home page:
     
    (I cannot upload them here because it's a 295 KB file.)

    Post Edited (Chris Nahr) : 7/1/2004 4:07:45 PM GMT

    • Post Points: 5
Page 2 of 2 (26 items) < Previous 1 2 | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems