Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
24a6a12
initial commit.
Jul 3, 2020
fad9ba6
documentation
llimllib Sep 5, 2022
d191caa
remove no-longer-valid type
llimllib Sep 5, 2022
0d937a7
close over state initialization for performance
llimllib Sep 5, 2022
8fd3f8a
link documentation in comment
llimllib Sep 5, 2022
ba733ba
more testing
llimllib Sep 5, 2022
9e6b462
run tests if they're main
llimllib Sep 6, 2022
573afa7
accept a single arg
llimllib Sep 6, 2022
a3abdcb
this kind of works but I'm abandoning this branch
llimllib Sep 6, 2022
9daf01f
a middle road sqlite3_agg_context solution
llimllib Sep 6, 2022
ec5c72b
try out auto-updating state
llimllib Sep 6, 2022
a927950
improve quantile test, add multiple agg test
llimllib Sep 6, 2022
e643bd9
add a null to the test
llimllib Sep 6, 2022
2cbdb0e
acorn fails to parse ||=, whatever
llimllib Sep 6, 2022
b9ccd48
make eslint happy
llimllib Sep 6, 2022
ac548d4
make initial_value an argument
llimllib Sep 7, 2022
bf22aa1
test step and finalize exceptions
llimllib Sep 7, 2022
55858e9
add memory leak test
llimllib Sep 7, 2022
9a0c185
update docs to current interface
llimllib Sep 7, 2022
2445107
delete state in exception handlers
llimllib Sep 7, 2022
5b62cf6
remove null state
llimllib Sep 7, 2022
062f147
return init function and document object
llimllib Sep 7, 2022
7aff1ae
more tests and update back to init function
llimllib Sep 7, 2022
67f85e5
update redefinition test for new interface
llimllib Sep 7, 2022
b8692d4
update README to match fixed signature
llimllib Sep 7, 2022
b41e5cf
more consistent test formatting
llimllib Sep 7, 2022
d257bba
Update README.md
llimllib Sep 7, 2022
e82c286
clarify what exactly the result will contain
llimllib Sep 7, 2022
b65457c
Update README.md
lovasoa Sep 7, 2022
8d2c2e0
Update README.md
lovasoa Sep 7, 2022
f8f4a7c
Update README.md
lovasoa Sep 7, 2022
bdaa1b6
Update README.md
lovasoa Sep 7, 2022
e86d7ff
Update README.md
lovasoa Sep 7, 2022
423fc36
Improve documentation and type annotations
lovasoa Sep 8, 2022
f8e7bd3
ignore documentation in eslintrc
lovasoa Sep 8, 2022
799ebcd
reduce code size
lovasoa Sep 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
try out auto-updating state
  • Loading branch information
llimllib committed Sep 6, 2022
commit ec5c72b059c2b3323c9712ab0df26eba33d63450
30 changes: 13 additions & 17 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,44 +1267,39 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
aggregateFunctions
) {
if (!Object.hasOwnProperty.call(aggregateFunctions, "step")
|| !Object.hasOwnProperty.call(
aggregateFunctions, "finalize"
)
) {
throw "An aggregate function must have step and finalize "
+ "properties";
throw "An aggregate function must have a step property";
}

// state is a state array; we'll use the pointer p to serve as the
aggregateFunctions["init"] ||= (() => null)
aggregateFunctions["finalize"] ||= ((state) => state)

// state is a state object; we'll use the pointer p to serve as the
// key for where we hold our state so that multiple invocations of
// this function never step on each other
var state = {};

function wrapped_step(cx, argc, argv) {
// The first time the sqlite3_aggregate_context(C,N) routine is
// called for a particular aggregate function, SQLite allocates N
// bytes of memory, zeroes out that memory, and returns a pointer
// to the new memory.
// > The first time the sqlite3_aggregate_context(C,N) routine is
// > called for a particular aggregate function, SQLite allocates N
// > bytes of memory, zeroes out that memory, and returns a pointer
// > to the new memory.
//
// We're going to use that pointer as a key to our state array,
// since using sqlite3_aggregate_context as it's meant to be used
// through webassembly seems to be very difficult. Just allocate
// one byte.
var p = sqlite3_aggregate_context(cx, 1);

// If this is the first invocation of wrapped_step, state[p]
// If this is the first invocation of wrapped_step, call `init`
if (!state[p]) {
if (Object.hasOwnProperty.call(aggregateFunctions, "init")) {
state[p] = aggregateFunctions["init"].apply(null);
} else {
state[p] = [];
}
state[p] = aggregateFunctions["init"].apply(null);
}

var args = parseFunctionArguments(argc, argv);
var mergedArgs = [state[p]].concat(args);
try {
aggregateFunctions["step"].apply(null, mergedArgs);
state[p] = aggregateFunctions["step"].apply(null, mergedArgs);
} catch (error) {
sqlite3_result_error(cx, error, -1);
}
Expand Down Expand Up @@ -1340,6 +1335,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
// The signature of the wrapped function is :
// void wrapped(sqlite3_context *db, int argc, sqlite3_value **argv)
var step_ptr = addFunction(wrapped_step, "viii");

// The signature of the wrapped function is :
// void wrapped(sqlite3_context *db)
var finalize_ptr = addFunction(wrapped_finalize, "vi");
Expand Down