MCPcopy Create free account
hub / github.com/pomber/code-surfer / _getChildrenMap

Method _getChildrenMap

packs/standalone/src/tuple.ts:51–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49 _dict?: Map<any, Tuple<T>>;
50
51 _getChildrenMap() {
52 if (!this._dict) {
53 const [maybePrevs, maybeNexts] = this.spread();
54 const prevs: T[] = maybePrevs || [];
55 const nexts: T[] = maybeNexts || [];
56
57 const unsortedMap = new Map<any, { prev: Maybe<T>; next?: Maybe<T> }>(
58 prevs.map(prev => [prev.key, { prev }])
59 );
60 nexts.forEach(next => {
61 const { prev } = unsortedMap.get(next.key) || { prev: undefined };
62 unsortedMap.set(next.key, { prev, next });
63 });
64
65 const sortedKeys = Array.from(unsortedMap.keys());
66 sortedKeys.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
67 this._dict = new Map<any, Tuple<T>>(
68 sortedKeys.map(key => {
69 const { prev = undefined, next = undefined } =
70 unsortedMap.get(key) || {};
71 return [key, new Tuple(prev, next)];
72 })
73 );
74 }
75 return this._dict;
76 }
77
78 get(key: any): Tuple<T> | undefined {
79 const childrenMap = this._getChildrenMap();

Callers 2

getMethod · 0.95
mapMethod · 0.95

Calls 3

spreadMethod · 0.80
mapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected