lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


* Javier Guerra Giraldez <javier@guerrag.com> [15/04/15 00:38]:
> > typedef struct Table {
> >   CommonHeader;
> >   lu_byte flags;  /* 1<<p means tagmethod(p) is not present */
> >   lu_byte lsizenode;  /* log2 of size of 'node' array */
> >   unsigned int sizearray;  /* size of 'array' array */
> >   TValue *array;  /* array part */
> >   Node *node;
> >   Node *lastfree;  /* any free position is before this position */
> >   struct Table *metatable;
> >   GCObject *gclist;
> > } Table;
> 
> 
> that "array part" is an optimization that holds _some_ values, but
> it's not guaranteed that all integer keys are stored there.
> 
> for example: if you define t={[1000000]=true}  it's quite likely that
> you will have an empty array part.  if you start adding values with
> keys between 1..999999, at some point you will have some of them in
> the array part and some in the hash part.  when you finally fill it
> and you have all consecutive integer keys, you still might have a
> sizable portion of them as hash entries.... or maybe not.

To me, the case you described, is a sparse array, not a plain
array. If something quick was available for dense arrays,
it'd already be a big deal.

-- 
http://tarantool.org - a NoSQL database in a Lua script