MCPcopy
hub / github.com/apache/echarts / removeDuplicates

Function removeDuplicates

src/util/model.ts:1333–1358  ·  view source on GitHub ↗
(
    arr: (TItem | NullUndefined)[],
    getKey: (item: TItem) => string,
    // `existingCount`: the count before this item is added.
    resolve: ((item: TItem, existingCount: number) => void) | NullUndefined,
)

Source from the content-addressed store, hash-verified

1331 * - Callers need to handle null/undefined (if existing) in `getKey`.
1332 */
1333export function removeDuplicates<TItem>(
1334 arr: (TItem | NullUndefined)[],
1335 getKey: (item: TItem) => string,
1336 // `existingCount`: the count before this item is added.
1337 resolve: ((item: TItem, existingCount: number) => void) | NullUndefined,
1338): void {
1339 const dupMap = createHashMap<number, string>();
1340 let writeIdx = 0;
1341 each(arr, function (item) {
1342 const key = getKey(item);
1343 if (__DEV__) {
1344 assert(isString(key));
1345 }
1346 const count = dupMap.get(key) || 0;
1347 if (resolve) {
1348 resolve(item, count);
1349 }
1350 if (!count && !resolve) {
1351 arr[writeIdx++] = item;
1352 }
1353 dupMap.set(key, count + 1);
1354 });
1355 if (!resolve) {
1356 arr.length = writeIdx;
1357 }
1358}
1359
1360export function removeDuplicatesGetKeyFromValueProp<TValue extends (string | number)>(
1361 item: {value: TValue}

Callers 6

model.test.tsFile · 0.90
runFunction · 0.90
createIntervalTicksFunction · 0.90
brushPreprocessorFunction · 0.90
prepareSeriesDataSchemaFunction · 0.90

Calls 4

getKeyFunction · 0.85
eachFunction · 0.50
assertFunction · 0.50
getMethod · 0.45

Tested by 1

runFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…