@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
42 lines • 2.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.clusterStatisticsOutput = clusterStatisticsOutput;
/**
* Reading the given file line by line and expecting constructs of {@link StatisticsOutputFormat},
* this module is responsible for identifying interesting groups of same data.
*
* @module
*/
const n_readlines_1 = __importDefault(require("n-readlines"));
const defaultmap_1 = require("../../../util/defaultmap");
const decorate_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/decorate");
/**
* Takes a statistics file like `statistics-out/top-2023-01-01-00-00-00/Assignments/assignmentOperator.txt` and clusters the values by context
*
* @param filepath - Filepath of the statistics file
* @param contextIdMap - The id map to use, can use an existing one to reuse ids for same contexts spreading over multiple input files.
* `undefined` is used for unknown contexts. This map allows us to reference contexts with a way shorter identifier (vs. the full file path).
*/
function clusterStatisticsOutput(filepath, contextIdMap = new defaultmap_1.DefaultMap((0, decorate_1.deterministicCountingIdGenerator)())) {
const lineReader = new n_readlines_1.default(filepath);
// for each value we store the context ids it was seen in (may list the same context multiple times if more often) - this serves as a counter as well
const valueInfoMap = new defaultmap_1.DefaultMap(() => new defaultmap_1.DefaultMap(() => 0));
let line;
// eslint-disable-next-line no-cond-assign
while (line = lineReader.next()) {
const json = JSON.parse(line.toString());
const contextId = contextIdMap.get(json[1]);
const value = valueInfoMap.get(json[0]);
// step the counter accordingly
value.set(contextId, value.get(contextId) + 1);
}
return {
filepath,
contextIdMap,
valueInfoMap
};
}
//# sourceMappingURL=clusterer.js.map