Primeiro commit do projeto Angular
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
import type { TaskQueue, Task } from '.';
|
||||
export declare class ArrayTaskQueue implements TaskQueue {
|
||||
tasks: Task[];
|
||||
get size(): number;
|
||||
shift(): Task | null;
|
||||
push(task: Task): void;
|
||||
remove(task: Task): void;
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayTaskQueue = void 0;
|
||||
const node_assert_1 = __importDefault(require("node:assert"));
|
||||
class ArrayTaskQueue {
|
||||
constructor() {
|
||||
this.tasks = [];
|
||||
}
|
||||
get size() {
|
||||
return this.tasks.length;
|
||||
}
|
||||
shift() {
|
||||
var _a;
|
||||
return (_a = this.tasks.shift()) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
push(task) {
|
||||
this.tasks.push(task);
|
||||
}
|
||||
remove(task) {
|
||||
const index = this.tasks.indexOf(task);
|
||||
node_assert_1.default.notStrictEqual(index, -1);
|
||||
this.tasks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
exports.ArrayTaskQueue = ArrayTaskQueue;
|
||||
//# sourceMappingURL=array_queue.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"array_queue.js","sourceRoot":"","sources":["../../src/task_queue/array_queue.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAIjC,MAAa,cAAc;IAA3B;QACE,UAAK,GAAW,EAAE,CAAA;IAmBpB,CAAC;IAjBC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,KAAK;;QACH,OAAO,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,mCAAI,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,CAAE,IAAU;QACd,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,CAAE,IAAU;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,qBAAM,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC9B,CAAC;CACF;AApBD,wCAoBC"}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import type { kQueueOptions } from '../symbols';
|
||||
export interface TaskQueue {
|
||||
readonly size: number;
|
||||
shift(): Task | null;
|
||||
remove(task: Task): void;
|
||||
push(task: Task): void;
|
||||
}
|
||||
export interface PiscinaTask extends Task {
|
||||
taskId: number;
|
||||
filename: string;
|
||||
name: string;
|
||||
created: number;
|
||||
isAbortable: boolean;
|
||||
}
|
||||
export interface Task {
|
||||
readonly [kQueueOptions]: object | null;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
;
|
||||
//# sourceMappingURL=common.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/task_queue/common.ts"],"names":[],"mappings":";;AAoBC,CAAC"}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import type { Task } from './common';
|
||||
import { TaskQueue } from '.';
|
||||
declare class FixedCircularBuffer {
|
||||
bottom: number;
|
||||
top: number;
|
||||
list: Array<Task | undefined>;
|
||||
next: FixedCircularBuffer | null;
|
||||
isEmpty(): boolean;
|
||||
isFull(): boolean;
|
||||
push(data: Task): void;
|
||||
shift(): Task | null;
|
||||
remove(task: Task): void;
|
||||
}
|
||||
export declare class FixedQueue implements TaskQueue {
|
||||
#private;
|
||||
head: FixedCircularBuffer;
|
||||
tail: FixedCircularBuffer;
|
||||
constructor();
|
||||
isEmpty(): boolean;
|
||||
push(data: Task): void;
|
||||
shift(): Task | null;
|
||||
remove(task: Task): void;
|
||||
get size(): number;
|
||||
}
|
||||
export {};
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
"use strict";
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _FixedQueue_size;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FixedQueue = void 0;
|
||||
/*
|
||||
* Modified Fixed Queue Implementation based on the one from Node.js Project
|
||||
* License: MIT License
|
||||
* Source: https://github.com/nodejs/node/blob/de7b37880f5a541d5f874c1c2362a65a4be76cd0/lib/internal/fixed_queue.js
|
||||
*/
|
||||
const node_assert_1 = __importDefault(require("node:assert"));
|
||||
// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
|
||||
const kSize = 2048;
|
||||
const kMask = kSize - 1;
|
||||
// The FixedQueue is implemented as a singly-linked list of fixed-size
|
||||
// circular buffers. It looks something like this:
|
||||
//
|
||||
// head tail
|
||||
// | |
|
||||
// v v
|
||||
// +-----------+ <-----\ +-----------+ <------\ +-----------+
|
||||
// | [null] | \----- | next | \------- | next |
|
||||
// +-----------+ +-----------+ +-----------+
|
||||
// | item | <-- bottom | item | <-- bottom | [empty] |
|
||||
// | item | | item | | [empty] |
|
||||
// | item | | item | | [empty] |
|
||||
// | item | | item | | [empty] |
|
||||
// | item | | item | bottom --> | item |
|
||||
// | item | | item | | item |
|
||||
// | ... | | ... | | ... |
|
||||
// | item | | item | | item |
|
||||
// | item | | item | | item |
|
||||
// | [empty] | <-- top | item | | item |
|
||||
// | [empty] | | item | | item |
|
||||
// | [empty] | | [empty] | <-- top top --> | [empty] |
|
||||
// +-----------+ +-----------+ +-----------+
|
||||
//
|
||||
// Or, if there is only one circular buffer, it looks something
|
||||
// like either of these:
|
||||
//
|
||||
// head tail head tail
|
||||
// | | | |
|
||||
// v v v v
|
||||
// +-----------+ +-----------+
|
||||
// | [null] | | [null] |
|
||||
// +-----------+ +-----------+
|
||||
// | [empty] | | item |
|
||||
// | [empty] | | item |
|
||||
// | item | <-- bottom top --> | [empty] |
|
||||
// | item | | [empty] |
|
||||
// | [empty] | <-- top bottom --> | item |
|
||||
// | [empty] | | item |
|
||||
// +-----------+ +-----------+
|
||||
//
|
||||
// Adding a value means moving `top` forward by one, removing means
|
||||
// moving `bottom` forward by one. After reaching the end, the queue
|
||||
// wraps around.
|
||||
//
|
||||
// When `top === bottom` the current queue is empty and when
|
||||
// `top + 1 === bottom` it's full. This wastes a single space of storage
|
||||
// but allows much quicker checks.
|
||||
class FixedCircularBuffer {
|
||||
constructor() {
|
||||
this.bottom = 0;
|
||||
this.top = 0;
|
||||
this.list = new Array(kSize);
|
||||
this.next = null;
|
||||
}
|
||||
isEmpty() {
|
||||
return this.top === this.bottom;
|
||||
}
|
||||
isFull() {
|
||||
return ((this.top + 1) & kMask) === this.bottom;
|
||||
}
|
||||
push(data) {
|
||||
this.list[this.top] = data;
|
||||
this.top = (this.top + 1) & kMask;
|
||||
}
|
||||
shift() {
|
||||
const nextItem = this.list[this.bottom];
|
||||
if (nextItem === undefined) {
|
||||
return null;
|
||||
}
|
||||
this.list[this.bottom] = undefined;
|
||||
this.bottom = (this.bottom + 1) & kMask;
|
||||
return nextItem;
|
||||
}
|
||||
remove(task) {
|
||||
const indexToRemove = this.list.indexOf(task);
|
||||
node_assert_1.default.notStrictEqual(indexToRemove, -1);
|
||||
let curr = indexToRemove;
|
||||
while (true) {
|
||||
const next = (curr + 1) & kMask;
|
||||
this.list[curr] = this.list[next];
|
||||
if (this.list[curr] === undefined) {
|
||||
break;
|
||||
}
|
||||
if (next === indexToRemove) {
|
||||
this.list[curr] = undefined;
|
||||
break;
|
||||
}
|
||||
curr = next;
|
||||
}
|
||||
this.top = (this.top - 1) & kMask;
|
||||
}
|
||||
}
|
||||
class FixedQueue {
|
||||
constructor() {
|
||||
_FixedQueue_size.set(this, 0);
|
||||
this.head = this.tail = new FixedCircularBuffer();
|
||||
}
|
||||
isEmpty() {
|
||||
return this.head.isEmpty();
|
||||
}
|
||||
push(data) {
|
||||
var _a;
|
||||
if (this.head.isFull()) {
|
||||
// Head is full: Creates a new queue, sets the old queue's `.next` to it,
|
||||
// and sets it as the new main queue.
|
||||
this.head = this.head.next = new FixedCircularBuffer();
|
||||
}
|
||||
this.head.push(data);
|
||||
__classPrivateFieldSet(this, _FixedQueue_size, (_a = __classPrivateFieldGet(this, _FixedQueue_size, "f"), _a++, _a), "f");
|
||||
}
|
||||
shift() {
|
||||
var _a;
|
||||
const tail = this.tail;
|
||||
const next = tail.shift();
|
||||
if (next !== null)
|
||||
__classPrivateFieldSet(this, _FixedQueue_size, (_a = __classPrivateFieldGet(this, _FixedQueue_size, "f"), _a--, _a), "f");
|
||||
if (tail.isEmpty() && tail.next !== null) {
|
||||
// If there is another queue, it forms the new tail.
|
||||
this.tail = tail.next;
|
||||
tail.next = null;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
remove(task) {
|
||||
var _a;
|
||||
let prev = null;
|
||||
let buffer = this.tail;
|
||||
while (true) {
|
||||
if (buffer.list.includes(task)) {
|
||||
buffer.remove(task);
|
||||
__classPrivateFieldSet(this, _FixedQueue_size, (_a = __classPrivateFieldGet(this, _FixedQueue_size, "f"), _a--, _a), "f");
|
||||
break;
|
||||
}
|
||||
if (buffer.next === null)
|
||||
break;
|
||||
prev = buffer;
|
||||
buffer = buffer.next;
|
||||
}
|
||||
if (buffer.isEmpty()) {
|
||||
// removing tail
|
||||
if (prev === null) {
|
||||
// if tail is not the last buffer
|
||||
if (buffer.next !== null)
|
||||
this.tail = buffer.next;
|
||||
}
|
||||
else {
|
||||
// removing head
|
||||
if (buffer.next === null) {
|
||||
this.head = prev;
|
||||
}
|
||||
else {
|
||||
// removing buffer from middle
|
||||
prev.next = buffer.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
get size() {
|
||||
return __classPrivateFieldGet(this, _FixedQueue_size, "f");
|
||||
}
|
||||
}
|
||||
exports.FixedQueue = FixedQueue;
|
||||
_FixedQueue_size = new WeakMap();
|
||||
;
|
||||
//# sourceMappingURL=fixed_queue.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fixed_queue.js","sourceRoot":"","sources":["../../src/task_queue/fixed_queue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,8DAAiC;AAGjC,8EAA8E;AAC9E,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC;AAExB,sEAAsE;AACtE,kDAAkD;AAClD,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,kEAAkE;AAClE,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA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AAO,EAAE,EAAE,CAAC;YACrB,gBAAgB;YAChB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBAClB,iCAAiC;gBACjC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;oBAAE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACN,gBAAgB;gBAChB,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;oBACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,8BAA8B;oBAC9B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,wBAAM,CAAC;IACpB,CAAC;CACF;AApED,gCAoEC;;AAAA,CAAC"}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import type { MessagePort } from 'node:worker_threads';
|
||||
import { AsyncResource } from 'node:async_hooks';
|
||||
import type { WorkerInfo } from '../worker_pool';
|
||||
import type { Task, TaskQueue, PiscinaTask } from './common';
|
||||
import { type AbortSignalAny } from '../abort';
|
||||
import { kQueueOptions } from '../symbols';
|
||||
export { ArrayTaskQueue } from './array_queue';
|
||||
export { FixedQueue } from './fixed_queue';
|
||||
export type TaskCallback = (err: Error, result: any) => void;
|
||||
export type TransferList = MessagePort extends {
|
||||
postMessage: (value: any, transferList: infer T) => any;
|
||||
} ? T : never;
|
||||
export type TransferListItem = TransferList extends Array<infer T> ? T : never;
|
||||
type TaskInfoParameters = {
|
||||
task: any;
|
||||
transferList: TransferList;
|
||||
filename: string;
|
||||
name: string;
|
||||
abortSignal: AbortSignalAny | null;
|
||||
triggerAsyncId: number;
|
||||
};
|
||||
/**
|
||||
* Verifies if a given TaskQueue is valid
|
||||
*
|
||||
* @export
|
||||
* @param {*} value
|
||||
* @return {*} {boolean}
|
||||
*/
|
||||
export declare function isTaskQueue(value: TaskQueue): boolean;
|
||||
export declare class TaskInfo extends AsyncResource implements Task {
|
||||
callback: TaskCallback;
|
||||
task: any;
|
||||
transferList: TransferList;
|
||||
filename: string;
|
||||
name: string;
|
||||
taskId: number;
|
||||
abortSignal: AbortSignalAny | null;
|
||||
workerInfo: WorkerInfo | null;
|
||||
created: number;
|
||||
started: number;
|
||||
aborted: boolean;
|
||||
_abortListener: (() => void);
|
||||
_abortCleaner: (() => void) | null;
|
||||
constructor({ task, transferList, filename, name, abortSignal, triggerAsyncId, }: TaskInfoParameters, callback: TaskCallback);
|
||||
onAbort(value: (() => void)): void;
|
||||
setAbortListener(signal: AbortSignalAny): void;
|
||||
releaseTask(): any;
|
||||
onResponse(_result: any): void;
|
||||
done(err: Error | null, result?: any): void;
|
||||
get [kQueueOptions](): {} | null;
|
||||
get interface(): PiscinaTask;
|
||||
}
|
||||
export { Task, TaskQueue, PiscinaTask };
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TaskInfo = exports.FixedQueue = exports.ArrayTaskQueue = void 0;
|
||||
exports.isTaskQueue = isTaskQueue;
|
||||
const node_perf_hooks_1 = require("node:perf_hooks");
|
||||
const node_async_hooks_1 = require("node:async_hooks");
|
||||
const abort_1 = require("../abort");
|
||||
const common_1 = require("../common");
|
||||
const symbols_1 = require("../symbols");
|
||||
var array_queue_1 = require("./array_queue");
|
||||
Object.defineProperty(exports, "ArrayTaskQueue", { enumerable: true, get: function () { return array_queue_1.ArrayTaskQueue; } });
|
||||
var fixed_queue_1 = require("./fixed_queue");
|
||||
Object.defineProperty(exports, "FixedQueue", { enumerable: true, get: function () { return fixed_queue_1.FixedQueue; } });
|
||||
/**
|
||||
* Verifies if a given TaskQueue is valid
|
||||
*
|
||||
* @export
|
||||
* @param {*} value
|
||||
* @return {*} {boolean}
|
||||
*/
|
||||
function isTaskQueue(value) {
|
||||
return (typeof value === 'object' &&
|
||||
value !== null &&
|
||||
'size' in value &&
|
||||
typeof value.shift === 'function' &&
|
||||
typeof value.remove === 'function' &&
|
||||
typeof value.push === 'function');
|
||||
}
|
||||
let taskIdCounter = 0;
|
||||
// Extend AsyncResource so that async relations between posting a task and
|
||||
// receiving its result are visible to diagnostic tools.
|
||||
class TaskInfo extends node_async_hooks_1.AsyncResource {
|
||||
constructor({ task, transferList, filename, name, abortSignal, triggerAsyncId, }, callback) {
|
||||
super('Piscina.Task', { requireManualDestroy: true, triggerAsyncId });
|
||||
this.workerInfo = null;
|
||||
this.aborted = false;
|
||||
this._abortListener = () => { this.aborted = true; };
|
||||
this._abortCleaner = null;
|
||||
this.callback = callback;
|
||||
this.task = task;
|
||||
this.transferList = transferList;
|
||||
// If the task is a Transferable returned by
|
||||
// Piscina.move(), then add it to the transferList
|
||||
// automatically
|
||||
if ((0, common_1.isMovable)(task)) {
|
||||
// This condition should never be hit but typescript
|
||||
// complains if we dont do the check.
|
||||
/* c8 ignore next */
|
||||
if (this.transferList == null) {
|
||||
this.transferList = [];
|
||||
}
|
||||
this.transferList = this.transferList.concat(task[symbols_1.kTransferable]);
|
||||
this.task = task[symbols_1.kValue];
|
||||
}
|
||||
this.filename = filename;
|
||||
this.name = name;
|
||||
// TODO: This should not be global
|
||||
this.taskId = taskIdCounter++;
|
||||
this.abortSignal = abortSignal;
|
||||
this.created = node_perf_hooks_1.performance.now();
|
||||
this.started = 0;
|
||||
}
|
||||
onAbort(value) {
|
||||
this._abortListener = () => {
|
||||
this.aborted = true;
|
||||
value();
|
||||
};
|
||||
}
|
||||
setAbortListener(signal) {
|
||||
this._abortCleaner = (0, abort_1.onabort)(signal, this._abortListener);
|
||||
}
|
||||
releaseTask() {
|
||||
const ret = this.task;
|
||||
this.task = null;
|
||||
return ret;
|
||||
}
|
||||
// TODO: implement - helpful for streaming chunks of data from worker to parent
|
||||
onResponse(_result) { }
|
||||
done(err, result) {
|
||||
var _a;
|
||||
this.runInAsyncScope(this.callback, null, err, result);
|
||||
this.emitDestroy(); // `TaskInfo`s are used only once.
|
||||
// If an abort signal was used, remove the listener from it when
|
||||
// done to make sure we do not accidentally leak.
|
||||
(_a = this._abortCleaner) === null || _a === void 0 ? void 0 : _a.call(this);
|
||||
}
|
||||
get [symbols_1.kQueueOptions]() {
|
||||
var _a, _b;
|
||||
return (_b = (_a = this.task) === null || _a === void 0 ? void 0 : _a[symbols_1.kQueueOptions]) !== null && _b !== void 0 ? _b : null;
|
||||
}
|
||||
get interface() {
|
||||
return {
|
||||
taskId: this.taskId,
|
||||
filename: this.filename,
|
||||
name: this.name,
|
||||
created: this.created,
|
||||
isAbortable: this.abortSignal !== null,
|
||||
[symbols_1.kQueueOptions]: this[symbols_1.kQueueOptions]
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.TaskInfo = TaskInfo;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/task_queue/index.ts"],"names":[],"mappings":";;;AA0CA,kCASC;AAlDD,qDAA8C;AAC9C,uDAAiD;AAKjD,oCAAwD;AACxD,sCAAsC;AACtC,wCAAkE;AAGlE,6CAA+C;AAAtC,6GAAA,cAAc,OAAA;AACvB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AAsBnB;;;;;;GAMG;AACH,SAAgB,WAAW,CAAE,KAAgB;IAC3C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU;QACjC,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU;QAClC,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CACjC,CAAC;AACJ,CAAC;AAED,IAAI,aAAa,GAAG,CAAC,CAAC;AACtB,0EAA0E;AAC1E,wDAAwD;AACxD,MAAa,QAAS,SAAQ,gCAAa;IAevC,YAAa,EACX,IAAI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