(
arr: (TItem | NullUndefined)[],
getKey: (item: TItem) => string,
// `existingCount`: the count before this item is added.
resolve: ((item: TItem, existingCount: number) => void) | NullUndefined,
)
| 1331 | * - Callers need to handle null/undefined (if existing) in `getKey`. |
| 1332 | */ |
| 1333 | export 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 | |
| 1360 | export function removeDuplicatesGetKeyFromValueProp<TValue extends (string | number)>( |
| 1361 | item: {value: TValue} |
searching dependent graphs…