Large List: is there a way to query list values by index


by peter » Wed Jul 16, 2014 4:58 pm

Yes, Large (Ordered) Lists can be accessed in several ways: find() finds an individual element or a range of elements, with an optional filter scan() scans the list with an optional filter


We have a bit of a name collision with the term “Large List”. In fact, we need to be more careful to call it “Large Ordered List”. Because there’s ordering, (e.g.list values [ 12, 40, 55, 90 ] ) all of the operations are value-based, rather than index-based, as they would be for an array list. As the ordered list changes over time with inserts and deletes, the value in a particular position (say, the second position) would change.

For example, our starting list (values [ 12, 40, 55, 90 ] ) , after some number of ops might look like this: (values [ 12, 33, 39, 44, 55, 71, 75, 90 ] ). It’s not clear what general-purpose value there would be in having a “get value at position N” function would be.

I can see the benefit of a “top N” function (or “bottom N”), especially when we’re implementing a scoreboard. After tracking a number of scores, we might want to get the top 10. That type of function capability is on our TODO list. However, for ordered list, we will not have the function of getting a value for a particular position (e.g. array index).

Now, all that said, there is a way to fake a Large Array List (Large Array List is something that we do not yet have) with Large Ordered List. When you use a Map as the value, and an array index as the map key, you could store an array of objects (maps) that are managed in array index order. However, that particular implementation would have some limitations (no easy prepending, no easy length-changing operations in the middle, etc).