Skip to content

Commit

Permalink
made "distribution" list selector case-sensitivity setting aware
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoenig committed Jul 12, 2023
1 parent 2ec1d88 commit 29b6806
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* changed the semantics of empty list-type slots to return a new empty list instead of "nothing"
* improved browser resource management for graphics and sounds
* changed long-form input dialog setting's behavior to automatically expand / collapse slot type view
* made "distribution" list selector case-sensitivity setting aware and optimized for atomic data
* slightly optimized pen drawing performance when WARPed
* removed multibranched conditional library (cases.xml), because IF is now variadic
* updated audio comp library with a faster (hyper) version of the "Hz for secs" reporter
Expand Down Expand Up @@ -82,6 +83,7 @@
* v9-rc7
* blocks: replaced the variadic black "ladder" symbol with a white vertical ellipsis label
* blocks: changed the semantics of empty list-type slots to return a new empty list instead of "nothing"
* threads: made "distribution" list selector case-sensitivity setting aware

### 2023-07-11
* blocks, symbols, gui: design overhaul of variadic input slots
Expand Down
46 changes: 45 additions & 1 deletion src/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,18 @@ Process.prototype.reportListAttribute = function (choice, list) {
return this.reportUniqueValues(list);
case 'distribution':
this.assertType(list, 'list');
return list.distribution();
if (list.canBeCSV()) {
if (Process.prototype.isCaseInsensitive) {
return list.map(row => row instanceof List ?
row.map(cell =>
cell.toLowerCase()
)
: row.toLowerCase()
).distribution();
}
return list.distribution();
}
return this.reportDistribution(list);
case 'sorted':
this.assertType(list, 'list');
return this.reportSorted(list);
Expand Down Expand Up @@ -2374,6 +2385,39 @@ Process.prototype.reportUniqueValues = function (list) {
this.pushContext();
};

Process.prototype.reportDistribution = function (list) {
// answer a new list with an entry for each unique value and the
// number of its occurrences in the source list,
// interpolated so it can be interrupted by the user
// because snapEquals() can be a lot slower than identity comparison
var next, record;
if (this.context.accumulator === null) {
this.assertType(list, 'list');
this.context.accumulator = {
idx : 0,
target : []
};
}
if (this.context.accumulator.idx === list.length()) {
this.returnValueToParentContext(
new List(this.context.accumulator.target.map(row => new List(row)))
);
return;
}
this.context.accumulator.idx += 1;
next = list.at(this.context.accumulator.idx);

record = this.context.accumulator.target.find(row =>
snapEquals(row[0], next)
);
if (record !== undefined) {
record[1] += 1;
} else {
this.context.accumulator.target.push([next, 1]);
}
this.pushContext();
};

Process.prototype.reportSorted = function (data) {
return new List(data.itemsArray().slice().sort((a, b) =>
this.reportIsBefore(a, b) ? - 1 : 1
Expand Down

0 comments on commit 29b6806

Please sign in to comment.