[R] beginner Q: hashtable or dictionary?

Patrick Burns pburns at pburns.seanet.com
Mon Jan 30 17:46:29 CET 2006


hadley wickham wrote:

> I read this to mean that setting a value in list will be O(n) (where n
>
>is the length of the new list) - If you blindly expect a list to act
>like a hash table you will be badly surprised.  If you are copying an
>algorithm from another language, you will probably need to rethink the
>way that updates work.  If however, you just want an object that can
>be indexed by a string, then a list will be fine.
>

I would think that when translating from another language,
it is best to write it in R in the simplest way, which probably
means using a list.  Then if it turns out to be too slow, try doing
something fancy.  I suspect that speed improvements are
seldom necessary -- I can't believe how fast most computations
are these days.

I don't see that worrying about O(1) versus O(n) is likely to
get you very far.  Just try it out on a normal size problem,
and try it out on a very large problem and see if it is good
enough.


Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

>
>
>
>  
>




More information about the R-help mailing list