Collection library

Discussion in 'Additional Libraries' started by agraham, Jan 30, 2008.

  1. agraham

    agraham Expert Licensed User

    I've had this library lying around waiting for a help file for some time, so I've decided to get it done and out of the way.

    The .NET platform implements several useful collection classes of which only ArrayList is included with Basic4PPC. This library adds some others, Stack, Queue, Hashtable and SortedList, that are very useful in some circumstances.

    It requires .NET 2.0 and will run on both desktop and device. See the help file for further details.

    EDIT : Source code for merging dll posted. Put it in the Basic4pp Desktop\Libraries folder.

    EDIT:- Version 1.2 posted with enhanced array and ArrayList functions. Help, demos, library and source for merging are in the zip. See post #6 for details.

    EDIT:- Version 1.3 posted with all the objects renamed with an 'Ex' suffix to avoid name clashes with Basic4ppc version 6.80 which implements Stack and Hashtable internally. See post #8 for further details.

    EDIT:- Version 1.4 posted with culture sorting options added. See post #14 for details.

    EDIT:- Version 1.5 posted with changes to suit Basic4ppc v6.90. See post #22 for details.
     

    Attached Files:

    Last edited: Aug 24, 2010
  2. Erel

    Erel Administrator Staff Member Licensed User

    Thank you agraham :sign0188:

    I'm sure that this library will be very useful for many of us.
     
  3. Cableguy

    Cableguy Expert Licensed User

    SortedList is very welcome to my current project, thanks Agraham...
     
  4. Woinowski

    Woinowski Active Member Licensed User

    And Hashtable is something i was waiting for

    Compliments, great idea to implemement these collections!
     
  5. agraham

    agraham Expert Licensed User

    Source code for merging dll posted in original post.
     
  6. agraham

    agraham Expert Licensed User

    Collections version 1.2 now posted with two additional objects, ArraysEx and ArrayListsEx.

    Both ordinary arrays and the more specialised ArrayList are capable of some functions that are not exposed in B4ppc. This library now provides access to additional functionality for both.

    The new ArraysEx object in the library allows you, along with some other things, to sort, search and copy normal arrays.

    The new ArrayListsEx object in the library, along with some other things, lets you more easily transfer data between arrays and ArrayLists.

    This library should work on desktop and device, but requires .NET 2.0
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Thanks again :)
    The online documentation is available here: Collections
     
  8. agraham

    agraham Expert Licensed User

    Version 1.3 now posted with all the objects renamed with an 'Ex' suffix to avoid name clashes with Basic4ppc version 6.80 which implements Stack and Hashtable internally. The Basic4ppc implementation of Stack is the same as StackEx but there are differences between Hashtable and HashtableEx. See the help file. Note the ArrayListsEx is now called ArrayListEx for reasons of personal whim!

    Minor changes are that all ControlRefs now support getting and setting a control reference and StackEx, which implements some strongly typed methods, now has a PeekType method to determine the type of the item on the top of the stack.
     
    Last edited: Apr 27, 2009
  9. Byak@

    Byak@ Active Member Licensed User

    Hello Agraham.
    please,add new method to ArrayEx object- ToString(Array() as array,Separator as string)

    Yes,i can do it in basic with small cod but i have big array...and it is slow. I think this cod in library will be faster
     
  10. agraham

    agraham Expert Licensed User

    I assume you are using something like

    For i = 0 to Arraylen(array())
    Str = Str + array(i) + separator
    Next

    This will be slow using strings. Try using a Stringbuilder from my StringsEx library, that should be a lot quicker. New it with a reasonably large capacity so it doesn't have to grow itself too often.
     
  11. Byak@

    Byak@ Active Member Licensed User

    how can i'm do it with stringbuilder?
    now it is
     
  12. agraham

    agraham Expert Licensed User

    It's all in the help.

    StrBld.New1(10000)
    ...
    StrBld.Append(list(i))
    StrBld.Append(",")
    ...
    Str = StrBld.ToString
     
  13. Byak@

    Byak@ Active Member Licensed User

    oo,big thanks :cool:
     
  14. agraham

    agraham Expert Licensed User

    Version 1.4 adds an additional variant of New to ArraysEx, ArrayListEx and Sorted List that accepts a culture which determines the way that sorts are made. Details are in the help, a link to a list of valid culture strings is in the help overview topic.
     
  15. Byak@

    Byak@ Active Member Licensed User

    Andrew, can you add a method 'AddOrUpdate' to HashtableEx, as in native basic hashtable OR another method for EDIT existing pair?
    yes,i can remove and then add pair,but this pair now be in the end of hashtable...
     
  16. agraham

    agraham Expert Licensed User

    A pure hashtable has no internal order so there is no beginning or end at which to put a key/value pair. If you read the Overview topic of the version 1.4 Collections help I try to explain the difference between a Hashtable and a HashtableEx.

    A HashtableEx is a pure .NET unordered hashtable. A Basic4ppc Hashtable has an associated (invisible) Arraylist that keeps track of the order in which items are added to the Hashtable and allows them to be indexed in that order. However maintaing the Arraylist in parallel with the true hashtable adds a performance overhead to a Hashtable compared to a Hashtable Ex. In particular Remove on a Hashtable containing more than a few items is very slow as it inspects every entry in the Arraylist to ensure that the indexing is correct. The other Hashtable methods have only a slight performance disadvantage so if you don't need Remove a Basic4ppc Hashtable is more convenient. However if you have a lot of items and are doing a lot of Adding and Removing you should use a HashtableEx.
     
  17. Byak@

    Byak@ Active Member Licensed User

    Thanks for response) i'm find a new way for my problem
     
  18. Skates

    Skates New Member Licensed User

    Compiler error with B4P 6.90

    Hello Andrew,

    Looking at your Collections 1.4 library I noticed two compiler errors when compiling "ArraysExDemo.sbp" with Basic4ppc version 6.90 (6.901 actually).

    The compiler error is:

    Error message: error CS0266: Cannot implicitly convert type 'object' to 'string[]'.
    Line number: 137
    Line: b() = Arraylistex.ToArray

    Their is also the same problem with method ArraysEx.Clone (Line: 186).

    Both of your examples work fine in the desktop IDE, and example "CollectionsDemo.sbp" compiles fine.

    Compiling this with Basic4ppc version 6.80 worked as well.

    Thanks for all the great libraries.....Skates
     
  19. agraham

    agraham Expert Licensed User

    Thanks for pointing it out. Basic4ppc v6.9 fundamentally changed the handling of variables, both regular ones and arrays. I've posted modified versions of the other libraries affected but I totally overlooked that this one might be affected.

    It should work fine, at least for default (String) arrays, if you avoid ArrayListex.ToArray and Arraysex.Clone. I'll work at modifying the library in the next few days.
     
  20. konisek

    konisek Member Licensed User

    I have the similar problem while compiling under the v6.9:
    Code:
    Error message: error CS0266: Cannot implicitly convert type 'System.Aray' to 'string[]'.
    Line number: 222
    Line: xInfo() = Getdevice.info 
    'reads IMEI
    Do I have to upgrade the library? Under v6.8 it compiles well.
    Thx, (L)
     
Loading...