Re: Collections of structured-data objects: what approach?



Robert:

Question and then a comment:

Question: What does the keyword "self" do when sitting on a line by itself,
as in several of your methods?

Comment:

For the sake of discussion I present a different approach. As long as
you don't need 4 (lookup by key) an Array is perfect. However, with the
lookup IMHO a new data structure is preferred because then consistency
can be handled internally. I'll attach a half grown quick hack to
demonstrate what I mean.

If I'm reading you correctly, you are saying a bit more than this:

1. For lookup (or for that matter if one want to implement a
SortedCollection), then it's desirable to have an index for the array on the
key field(s), which can be a ruby hash. (Ie: one *could* use Enumerable#find
or find_all, but on larger collections that's slow?)

2. But if you are going to implement an index using a helper hash, then you
want a way to keep the hash up-to-date as items are inserted or deleted from
the array.

3. So you advocate a class to wrap these together so that "consistency can
be handled internally".

Thanks for your reply,

Graham
--
---------------------------------------------------
Graham Wideman
Microsoft Visio MVP
---------------------------------------------------
Book/Tools:
Visio 2003 Developer's Survival Pack
Resources for programmable diagramming at:
http://www.diagramantics.com


.



Relevant Pages

  • Re: Collections of structured-data objects: what approach?
    ... by doing this you can chain methods. ... you don't need 4 (lookup by key) an Array is perfect. ... For lookup, then it's desirable to have an index for the array on the key field, which can be a ruby hash. ...
    (comp.lang.ruby)
  • Re: Associative Array in C
    ... OK so my current idea for implementing this is using an array of C ... If you provided the errors in sorted order, ... do the lookup. ... I guess that a hash table will work perfectly well and be the best ...
    (comp.lang.c)
  • Re: hash tables, non-random keys
    ... large numbers of insertions, or I would just use an array. ... optimize hash tables). ... I guess then the issue is how frequent lookup fails are... ...
    (comp.programming)
  • Re: hash tables, non-random keys
    ... large numbers of insertions, or I would just use an array. ... optimize hash tables). ... I guess then the issue is how frequent lookup fails are... ...
    (comp.programming)
  • Re: Idea for ECMA/C# Standard - compile time hash for performance
    ... contains 100 fields that I do hash lookups on to get and set the values. ... counting the lookup then and processing. ... this could be done with a straight array lookup using the minimal memory ... > The key is I don't want to burn a huge amount of memory and I want to incur ...
    (microsoft.public.dotnet.languages.csharp)

Loading