lua-users home
lua-l archive

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




On Saturday, June 6, 2015, Tim Hill <drtimhill@gmail.com> wrote:

On Jun 6, 2015, at 1:04 PM, Brigham Toskin <brighamtoskin@gmail.com> wrote:

I'm not sure what Andrew's specific usecase is, but imagine timeseries data indexed by some non-integer timestamp format.

On Fri, Jun 5, 2015 at 9:36 PM, Tim Hill <drtimhill@gmail.com> wrote:

On Jun 5, 2015, at 11:50 AM, Andrew Starks <andrew.starks@trms.com> wrote:

If Lua always stored all numeric keys in order, then there might be
more opportunities to dream up efficient iterators, like a sort of
`npairs`. I think I'm different, because i need to index values by
arbitrary numbers (and need them in order) quite often, whereas
everyone else is concerned only with sequences and their strict
definition.

Can you describe this is more detail? I’m curious.

—Tim



Yes, I was guessing it was something like that.

Yes. Time series data, for me. That's why I'm mostly interested in integers (samples/scale). I also imagine that floats would make it more difficult to implement and therefore not worth it.

But generally, if all integers were stored in order, then some nice things become possible / necessary.
Things like: "nexti", "firsti", "lasti", and some way to get the index at or lower than some specified value.

I use a single sequence and a table with the index / time value at [1] and the vale at [2]. So every key value is indirected once, simply because I need them to be in order.  I use a simple binary search function, given a desired time value, returns: index (of sequence), value, next_value. I use insert/remove to keep everything together. I couldn't see a way to implement something faster in C.

-Andrew