MCPcopy Index your code
hub / github.com/Effect-TS/effect / getSearchTree

Function getSearchTree

packages/effect/src/ParseResult.ts:1553–1605  ·  view source on GitHub ↗
(
  members: ReadonlyArray<AST.AST>,
  isDecoding: boolean
)

Source from the content-addressed store, hash-verified

1551 * @internal
1552 */
1553export const getSearchTree = (
1554 members: ReadonlyArray<AST.AST>,
1555 isDecoding: boolean
1556): {
1557 keys: {
1558 readonly [key: PropertyKey]: {
1559 buckets: { [literal: string]: ReadonlyArray<AST.AST> }
1560 literals: ReadonlyArray<AST.Literal> // this is for error messages
1561 candidates: ReadonlyArray<AST.AST>
1562 }
1563 }
1564 otherwise: ReadonlyArray<AST.AST>
1565 candidates: ReadonlyArray<AST.AST>
1566} => {
1567 const keys: {
1568 [key: PropertyKey]: {
1569 buckets: { [literal: string]: Array<AST.AST> }
1570 literals: Array<AST.Literal>
1571 candidates: Array<AST.AST>
1572 }
1573 } = {}
1574 const otherwise: Array<AST.AST> = []
1575 const candidates: Array<AST.AST> = []
1576 for (let i = 0; i < members.length; i++) {
1577 const member = members[i]
1578 const tags = getLiterals(member, isDecoding)
1579 if (tags.length > 0) {
1580 candidates.push(member)
1581 for (let j = 0; j < tags.length; j++) {
1582 const [key, literal] = tags[j]
1583 const hash = String(literal.literal)
1584 keys[key] = keys[key] || { buckets: {}, literals: [], candidates: [] }
1585 const buckets = keys[key].buckets
1586 if (Object.prototype.hasOwnProperty.call(buckets, hash)) {
1587 if (j < tags.length - 1) {
1588 continue
1589 }
1590 buckets[hash].push(member)
1591 keys[key].literals.push(literal)
1592 keys[key].candidates.push(member)
1593 } else {
1594 buckets[hash] = [member]
1595 keys[key].literals.push(literal)
1596 keys[key].candidates.push(member)
1597 break
1598 }
1599 }
1600 } else {
1601 otherwise.push(member)
1602 }
1603 }
1604 return { keys, otherwise, candidates }
1605}
1606
1607const dropRightRefinement = (ast: AST.AST): AST.AST => AST.isRefinement(ast) ? dropRightRefinement(ast.from) : ast
1608

Callers 1

goFunction · 0.85

Calls 2

getLiteralsFunction · 0.85
StringInterface · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…