Results 1 to 3 of 3

Thread: [java] HasSet vs ArrayList and modelling issue

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default [java] HasSet vs ArrayList and modelling issue

    Hello,

    I must implement a class MyMethod; read a method declaration from a file with a parser, and while parsing I must fill that MyMethod Object.

    Now, at the moment this my objects are in this fashion:
    Qt Code:
    1. //allow me all public to reduce code verbosity
    2. class MyMethod {
    3. public Signature s;
    4. public String returnedType;
    5. }
    6. class MySignature {
    7. public String name;
    8. //public List<MyVar> vars = new ArrayList<Var>();
    9. public Set<MyVar> vars = new LinkedHashSet<MyVar>(); //eg, (int x, String s, int y)'
    10. }
    11. class MyVar { //eg. 'int x'
    12. public String id;
    13. public String type;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Now, in MySignature I used a Linked hashSet because I want to keep the order of insertion (and I know that I can't have two params with the same ID, here overrivde properly) since the Parser parser the list of parameters in the order they are written.
    I want to keep a position field because I would like, given an id (eg, 'x'), find its position within a certain signature WITHOUT iterate over all list of parameters (I suppose this is slower). So:
    - was it better to iterate on it (and better declare it as ArrayList) ? using arrayList I could avoid the position "problem", since I can retrieve it from iterating on the List.
    - assuming to really need the position, where could I put it ? Within MyVar?
    - assuming to use the Set, how can I override equals in MyVar to cope this situation (ie. no at most one MyVar with a certain Id)

    thanks.
    Regards

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: [java] HasSet vs ArrayList and modelling issue

    It's impossible to give a valid answer without knowing how many items might be in the list. If it's small (a few hundred items or less) then you would be hard pressed to see any difference in throughput no matter which container you chose. Processing times really only come into play when containers get quite large, with thousands of items.

    If you need to order your items in a container that isn't sequential, you can provide a comparison operator that allows the container to sort the items according to your own criteria, and/or you can add a field to your item class that keeps track of the position it would hold in a sequential list.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: [java] HasSet vs ArrayList and modelling issue

    Quote Originally Posted by SixDegrees View Post
    It's impossible to give a valid answer without knowing how many items might be in the list. If it's small (a few hundred items or less) then you would be hard pressed to see any difference in throughput no matter which container you chose. Processing times really only come into play when containers get quite large, with thousands of items.

    If you need to order your items in a container that isn't sequential, you can provide a comparison operator that allows the container to sort the items according to your own criteria, and/or you can add a field to your item class that keeps track of the position it would hold in a sequential list.
    Hello,
    my problem is indeed that. the list/set of params are the normal number of params of a function: zero, one, two, even 10; I don't even know what I need; in fact the question was even on that. What I need? How do you model this? Which container would you choose?
    Regards

Similar Threads

  1. ArrayList-Like Qt Class
    By zdunham in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2010, 15:29
  2. Qt and Java
    By gmseed in forum General Discussion
    Replies: 1
    Last Post: 21st November 2009, 11:55
  3. How can I create button from arraylist.
    By electronicboy in forum Qt Programming
    Replies: 5
    Last Post: 5th October 2009, 20:25
  4. [java] Sax
    By mickey in forum General Discussion
    Replies: 0
    Last Post: 29th September 2009, 09:42
  5. objects modelling
    By mickey in forum General Discussion
    Replies: 1
    Last Post: 12th April 2008, 08:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.