{"version":3,"file":"permutations.mjs","names":[],"sources":["../../src/sql/permutations.ts"],"sourcesContent":["/**\n * Create permutations of the array while sorting it from\n * largest permutation to smallest.\n *\n * This is important when generating index permutations as\n * postgres happens to prefer indexes with the latest\n * creation date when the cost of using 2 are the same\n **/\nexport function permutationsWithDescendingLength<T>(arr: T[]): T[][] {\n  const collected: T[][] = [];\n\n  function collect(path: T[], rest: T[]): void {\n    for (let i = 0; i < rest.length; i++) {\n      const nextRest = [...rest.slice(0, i), ...rest.slice(i + 1)];\n      const nextPath = [...path, rest[i]];\n      collected.push(nextPath);\n      collect(nextPath, nextRest);\n    }\n  }\n\n  collect([], arr);\n  collected.sort((a, b) => b.length - a.length);\n\n  return collected;\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,iCAAoC,KAAiB;CACnE,MAAM,YAAmB,EAAE;CAE3B,SAAS,QAAQ,MAAW,MAAiB;AAC3C,OAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,WAAW,CAAC,GAAG,KAAK,MAAM,GAAG,EAAE,EAAE,GAAG,KAAK,MAAM,IAAI,EAAE,CAAC;GAC5D,MAAM,WAAW,CAAC,GAAG,MAAM,KAAK,GAAG;AACnC,aAAU,KAAK,SAAS;AACxB,WAAQ,UAAU,SAAS;;;AAI/B,SAAQ,EAAE,EAAE,IAAI;AAChB,WAAU,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,OAAO;AAE7C,QAAO"}