[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A fast array implementation
- From: "Joshua Jensen" <jjensen@...>
- Date: Wed, 18 Apr 2001 08:15:08 -0600
From: "Ben Cooley" <benc@primenet.com>
Sent: Wednesday, April 18, 2001 2:03 AM
> > Has anyone done a non-hash array implementation for the Lua 4.0
compiler?
> > Something on the order of (I'm making up syntax):
> >
> > array myArray[10] -- All 10 elements set to nil by default
> > myArray[10] = 5 -- Array index 10 becomes the number 5.
> >
> > I know that using the [] for array access would be ambiguous... is it a
> > table or an array? But for the sake of this example, please bear with
me.
>
> If you look at the table implementation in lua, you'll be pleasantly
> suprised to discover that for numeric indexes, it actually is an array (it
> doesn't use hash values because it can't). It's really amazingly clever.
I did look at the table implementation in Lua. lua_rawgeti() calls
luaH_getnum(). luaH_getnum() sure looks like it accesses a hash table to
me, complete with a hash on the index being requested and a run of the
bucket's linked list checking for a number type and then checking if the key
matches...
Josh
----------
Author, Workspace Whiz! - A Visual Studio Add-in
http://workspacewhiz.com/