MOO-cows Mailing List Archive
[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: my kingdom for a hash table!
Ben writes:
> Amy writes:
>> In MOOSE, I'm using hash tables for verb lookup for in-db parsing.
>> I implemented this by having each hash slot be a property on the
>> object.
> If you don't like that, keep in mind that:
>
> object.(propname)
>
> is almost exactly the same as:
>
> values[propname in keys]
...right now, at least.
> I would have to do some experiments to determine which one is faster,
> but in most situations I would expect them to be very nearly equal.
> Both are linear searches, of course,
It will be a lot easier to make `object.(propname)' run faster than
`values[propname in keys]', and there are plenty of incentives to
expend effort there. For that reason, I'd prefer the propname
version.
As Amy mentioned, keeping lists reasonably short is probably a good
thing. Somebody with more time for exposition for me should detail
this.
> but take advantage of the fact that it's a linear search in C code
> rather than any other kind of search in MOO code.
The other advantage that `object.(propname)' takes advantage of is
that it will be working with relatively short string-valued keys; it
can make sense to avoid strcmps by trying hashes first if strcmp isn't
heavily optimized by your C compiler. As Ben notes this clearly calls
for experiment rather than guesses pulled out of a hat.
--
Jay Carlson nop@nop.com nop@kagoona.mitre.org
Flat text is just *never* what you want. ---stephen p spackman
Follow-Ups:
References:
Home |
Subject Index |
Thread Index