Closed ralsei closed 3 years ago
Another consideration you might want to give to df-index-range
is whether it should return two values or a cons cell. If you find that most of the uses of df-index-range
are like so:
(match-define (cons start end) (df-index-range ...))
You might want to make df-index-range
return two values instead, as this would be more efficient.
Hi @ralsei , can you pull from the ah/lower-bound branch as this implements the lower-bound
and upper-bound
functions, plus an equal-range
function which you can use in the series-index-range
function? These functions have better semantics than bsearch
, but require the use of strict ordering for the sort function (e.g. use <
instead of <=
)
So the issue with the changes in the ah/lower-bound
branch is that sorting with <=
no longer produces expected behavior, but using check-valid-sort
with <
and duplicate items in a series fails. This is why I added an equal?
check -- but I don't know if this is what is wanted.
Still going to incorporate the requested changes.
I think I have resolved all requested changes. Feel free to tell me if it doesn't.
This adds a few utility functions, and therefore closes #8.
Changes to existing functions:
bsearch
now has a#:rightmost?
argument, which determines whether to get the index of the rightmost element in the vector, rather than the leftmost one. necessary forseries-index-range
New functions:
series-index-range
: binary searches on a series, and returns both the left and rightmost index of an element. useful for when a series has duplicatesdf-index-range
: same for data-framesseries-is-sorted?
: determines if a series has a comparison function. useful for knowing whetherseries-index-of
is possible, or sorting/linear search is requireddf-is-sorted?
: same for data-framesseries-shallow-copy
: copies a series's vector, retaining all of its propertiesdf-duplicate-series
: returns a copy of the given series from the data-frame, retaining all of its properties, usingseries-shallow-copy
Nit-picks:
df-shallow-copy
to docsfor/data-frame
syntax in docs (call that cleaning up my own mess)All functions have tests, but do feel free to let me know if they're insufficient.