[Opa] documentation for database functions

Owen Gunden ogunden at phauna.org
Wed Jan 18 23:05:30 UTC 2012

On Wed, Jan 18, 2012 at 2:37 PM, Adam Koprowski
<Adam.Koprowski at mlstate.com> wrote:
>> > This comment is for intmap_fold_range only.
>> Okay, so what is the meaning of the params [start] and [ending]
>> for stringmap_fold_range?
>   The fold will be performed on the values in the range [start]-[ending]
> (should be [end]).

Okay, so it wasn't clear to me what this means (are the strings
ordered lexicographically? How is [ending], an integer, used?)

So I wrote a small test:

db /test : stringmap(int)

test_page() =
  do /test["foo"] <- 1
  do /test["bar"] <- 2
  do /test["baz"] <- 3
  do /test["quux"] <- 4
  do /test["zebra"] <- 5
  do /test["apple"] <- 6
  res = Db.stringmap_fold_range(
    !/test, (acc,k -> [ k | acc ]), [], "", {some=10}, (_->true)
  <div><p> { String.concat(" , ",List.rev(res)) } </p> </div>

Playing around with different values for [start] and [end], I discovered:
 - The strings are indeed iterated over in lexicographic order
 - The empty string is before all other strings
 - For [end]:
   - {some 1} is equivalent to {none} (I think)
   - the number is an index into the list of *all*
lexicographically-ordered keys, not just the ones starting with
[start]. e.g. if ["a","b","c","d","e"] is the list, start is "b", and
end is {some=2}, you get just "b" and "c" (elements 0,1,2 are
processed, "a" is dropped, leaving "b" and "c").

None of this was obvious to me, and it took a while to figure out.

Also, I just took a look at the implementation in opabsl/mlbsl/path.ml
and it's not clear whether the [filter] is applied during or after the
query. I had thought it would be passed to the underlying engine to
make it fast. Can somebody clarify?


More information about the Opa mailing list